Documentation
¶
Overview ¶
Package slice is a collection of miscellaneous functions involving slices of bytes, including little-endian encoding for 16, 32 and 64-bit unsigned integers used for serialisation length prefixes and system entropy based hash chain padding.
Index ¶
- Constants
- func Cat(chunks ...[]byte) (pkt []byte)
- func Cut(b []byte, l int) (seg []byte, rem []byte)
- func DecodeUint16(b []byte) int
- func DecodeUint24(b []byte) int
- func DecodeUint32(b []byte) int
- func DecodeUint64(b []byte) uint64
- func EncodeUint16(b []byte, n int)
- func EncodeUint24(b []byte, n int)
- func EncodeUint32(b []byte, n int)
- func EncodeUint64(b []byte, n uint64)
- func GenerateRandomAddrPortIPv4() (ap *netip.AddrPort)
- func GenerateRandomAddrPortIPv6() (ap *netip.AddrPort)
- func NoisePad(l int) (noise []byte)
- func Segment(b []byte, segmentSize int) (segs [][]byte)
- func SumLen(chunks ...[]byte) (l int)
- type Bytes
- type Cursor
- type U64Slice
Constants ¶
const ( Uint64Len = 8 Uint32Len = 4 Uint24Len = 3 Uint16Len = 2 )
Variables ¶
This section is empty.
Functions ¶
func Cat ¶
Cat takes a slice of byte slices and packs them together in a packet. The returned packet has its capacity pre-allocated to match what gets copied into it by append.
func DecodeUint16 ¶
DecodeUint16 returns an int containing the little endian encoded 32bit value stored in a 4 byte long slice
func DecodeUint24 ¶
DecodeUint24 returns an int containing the little endian encoded 24bit value stored in a 3 byte long slice
func DecodeUint32 ¶
DecodeUint32 returns an int containing the little endian encoded 32bit value stored in a 4 byte long slice
func DecodeUint64 ¶
DecodeUint64 returns an int containing the little endian encoded 64-bit value stored in a 4 byte long slice
func EncodeUint16 ¶
EncodeUint16 puts an int into a uint32 and then into 2 byte long slice.
func EncodeUint24 ¶
EncodeUint24 puts an int into a uint32 and then into 3 byte long slice.
func EncodeUint32 ¶
EncodeUint32 puts an int into a uint32 and then into 4 byte long slice.
func EncodeUint64 ¶
EncodeUint64 puts an int into a uint32 and then into 8 byte long slice.
Types ¶
type Bytes ¶
type Bytes []byte
func (Bytes) ToU64Slice ¶
ToU64Slice converts the message with zero allocations if the slice capacity was already 8 plus the modulus of the length and 8, otherwise this function will trigger a stack allocation, or heap, if the bytes are very long. This is intended to be used with short byte slices like cipher nonces and hashes, so it usually won't trigger allocations off stack and very often won't trigger a copy on stack, saving a lot of time in a short, oft repeated operations.