bufs

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const GeohashBase32Alphabet = "0123456789bcdefghjkmnpqrstuvwxyz"

GeohashBase32Alphabet is the alphabet used for Base32Encoding

Variables

View Source
var (
	// Base32Encoding is used to encode/decode binary buffer to/from base 32
	Base32Encoding = base32.NewEncoding(GeohashBase32Alphabet).WithPadding(base32.NoPadding)

	// GenesisMemberID is the genesis member ID
	GenesisMemberID = uint32(1)
)
View Source
var (

	// Parsing/Encoding
	ErrSyntax = &encodingErr{"invalid hex string"}
)

Errors

Functions

func BufDesc

func BufDesc(inBuf []byte) string

BufDesc returns a base32 encoding of a binary string, limiting it to a short number of character for debugging and logging.

func SmartDecodeFromBase32

func SmartDecodeFromBase32(srcBase32 []byte, tryDst []byte) ([]byte, error)

SmartDecodeFromBase32 decodes the base32 (ASCII) string into the given scrap buffer, returning the scrap buffer set to proper size.

If tryDst is not large enough, a new buffer is allocated and returned in its place.

func SmartMarshal

func SmartMarshal(item Marshalable, tryDst []byte) []byte

SmartMarshal marshals the given item to the given buffer. If there is not enough space a new one is allocated. The purpose of this is to reuse a scrap buffer.

func SmartMarshalToBase32

func SmartMarshalToBase32(item Marshalable, tryDst []byte) []byte

SmartMarshalToBase32 marshals the given item and then encodes it into a base32 (ASCII) byte string.

If tryDst is not large enough, a new buffer is allocated and returned in its place.

func Zero

func Zero(buf []byte)

Zero zeros out a given slice

Types

type Buf

type Buf struct {
	Unmarshalable

	Bytes []byte
}

Buf is a flexible buffer designed for reuse.

func (*Buf) Unmarshal

func (buf *Buf) Unmarshal(srcBuf []byte) error

Unmarshal effectively copies the src buffer.

type Bytes

type Bytes []byte

Bytes marshal/unmarshal as a JSON string with 0x prefix. The empty slice marshals as "0x".

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Bytes) String

func (b Bytes) String() string

String returns the hex encoding of b.

func (*Bytes) UnmarshalJSON

func (b *Bytes) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Marshalable

type Marshalable interface {
	Marshal() ([]byte, error)
	MarshalToSizedBuffer([]byte) (int, error)
	Size() int
}

Marshalable generalizes efficient serialization

type Unmarshalable

type Unmarshalable interface {
	Unmarshal([]byte) error
}

Unmarshalable used to generalize deserialization

Jump to

Keyboard shortcuts

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