Documentation
¶
Index ¶
- type Reader
- func (r *Reader) Err() error
- func (r *Reader) F32() float32
- func (r *Reader) Obj(n int, v encoding.BinaryUnmarshaler)
- func (r *Reader) Raw(n int) []byte
- func (r *Reader) Remaining() int
- func (r *Reader) Str(n int) string
- func (r *Reader) U8() uint8
- func (r *Reader) U8LenStr() string
- func (r *Reader) U16() uint16
- func (r *Reader) U32() uint32
- func (r *Reader) U32LenStr() string
- func (r *Reader) U64() uint64
- type Writer
- func (w *Writer) Bytes() []byte
- func (w *Writer) Err() error
- func (w *Writer) F32(v float32)
- func (w *Writer) Obj(v encoding.BinaryMarshaler)
- func (w *Writer) Raw(v []byte)
- func (w *Writer) Str(v string)
- func (w *Writer) U8(v uint8)
- func (w *Writer) U8LenStr(v string)
- func (w *Writer) U16(v uint16)
- func (w *Writer) U32(v uint32)
- func (w *Writer) U32LenStr(v string)
- func (w *Writer) U64(v uint64)
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 (*Reader) Obj ¶
func (r *Reader) Obj(n int, v encoding.BinaryUnmarshaler)
Obj reads n bytes and decodes them into v.
func (*Reader) Str ¶
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) U8LenStr ¶
U8LenStr reads a length-prefixed string where the length is a single byte.
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 ¶
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 ¶
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) Obj ¶
func (w *Writer) Obj(v encoding.BinaryMarshaler)
Obj encodes v and appends the result to the buffer.
func (*Writer) Str ¶
Str writes a string with no length prefix. Use U8LenStr or U32LenStr instead if the reader expects a length prefix.
func (*Writer) U8LenStr ¶
U8LenStr writes a length-prefixed string where the length is a single byte. Sets w.err if len(v) exceeds 255.