Documentation
¶
Index ¶
- Constants
- func BytesToInt(b []byte) int
- func BytesToInt16(b []byte) int16
- func BytesToInt32(b []byte) int32
- func BytesToInt64(b []byte) int64
- func BytesToInt8(b []byte) int8
- func BytesToUint(b []byte) uint
- func BytesToUint16(b []byte) uint16
- func BytesToUint32(b []byte) uint32
- func BytesToUint64(b []byte) uint64
- func BytesToUint8(b []byte) uint8
- func GetSize(v any) int
- func GetSizeUnsafe[T Integer](v T) int
- func Int16ToBytes(i int16) []byte
- func Int32ToBytes(i int32) []byte
- func Int64ToBytes(i int64) []byte
- func Int8ToBytes(i int8) []byte
- func IntToBytes(i int) []byte
- func Uint16ToBytes(i uint16) []byte
- func Uint32ToBytes(i uint32) []byte
- func Uint64ToBytes(i uint64) []byte
- func Uint8ToBytes(i uint8) []byte
- func UintToBytes(i uint) []byte
- type Integer
Constants ¶
const ( INT8Size = 1 INT16Size = 2 INT32Size = 4 INT64Size = 8 INTSize = INT64Size UINT8Size = 1 UINT16Size = 2 UINT32Size = 4 UINT64Size = 8 UINTSize = UINT64Size Float32Size = 4 Float64Size = 8 )
Variables ¶
This section is empty.
Functions ¶
func BytesToInt ¶
BytesToInt converts a byte slice in big endian order to an int value. It is equivalent to BytesToInt64 with an int cast.
func BytesToInt16 ¶
BytesToInt16 converts a byte slice in big endian order to an int16 value.
func BytesToInt32 ¶
BytesToInt32 converts a byte slice in big endian order to an int32 value.
func BytesToInt64 ¶
BytesToInt64 converts a byte slice in big endian order to an int64 value.
func BytesToInt8 ¶
BytesToInt8 converts a byte slice to an int8 value. It is equivalent to taking the first element of the slice and casting it to int8.
func BytesToUint ¶
BytesToUint converts a byte slice in big endian order to a uint value. It is equivalent to BytesToUint64 with a uint cast.
func BytesToUint16 ¶
BytesToUint16 converts a byte slice in big endian order to a uint16 value.
func BytesToUint32 ¶
BytesToUint32 converts a byte slice in big endian order to a uint32 value.
func BytesToUint64 ¶
BytesToUint64 converts a byte slice in big endian order to a uint64 value.
func BytesToUint8 ¶
BytesToUint8 converts a byte slice to a uint8 value. It is equivalent to taking the first element of the slice.
func GetSize ¶
GetSize returns the size in bytes of the given value, based on its type. It uses a type switch to handle different types.
func GetSizeUnsafe ¶
GetSizeUnsafe returns the size in bytes of the given value, based on its type. It uses unsafe.Sizeof to get the size of any type that implements Integer.
func Int16ToBytes ¶
Int16ToBytes converts an int16 value to a byte slice in big endian order.
func Int32ToBytes ¶
Int32ToBytes converts an int32 value to a byte slice in big endian order.
func Int64ToBytes ¶
Int64ToBytes converts an int64 value to a byte slice in big endian order.
func Int8ToBytes ¶
Int8ToBytes converts an int8 value to a byte slice. It is equivalent to casting the value to uint8 and wrapping it in a slice.
func IntToBytes ¶
IntToBytes converts an int value to a byte slice in big endian order. It is equivalent to Int64ToBytes with an int64 cast.
func Uint16ToBytes ¶
Uint16ToBytes converts a uint16 value to a byte slice in big endian order.
func Uint32ToBytes ¶
Uint32ToBytes converts a uint32 value to a byte slice in big endian order.
func Uint64ToBytes ¶
Uint64ToBytes converts a uint64 value to a byte slice in big endian order.
func Uint8ToBytes ¶
Uint8ToBytes converts a uint8 value to a byte slice. It is equivalent to wrapping the value in a slice.
func UintToBytes ¶
UintToBytes converts a uint value to a byte slice in big endian order. It is equivalent to Uint64ToBytes with a uint64 cast.
Types ¶
type Integer ¶
type Integer interface { constraints.Integer | constraints.Float }
Integer is a generic interface that represents any integer or float type.