codec

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is a cursor over a byte slice. The first out-of-bounds read sets err; all subsequent reads are no-ops. Call Err() once after all reads to check.

func NewReader

func NewReader(p []byte) *Reader

func (*Reader) Err

func (r *Reader) Err() error

Err returns the first error encountered during reading, or nil.

func (*Reader) F32

func (r *Reader) F32() float32

func (*Reader) Obj

func (r *Reader) Obj(n int, v encoding.BinaryUnmarshaler)

Obj reads n bytes and decodes them into v.

func (*Reader) Raw

func (r *Reader) Raw(n int) []byte

Raw reads exactly n bytes and returns a copy.

func (*Reader) Remaining

func (r *Reader) Remaining() int

Remaining returns the number of unread bytes.

func (*Reader) Str

func (r *Reader) Str(n int) string

Str reads exactly n bytes and returns a copy as a string. Use U8LenStr or U32LenStr instead if the data is length-prefixed:

[length: 1 byte][data: N bytes]   → U8LenStr
[length: 4 bytes][data: N bytes]  → U32LenStr

func (*Reader) U8

func (r *Reader) U8() uint8

func (*Reader) U8LenStr

func (r *Reader) U8LenStr() string

U8LenStr reads a length-prefixed string where the length is a single byte.

func (*Reader) U16

func (r *Reader) U16() uint16

func (*Reader) U32

func (r *Reader) U32() uint32

func (*Reader) U32LenStr

func (r *Reader) U32LenStr() string

U32LenStr reads a length-prefixed string where the length is a 4-byte little-endian unsigned integer.

func (*Reader) U64

func (r *Reader) U64() uint64

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer appends encoded values to a growing byte slice. The first encoding error sets err; all subsequent writes are no-ops. Call Err() once after all writes to check.

func NewWriter

func NewWriter() *Writer

NewWriter returns a new Writer with an empty internal buffer. Use NewWriterCap instead if the final size is known.

func NewWriterCap

func NewWriterCap(n int) *Writer

NewWriterCap returns a Writer with its internal buffer pre-allocated to n bytes. Use this when the final size is known in advance to avoid reallocations.

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes returns the accumulated buffer directly. The slice is valid only until the next write. The caller must not mutate the returned slice.

func (*Writer) Err

func (w *Writer) Err() error

Err returns the first error encountered during writing, or nil.

func (*Writer) F32

func (w *Writer) F32(v float32)

func (*Writer) Obj

func (w *Writer) Obj(v encoding.BinaryMarshaler)

Obj encodes v and appends the result to the buffer.

func (*Writer) Raw

func (w *Writer) Raw(v []byte)

Raw appends a raw byte slice with no length prefix.

func (*Writer) Str

func (w *Writer) Str(v string)

Str writes a string with no length prefix. Use U8LenStr or U32LenStr instead if the reader expects a length prefix.

func (*Writer) U8

func (w *Writer) U8(v uint8)

func (*Writer) U8LenStr

func (w *Writer) U8LenStr(v string)

U8LenStr writes a length-prefixed string where the length is a single byte. Sets w.err if len(v) exceeds 255.

func (*Writer) U16

func (w *Writer) U16(v uint16)

func (*Writer) U32

func (w *Writer) U32(v uint32)

func (*Writer) U32LenStr

func (w *Writer) U32LenStr(v string)

U32LenStr writes a length-prefixed string where the length is a 4-byte little-endian unsigned integer.

func (*Writer) U64

func (w *Writer) U64(v uint64)

Jump to

Keyboard shortcuts

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