encoding

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

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 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) Be64int64

func (d *Decbuf) Be64int64() int64

func (*Decbuf) Byte

func (d *Decbuf) Byte() byte

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) Uvarint

func (d *Decbuf) Uvarint() int

func (*Decbuf) Uvarint64

func (d *Decbuf) Uvarint64() uint64

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) PutByte

func (e *Encbuf) PutByte(c 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) 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) 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()

Jump to

Keyboard shortcuts

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