...

Source file src/net/netip/leaf_alts.go

Documentation: net/netip

     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 stringsLastIndexByte(s string, b byte) int {
    11  	for i := len(s) - 1; i >= 0; i-- {
    12  		if s[i] == b {
    13  			return i
    14  		}
    15  	}
    16  	return -1
    17  }
    18  
    19  func beUint64(b []byte) uint64 {
    20  	_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
    21  	return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
    22  		uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
    23  }
    24  
    25  func bePutUint64(b []byte, v uint64) {
    26  	_ = b[7] // early bounds check to guarantee safety of writes below
    27  	b[0] = byte(v >> 56)
    28  	b[1] = byte(v >> 48)
    29  	b[2] = byte(v >> 40)
    30  	b[3] = byte(v >> 32)
    31  	b[4] = byte(v >> 24)
    32  	b[5] = byte(v >> 16)
    33  	b[6] = byte(v >> 8)
    34  	b[7] = byte(v)
    35  }
    36  
    37  func bePutUint32(b []byte, v uint32) {
    38  	_ = b[3] // early bounds check to guarantee safety of writes below
    39  	b[0] = byte(v >> 24)
    40  	b[1] = byte(v >> 16)
    41  	b[2] = byte(v >> 8)
    42  	b[3] = byte(v)
    43  }
    44  
    45  func leUint16(b []byte) uint16 {
    46  	_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
    47  	return uint16(b[0]) | uint16(b[1])<<8
    48  }
    49  
    50  func lePutUint16(b []byte, v uint16) {
    51  	_ = b[1] // early bounds check to guarantee safety of writes below
    52  	b[0] = byte(v)
    53  	b[1] = byte(v >> 8)
    54  }
    55  

View as plain text