Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var BufferPool = sync.Pool{ New: func() any { buf := make([]byte, 0, 256) return &buf }, }
BufferPool provides reusable byte buffers for encoding.
Functions ¶
Types ¶
type BatchDecodeResult ¶
type BatchDecodeResult struct {
Results []*DecodeResult
Errors []error
}
BatchDecodeResult holds results from batch decoding.
type BitReader ¶
type BitReader struct {
// contains filtered or unexported fields
}
BitReader reads bits from a byte slice. Bits are read MSB-first within each byte.
func NewBitReader ¶
NewBitReader creates a new BitReader from a byte slice.
func (*BitReader) BitOffset ¶
BitOffset returns the current bit offset within the current byte (0-7).
func (*BitReader) ByteOffset ¶
ByteOffset returns the current byte offset.
func (*BitReader) ReadBits ¶
ReadBits reads numBits bits (1-64) in the specified byte order and returns the value.
func (*BitReader) ReadRemainingBytes ¶
ReadRemainingBytes reads all remaining bytes. Must be byte-aligned.
func (*BitReader) RemainingBits ¶
RemainingBits returns the number of remaining bits.
type BitWriter ¶
type BitWriter struct {
// contains filtered or unexported fields
}
BitWriter accumulates bits into a byte buffer. Bits are written MSB-first within each byte.
func (*BitWriter) BitOffset ¶
BitOffset returns the current bit offset within the current byte (0-7).
func (*BitWriter) Bytes ¶
Bytes returns the written bytes, flushing any partial byte with zero padding.
func (*BitWriter) SetBytesAt ¶
SetBytesAt overwrites bytes at a specific offset in the buffer. Used for checksum backfill after encoding.
func (*BitWriter) WriteBits ¶
WriteBits writes numBits bits (1-64) of value in the specified byte order. For big-endian: most significant bits are written first. For little-endian multi-byte values: least significant byte is written first.
func (*BitWriter) WriteByteSlice ¶
WriteByteSlice writes raw bytes. The writer must be byte-aligned.
type CodecEngine ¶
type CodecEngine struct {
// contains filtered or unexported fields
}
CodecEngine provides a unified encode/decode interface backed by Encoder and Decoder with shared registries.
func NewCodecEngine ¶
func NewCodecEngine(cr *checksum.ChecksumRegistry, fr *format.FormatRegistry) *CodecEngine
NewCodecEngine creates a new CodecEngine with the given registries.
func (*CodecEngine) BatchDecode ¶
func (e *CodecEngine) BatchDecode(s interface{ GetSchema() interface{} }, packets [][]byte) *BatchDecodeResult
BatchDecode decodes multiple packets in sequence.
func (*CodecEngine) Decode ¶
func (e *CodecEngine) Decode(s *schema.ProtocolSchema, data []byte) (*DecodeResult, error)
Decode deserialises data into a DecodeResult according to the schema.
func (*CodecEngine) Encode ¶
func (e *CodecEngine) Encode(s *schema.ProtocolSchema, packet map[string]any) ([]byte, error)
Encode serialises packet into []byte according to the schema.
type DecodeResult ¶
DecodeResult holds the decoded packet and the number of bytes consumed.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes raw bytes into a Packet (map[string]any) according to a ProtocolSchema.
func NewDecoder ¶
func NewDecoder(cr *checksum.ChecksumRegistry, fr *format.FormatRegistry) *Decoder
NewDecoder creates a new Decoder with the given registries.
func (*Decoder) Decode ¶
func (dec *Decoder) Decode(s *schema.ProtocolSchema, data []byte) (*DecodeResult, error)
Decode deserialises data into a packet according to the schema.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes a Packet (map[string]any) into raw bytes according to a ProtocolSchema.
func NewEncoder ¶
func NewEncoder(cr *checksum.ChecksumRegistry, fr *format.FormatRegistry) *Encoder
NewEncoder creates a new Encoder with the given registries.