github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/net/netip/leaf_alts.go (about) 1 // Copyright 2021 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Stuff that exists in std, but we can't use due to being a dependency 6 // of net, for go/build deps_test policy reasons. 7 8 package netip 9 10 func beUint64(b []byte) uint64 { 11 _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808 12 return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 | 13 uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56 14 } 15 16 func bePutUint64(b []byte, v uint64) { 17 _ = b[7] // early bounds check to guarantee safety of writes below 18 b[0] = byte(v >> 56) 19 b[1] = byte(v >> 48) 20 b[2] = byte(v >> 40) 21 b[3] = byte(v >> 32) 22 b[4] = byte(v >> 24) 23 b[5] = byte(v >> 16) 24 b[6] = byte(v >> 8) 25 b[7] = byte(v) 26 } 27 28 func bePutUint32(b []byte, v uint32) { 29 _ = b[3] // early bounds check to guarantee safety of writes below 30 b[0] = byte(v >> 24) 31 b[1] = byte(v >> 16) 32 b[2] = byte(v >> 8) 33 b[3] = byte(v) 34 } 35 36 func leUint16(b []byte) uint16 { 37 _ = b[1] // bounds check hint to compiler; see golang.org/issue/14808 38 return uint16(b[0]) | uint16(b[1])<<8 39 } 40 41 func lePutUint16(b []byte, v uint16) { 42 _ = b[1] // early bounds check to guarantee safety of writes below 43 b[0] = byte(v) 44 b[1] = byte(v >> 8) 45 }