// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package byteorder provides functions for decoding and encoding // little and big endian integer types from/to byte slices.
package byteorder func ( []byte) uint16 { _ = [1] // bounds check hint to compiler; see golang.org/issue/14808 return uint16([0]) | uint16([1])<<8 } func ( []byte, uint16) { _ = [1] // early bounds check to guarantee safety of writes below [0] = byte() [1] = byte( >> 8) } func ( []byte, uint16) []byte { return append(, byte(), byte(>>8), ) } func ( []byte) uint32 { _ = [3] // bounds check hint to compiler; see golang.org/issue/14808 return uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24 } func ( []byte, uint32) { _ = [3] // early bounds check to guarantee safety of writes below [0] = byte() [1] = byte( >> 8) [2] = byte( >> 16) [3] = byte( >> 24) } func ( []byte, uint32) []byte { return append(, byte(), byte(>>8), byte(>>16), byte(>>24), ) } func ( []byte) uint64 { _ = [7] // bounds check hint to compiler; see golang.org/issue/14808 return uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 | uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56 } func ( []byte, uint64) { _ = [7] // early bounds check to guarantee safety of writes below [0] = byte() [1] = byte( >> 8) [2] = byte( >> 16) [3] = byte( >> 24) [4] = byte( >> 32) [5] = byte( >> 40) [6] = byte( >> 48) [7] = byte( >> 56) } func ( []byte, uint64) []byte { return append(, byte(), byte(>>8), byte(>>16), byte(>>24), byte(>>32), byte(>>40), byte(>>48), byte(>>56), ) } func ( []byte) uint16 { _ = [1] // bounds check hint to compiler; see golang.org/issue/14808 return uint16([1]) | uint16([0])<<8 } func ( []byte, uint16) { _ = [1] // early bounds check to guarantee safety of writes below [0] = byte( >> 8) [1] = byte() } func ( []byte, uint16) []byte { return append(, byte(>>8), byte(), ) } func ( []byte) uint32 { _ = [3] // bounds check hint to compiler; see golang.org/issue/14808 return uint32([3]) | uint32([2])<<8 | uint32([1])<<16 | uint32([0])<<24 } func ( []byte, uint32) { _ = [3] // early bounds check to guarantee safety of writes below [0] = byte( >> 24) [1] = byte( >> 16) [2] = byte( >> 8) [3] = byte() } func ( []byte, uint32) []byte { return append(, byte(>>24), byte(>>16), byte(>>8), byte(), ) } func ( []byte) uint64 { _ = [7] // bounds check hint to compiler; see golang.org/issue/14808 return uint64([7]) | uint64([6])<<8 | uint64([5])<<16 | uint64([4])<<24 | uint64([3])<<32 | uint64([2])<<40 | uint64([1])<<48 | uint64([0])<<56 } func ( []byte, uint64) { _ = [7] // early bounds check to guarantee safety of writes below [0] = byte( >> 56) [1] = byte( >> 48) [2] = byte( >> 40) [3] = byte( >> 32) [4] = byte( >> 24) [5] = byte( >> 16) [6] = byte( >> 8) [7] = byte() } func ( []byte, uint64) []byte { return append(, byte(>>56), byte(>>48), byte(>>40), byte(>>32), byte(>>24), byte(>>16), byte(>>8), byte(), ) }