byteutils

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddZeroBytesSuffix

func AddZeroBytesSuffix(data []byte, required int) []byte

AddZeroBytesSuffix appends zero bytes such that result byte length == required

func ClearBit added in v1.0.0

func ClearBit(n byte, pos uint) byte

ClearBit clears the bit at pos in n.

func ContainsBytesInSlice

func ContainsBytesInSlice(slice [][]byte, b []byte) bool

ContainsBytesInSlice returns bool if byte slice is contained in input

func CutFromSlice added in v1.0.0

func CutFromSlice(slice [][]byte, idx int) [][]byte

CutFromSlice returns a new slice without the value at idx

func IntBytesFromString

func IntBytesFromString(s string) ([]byte, error)

IntBytesFromString return the integer base 10 string in bytes.

func IsBitSet added in v1.0.0

func IsBitSet(n byte, pos uint) bool

IsBitSet checks if the bit at position is set

func RemoveBytesFromSlice added in v1.0.0

func RemoveBytesFromSlice(slice [][]byte, b []byte) [][]byte

RemoveBytesFromSlice removes bytes b from the slice of bytes Note: all duplicates of b in slice will be removed. Note: if thee bytes b doesn't exist, same slice is returned

func RemoveZeroBytesSuffix

func RemoveZeroBytesSuffix(data []byte) []byte

RemoveZeroBytesSuffix removes zero bytes appended to the end.

func SetBit added in v1.0.0

func SetBit(n byte, pos uint) byte

SetBit sets the bit at pos in the given byte.

func SortByte32Slice added in v1.0.0

func SortByte32Slice(arr [][32]byte) [][32]byte

SortByte32Slice sorts the byte32 slices in ascending order.

func TimestampToBytes added in v1.0.0

func TimestampToBytes(tm *timestamp.Timestamp, maxTimeByteLength int) ([]byte, error)

TimestampToBytes returns encodes timestamp into a 32 byte value

Types

type BytesArray added in v1.0.0

type BytesArray [][32]byte

BytesArray is a alias for 32 byte alice

func (BytesArray) Len added in v1.0.0

func (a BytesArray) Len() int

Len returns the length of the slice

func (BytesArray) Less added in v1.0.0

func (a BytesArray) Less(i, j int) bool

Less returns true if i'th item is less than j'th else false

func (BytesArray) Swap added in v1.0.0

func (a BytesArray) Swap(i, j int)

Swap swaps the i, j values with in the array.

type HexBytes added in v1.0.0

type HexBytes []byte

HexBytes is of type bytes with JSON hex string marshaller.

func ToHexByteSlice added in v1.0.0

func ToHexByteSlice(l [][]byte) (hb []HexBytes)

ToHexByteSlice converts slicee of slice of bytes to slice of HexBytes

func (HexBytes) Bytes added in v1.0.0

func (h HexBytes) Bytes() []byte

Bytes returns a copy of the HexBytes.

func (HexBytes) MarshalJSON added in v1.0.0

func (h HexBytes) MarshalJSON() ([]byte, error)

MarshalJSON marshall bytes to hex.

func (HexBytes) String added in v1.0.0

func (h HexBytes) String() string

String returns HexBytes in string format.

func (*HexBytes) UnmarshalJSON added in v1.0.0

func (h *HexBytes) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals hex string to bytes.

type OptionalHex added in v1.0.0

type OptionalHex struct {
	HexBytes
}

OptionalHex can have empty hex string and doesn't error.

func (*OptionalHex) UnmarshalJSON added in v1.0.0

func (o *OptionalHex) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshalls hex encoded string to bytes. if the data is an empty string, it decoded value is empty bytes.

Jump to

Keyboard shortcuts

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