integer

package
v0.0.0-...-2a10a86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
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

func BytesToInt(b []byte) int

BytesToInt converts a byte slice in big endian order to an int value. It is equivalent to BytesToInt64 with an int cast.

func BytesToInt16

func BytesToInt16(b []byte) int16

BytesToInt16 converts a byte slice in big endian order to an int16 value.

func BytesToInt32

func BytesToInt32(b []byte) int32

BytesToInt32 converts a byte slice in big endian order to an int32 value.

func BytesToInt64

func BytesToInt64(b []byte) int64

BytesToInt64 converts a byte slice in big endian order to an int64 value.

func BytesToInt8

func BytesToInt8(b []byte) int8

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

func BytesToUint(b []byte) uint

BytesToUint converts a byte slice in big endian order to a uint value. It is equivalent to BytesToUint64 with a uint cast.

func BytesToUint16

func BytesToUint16(b []byte) uint16

BytesToUint16 converts a byte slice in big endian order to a uint16 value.

func BytesToUint32

func BytesToUint32(b []byte) uint32

BytesToUint32 converts a byte slice in big endian order to a uint32 value.

func BytesToUint64

func BytesToUint64(b []byte) uint64

BytesToUint64 converts a byte slice in big endian order to a uint64 value.

func BytesToUint8

func BytesToUint8(b []byte) uint8

BytesToUint8 converts a byte slice to a uint8 value. It is equivalent to taking the first element of the slice.

func GetSize

func GetSize(v any) int

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

func GetSizeUnsafe[T Integer](v T) int

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

func Int16ToBytes(i int16) []byte

Int16ToBytes converts an int16 value to a byte slice in big endian order.

func Int32ToBytes

func Int32ToBytes(i int32) []byte

Int32ToBytes converts an int32 value to a byte slice in big endian order.

func Int64ToBytes

func Int64ToBytes(i int64) []byte

Int64ToBytes converts an int64 value to a byte slice in big endian order.

func Int8ToBytes

func Int8ToBytes(i int8) []byte

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

func IntToBytes(i int) []byte

IntToBytes converts an int value to a byte slice in big endian order. It is equivalent to Int64ToBytes with an int64 cast.

func Uint16ToBytes

func Uint16ToBytes(i uint16) []byte

Uint16ToBytes converts a uint16 value to a byte slice in big endian order.

func Uint32ToBytes

func Uint32ToBytes(i uint32) []byte

Uint32ToBytes converts a uint32 value to a byte slice in big endian order.

func Uint64ToBytes

func Uint64ToBytes(i uint64) []byte

Uint64ToBytes converts a uint64 value to a byte slice in big endian order.

func Uint8ToBytes

func Uint8ToBytes(i uint8) []byte

Uint8ToBytes converts a uint8 value to a byte slice. It is equivalent to wrapping the value in a slice.

func UintToBytes

func UintToBytes(i uint) []byte

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL