bytes

package
v0.0.0-...-77dcbbd Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package bytes provides utility functions for byte slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b []byte) int

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 Copy

func Copy(val []byte) []byte

Copy is utility function to copy the bytes to a new slice.

func Equal

func Equal(a, b []byte) bool

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

func FindIndex[T ~[]byte](values []T, target T) int

FindIndex returns the index in the slice if target bytes is in the values provided. It returns -1 if it does not exist.

func FromBools

func FromBools(input []bool) []byte

FromBools takes a slice of bool and converts to byte slice.

func FromUint16

func FromUint16(val uint16) []byte

FromUint16 converts uint16 to byte slice with length 2.

func FromUint32

func FromUint32(val uint32) []byte

FromUint32 converts uint32 to byte slice with length 4.

func FromUint64

func FromUint64(val uint64) []byte

FromUint64 converts uint64 to byte slice with length 8.

func IsBitSet

func IsBitSet(bits []byte, index int) bool

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 IsSorted

func IsSorted(values [][]byte) bool

IsSorted checks if the value is sorted.

func IsUnique

func IsUnique[T ~[]byte](values []T) bool

IsUnique returns true if the elements of the slice are unique.

func Join

func Join(s ...[]byte) []byte

Join joins multiple different bytes.

func JoinSize

func JoinSize(size int, s ...[]byte) []byte

JoinSize joins bytes with predefined size. (faster than join).

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

func NewReader(b []byte) *bytes.Reader

NewReader returns a new Reader reading from b.

NewReader is alias for the function from standard library "bytes".

func Repeat

func Repeat(b []byte, count int) []byte

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".

func Reverse

func Reverse(bytes []byte) []byte

Reverse input bytes and return a new slice.

func Sort

func Sort(values [][]byte)

Sort the input in lexographical order.

func ToBools

func ToBools(val []byte) []bool

ToBools takes byte slice and converted to corresponding boolean slice.

func ToUint32

func ToUint32(val []byte) uint32

ToUint32 converts byte slice to uint32. bytes[4:] will be ignored.

func ToUint64

func ToUint64(val []byte) uint64

ToUint64 converts byte slice to uint64. bytes[8:] will be ignored.

func Unique

func Unique[T ~[]byte](values []T) []T

Unique retuens uniqe value of the input.

Types

type SortBytesLexicographically

type SortBytesLexicographically [][]byte

SortBytesLexicographically is type for sorging bytes lexicographically.

func (SortBytesLexicographically) Len

func (SortBytesLexicographically) Less

func (b SortBytesLexicographically) Less(i, j int) bool

func (SortBytesLexicographically) Swap

func (b SortBytesLexicographically) Swap(i, j int)

Jump to

Keyboard shortcuts

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