encoding

package
v0.44.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 7 Imported by: 49

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSize     = errors.New("invalid size")
	ErrInvalidChecksum = errors.New("invalid checksum")
)

Functions

This section is empty.

Types

type ByteSlice

type ByteSlice interface {
	Len() int
	Range(start, end int) []byte
}

ByteSlice abstracts a byte slice.

type Decbuf

type Decbuf struct {
	B []byte
	E error
}

Decbuf provides safe methods to extract data from a byte slice. It does all necessary bounds checking and advancing of the byte slice. Several datums can be extracted without checking for errors. However, before using any datum, the err() method must be checked.

func NewDecbufAt

func NewDecbufAt(bs ByteSlice, off int, castagnoliTable *crc32.Table) Decbuf

NewDecbufAt returns a new decoding buffer. It expects the first 4 bytes after offset to hold the big endian encoded content length, followed by the contents and the expected checksum.

func NewDecbufRaw

func NewDecbufRaw(bs ByteSlice, length int) Decbuf

NewDecbufRaw returns a new decoding buffer of the given length.

func NewDecbufUvarintAt

func NewDecbufUvarintAt(bs ByteSlice, off int, castagnoliTable *crc32.Table) Decbuf

NewDecbufUvarintAt returns a new decoding buffer. It expects the first bytes after offset to hold the uvarint-encoded buffers length, followed by the contents and the expected checksum.

func (*Decbuf) Be32

func (d *Decbuf) Be32() uint32

func (*Decbuf) Be32int

func (d *Decbuf) Be32int() int

func (*Decbuf) Be64

func (d *Decbuf) Be64() uint64

func (*Decbuf) Be64Float64

func (d *Decbuf) Be64Float64() float64

func (*Decbuf) Be64int64

func (d *Decbuf) Be64int64() int64

func (*Decbuf) Byte

func (d *Decbuf) Byte() byte

func (*Decbuf) ConsumePadding

func (d *Decbuf) ConsumePadding()

func (*Decbuf) Crc32

func (d *Decbuf) Crc32(castagnoliTable *crc32.Table) uint32

Crc32 returns a CRC32 checksum over the remaining bytes.

func (*Decbuf) Err

func (d *Decbuf) Err() error

func (*Decbuf) Get

func (d *Decbuf) Get() []byte

func (*Decbuf) Len

func (d *Decbuf) Len() int

func (*Decbuf) Skip

func (d *Decbuf) Skip(l int)

func (*Decbuf) Uvarint

func (d *Decbuf) Uvarint() int

func (*Decbuf) Uvarint32 added in v0.40.0

func (d *Decbuf) Uvarint32() uint32

func (*Decbuf) Uvarint64

func (d *Decbuf) Uvarint64() uint64

func (*Decbuf) UvarintBytes

func (d *Decbuf) UvarintBytes() []byte

The return value becomes invalid if the byte slice goes away. Compared to UvarintStr, this avoid allocations.

func (*Decbuf) UvarintStr

func (d *Decbuf) UvarintStr() string

func (*Decbuf) Varint64

func (d *Decbuf) Varint64() int64

type Encbuf

type Encbuf struct {
	B []byte
	C [binary.MaxVarintLen64]byte
}

Encbuf is a helper type to populate a byte slice with various types.

func (*Encbuf) Get

func (e *Encbuf) Get() []byte

func (*Encbuf) Len

func (e *Encbuf) Len() int

func (*Encbuf) PutBE32

func (e *Encbuf) PutBE32(x uint32)

func (*Encbuf) PutBE32int

func (e *Encbuf) PutBE32int(x int)

func (*Encbuf) PutBE64

func (e *Encbuf) PutBE64(x uint64)

func (*Encbuf) PutBE64int64

func (e *Encbuf) PutBE64int64(x int64)

func (*Encbuf) PutBEFloat64

func (e *Encbuf) PutBEFloat64(x float64)

func (*Encbuf) PutByte

func (e *Encbuf) PutByte(c byte)

func (*Encbuf) PutBytes

func (e *Encbuf) PutBytes(b []byte)

func (*Encbuf) PutHash

func (e *Encbuf) PutHash(h hash.Hash)

PutHash appends a hash over the buffers current contents to the buffer.

func (*Encbuf) PutHashSum

func (e *Encbuf) PutHashSum(h hash.Hash)

PutHashSum writes the Sum of the given hash to the buffer.

func (*Encbuf) PutString

func (e *Encbuf) PutString(s string)

func (*Encbuf) PutUvarint

func (e *Encbuf) PutUvarint(x int)

func (*Encbuf) PutUvarint32

func (e *Encbuf) PutUvarint32(x uint32)

func (*Encbuf) PutUvarint64

func (e *Encbuf) PutUvarint64(x uint64)

func (*Encbuf) PutUvarintBytes

func (e *Encbuf) PutUvarintBytes(b []byte)

PutUvarintBytes writes a variable length byte buffer.

func (*Encbuf) PutUvarintStr

func (e *Encbuf) PutUvarintStr(s string)

PutUvarintStr writes a string to the buffer prefixed by its varint length (in bytes!).

func (*Encbuf) PutVarint64

func (e *Encbuf) PutVarint64(x int64)

func (*Encbuf) Reset

func (e *Encbuf) Reset()

func (*Encbuf) WriteToHash

func (e *Encbuf) WriteToHash(h hash.Hash)

WriteToHash writes the current buffer contents to the given hash.

Jump to

Keyboard shortcuts

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