{"modulePath":"github.com/hsqbyte/protospec","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package codec\n\n## Variables\n\n```go\nvar BufferPool = sync.Pool{\n\tNew: func() any {\n\t\tbuf := make([]byte, 0, 256)\n\t\treturn \u0026buf\n\t},\n}\n```\nBufferPool provides reusable byte buffers for encoding.\n\n## Functions\n\n```go\nfunc GetBuffer() *[]byte\n```\nGetBuffer returns a buffer from the pool.\n\n```go\nfunc PutBuffer(buf *[]byte)\n```\nPutBuffer returns a buffer to the pool.\n\n## Types\n\n```go\ntype BatchDecodeResult struct {\n\tResults []*DecodeResult\n\tErrors  []error\n}\n```\nBatchDecodeResult holds results from batch decoding.\n\n```go\ntype BitReader struct {\n\t// contains filtered or unexported fields\n}\n```\nBitReader reads bits from a byte slice. Bits are read MSB-first within each byte.\n\n```go\nfunc NewBitReader(data []byte) *BitReader\n```\nNewBitReader creates a new BitReader from a byte slice.\n\n```go\nfunc (r *BitReader) BitOffset() int\n```\nBitOffset returns the current bit offset within the current byte (0-7).\n\n```go\nfunc (r *BitReader) ByteOffset() int\n```\nByteOffset returns the current byte offset.\n\n```go\nfunc (r *BitReader) ReadBits(numBits int, order schema.ByteOrder) (uint64, error)\n```\nReadBits reads numBits bits (1-64) in the specified byte order and returns the value.\n\n```go\nfunc (r *BitReader) ReadBytes(n int) ([]byte, error)\n```\nReadBytes reads n bytes. The reader must be byte-aligned.\n\n```go\nfunc (r *BitReader) ReadRemainingBytes() []byte\n```\nReadRemainingBytes reads all remaining bytes. Must be byte-aligned.\n\n```go\nfunc (r *BitReader) RemainingBits() int\n```\nRemainingBits returns the number of remaining bits.\n\n```go\ntype BitWriter struct {\n\t// contains filtered or unexported fields\n}\n```\nBitWriter accumulates bits into a byte buffer. Bits are written MSB-first within each byte.\n\n```go\nfunc NewBitWriter() *BitWriter\n```\nNewBitWriter creates a new BitWriter.\n\n```go\nfunc (w *BitWriter) BitOffset() int\n```\nBitOffset returns the current bit offset within the current byte (0-7).\n\n```go\nfunc (w *BitWriter) Bytes() []byte\n```\nBytes returns the written bytes, flushing any partial byte with zero padding.\n\n```go\nfunc (w *BitWriter) Len() int\n```\nLen returns the number of complete bytes written so far.\n\n```go\nfunc (w *BitWriter) SetBytesAt(offset int, data []byte)\n```\nSetBytesAt overwrites bytes at a specific offset in the buffer. Used for checksum backfill after encoding.\n\n```go\nfunc (w *BitWriter) WriteBits(value uint64, numBits int, order schema.ByteOrder) error\n```\nWriteBits 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.\n\n```go\nfunc (w *BitWriter) WriteByteSlice(data []byte) error\n```\nWriteByteSlice writes raw bytes. The writer must be byte-aligned.\n\n```go\ntype CodecEngine struct {\n\t// contains filtered or unexported fields\n}\n```\nCodecEngine provides a unified encode/decode interface backed by Encoder and Decoder with shared registries.\n\n```go\nfunc NewCodecEngine(cr *checksum.ChecksumRegistry, fr *format.FormatRegistry) *CodecEngine\n```\nNewCodecEngine creates a new CodecEngine with the given registries.\n\n```go\nfunc (e *CodecEngine) BatchDecode(s interface{ GetSchema() interface{} }, packets [][]byte) *BatchDecodeResult\n```\nBatchDecode decodes multiple packets in sequence.\n\n```go\nfunc (e *CodecEngine) Decode(s *schema.ProtocolSchema, data []byte) (*DecodeResult, error)\n```\nDecode deserialises data into a DecodeResult according to the schema.\n\n```go\nfunc (e *CodecEngine) Encode(s *schema.ProtocolSchema, packet map[string]any) ([]byte, error)\n```\nEncode serialises packet into \\[]byte according to the schema.\n\n```go\ntype DecodeResult struct {\n\tPacket    map[string]any\n\tBytesRead int\n}\n```\nDecodeResult holds the decoded packet and the number of bytes consumed.\n\n```go\ntype Decoder struct {\n\t// contains filtered or unexported fields\n}\n```\nDecoder decodes raw bytes into a Packet (map\\[string]any) according to a ProtocolSchema.\n\n```go\nfunc NewDecoder(cr *checksum.ChecksumRegistry, fr *format.FormatRegistry) *Decoder\n```\nNewDecoder creates a new Decoder with the given registries.\n\n```go\nfunc (dec *Decoder) Decode(s *schema.ProtocolSchema, data []byte) (*DecodeResult, error)\n```\nDecode deserialises data into a packet according to the schema.\n\n```go\ntype Encoder struct {\n\t// contains filtered or unexported fields\n}\n```\nEncoder encodes a Packet (map\\[string]any) into raw bytes according to a ProtocolSchema.\n\n```go\nfunc NewEncoder(cr *checksum.ChecksumRegistry, fr *format.FormatRegistry) *Encoder\n```\nNewEncoder creates a new Encoder with the given registries.\n\n```go\nfunc (enc *Encoder) Encode(s *schema.ProtocolSchema, packet map[string]any) ([]byte, error)\n```\nEncode serialises packet into \\[]byte according to the schema.\n\n","path":"github.com/hsqbyte/protospec/src/codec","name":"codec","synopsis":"","isRedistributable":true}
