Documentation ¶
Overview ¶
Package bytes provides utility functions for byte slices.
Index ¶
- func Compare(a, b []byte) int
- func Copy(val []byte) []byte
- func Equal(a, b []byte) bool
- func FindIndex[T ~[]byte](values []T, target T) int
- func FromBools(input []bool) []byte
- func FromUint16(val uint16) []byte
- func FromUint32(val uint32) []byte
- func FromUint64(val uint64) []byte
- func IsBitSet(bits []byte, index int) bool
- func IsSorted(values [][]byte) bool
- func IsUnique[T ~[]byte](values []T) bool
- func Join(s ...[]byte) []byte
- func JoinSize(size int, s ...[]byte) []byte
- func JoinSlice[T ~[]byte](a, b []T) []T
- func NewReader(b []byte) *bytes.Reader
- func Repeat(b []byte, count int) []byte
- func Reverse(bytes []byte) []byte
- func Sort(values [][]byte)
- func ToBools(val []byte) []bool
- func ToUint32(val []byte) uint32
- func ToUint64(val []byte) uint64
- func Unique[T ~[]byte](values []T) []T
- type SortBytesLexicographically
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare returns an integer comparing two byte slices lexicographically. The result will be 0 if a == b, -1 if a < b, and +1 if a > b. A nil argument is equivalent to an empty slice.
Compare is alias for the function from standard library "bytes".
func Equal ¶
Equal reports whether a and b are the same length and contain the same bytes. A nil argument is equivalent to an empty slice.
Equal is alias for the function from standard library "bytes".
func FindIndex ¶
FindIndex returns the index in the slice if target bytes is in the values provided. It returns -1 if it does not exist.
func FromUint16 ¶
FromUint16 converts uint16 to byte slice with length 2.
func FromUint32 ¶
FromUint32 converts uint32 to byte slice with length 4.
func FromUint64 ¶
FromUint64 converts uint64 to byte slice with length 8.
func IsBitSet ¶
IsBitSet takes in byte array, and check if bitwise index is 0 or 1.
[]byte{255, 0, 1} and index is 8, it looks at index 1 in the slice and determin if 0 bit is true/false.
func JoinSlice ¶
func JoinSlice[T ~[]byte](a, b []T) []T
JoinSlice joins 2 bytes slices provided and returns a new slice. Each element of slice T is copied but each byte in the slice is not copied.
func NewReader ¶
NewReader returns a new Reader reading from b.
NewReader is alias for the function from standard library "bytes".
func Repeat ¶
Repeat returns a new byte slice consisting of count copies of b.
It panics if count is negative or if the result of (len(b) * count) overflows. Repeat is alias for the function from standard library "bytes".
Types ¶
type SortBytesLexicographically ¶
type SortBytesLexicographically [][]byte
SortBytesLexicographically is type for sorging bytes lexicographically.
func (SortBytesLexicographically) Len ¶
func (b SortBytesLexicographically) Len() int
func (SortBytesLexicographically) Less ¶
func (b SortBytesLexicographically) Less(i, j int) bool
func (SortBytesLexicographically) Swap ¶
func (b SortBytesLexicographically) Swap(i, j int)