bytes

package
v1.2.0-dev.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fingerprint

func Fingerprint(slice []byte) []byte

Fingerprint returns the first 6 bytes of a byte slice. If the slice is less than 6 bytes, the fingerprint contains trailing zeroes.

func MarshalFixedSize

func MarshalFixedSize(data interface{}) ([]byte, error)

MarshalFixed marshals provided struct as a fixed-size buffer. It processes exported struct fields in the order of their declaration. At this point, it only supports the following data types: * uint16 * int64 * slices * fixed-size arrays

It also supports "tmbytes" tag with the following comma-separated attributes:

  • size=N - provide number of elements in the slice (only for slices) to be enforced; if 0 or not provided, size enforcement is responsibility of the caller

Example:

Field []byte `tmbytes:"size=123"`

func MustHexDecode

func MustHexDecode(s string) []byte

MustHexDecode decodes hex string to slice of bytes

func Reverse

func Reverse(bz []byte) []byte

Reverse returns a reversed sequence bytes of passed slice

Types

type HexBytes

type HexBytes []byte

HexBytes is a wrapper around []byte that encodes data as hexadecimal strings for use in JSON.

func (HexBytes) Bytes

func (bz HexBytes) Bytes() []byte

Bytes fulfills various interfaces in light-client, etc...

func (HexBytes) Copy

func (bz HexBytes) Copy() HexBytes

Copy creates a deep copy of HexBytes. It allocates new buffer and copies data into it.

func (HexBytes) Equal

func (bz HexBytes) Equal(b []byte) bool

func (HexBytes) Format

func (bz HexBytes) Format(s fmt.State, verb rune)

Format writes either address of 0th element in a slice in base 16 notation, with leading 0x (%p), or casts HexBytes to bytes and writes as hexadecimal string to s.

func (HexBytes) IsZero

func (bz HexBytes) IsZero() bool

func (HexBytes) Marshal

func (bz HexBytes) Marshal() ([]byte, error)

Marshal needed for protobuf compatibility

func (HexBytes) MarshalText

func (bz HexBytes) MarshalText() ([]byte, error)

MarshalText encodes a HexBytes value as hexadecimal digits. This method is used by json.Marshal.

func (HexBytes) ReverseBytes

func (bz HexBytes) ReverseBytes() HexBytes

ReverseBytes returns a reversed sequence bytes of the current slice of byte

func (HexBytes) ShortString

func (bz HexBytes) ShortString() string

func (HexBytes) String

func (bz HexBytes) String() string

func (*HexBytes) Unmarshal

func (bz *HexBytes) Unmarshal(data []byte) error

Unmarshal needed for protobuf compatibility

func (*HexBytes) UnmarshalText

func (bz *HexBytes) UnmarshalText(data []byte) error

UnmarshalText handles decoding of HexBytes from JSON strings. This method is used by json.Unmarshal. It allows decoding of both hex and base64-encoded byte arrays.

Jump to

Keyboard shortcuts

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