rowcodec

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

binary_codec.go provides a custom binary encoding/decoding for Row data (map[string]any) optimized for memory efficiency and performance.

Binary Format:

Map: [uint32: num_pairs] + pairs
Pair: [uint32: key_len][key_bytes][type_byte][value_data]

Type bytes:

0 = nil
1 = bool (1 byte: 0=false, 1=true)
2 = int64 (8 bytes, little endian)
3 = float64 (8 bytes, little endian)
4 = string ([uint32: len][bytes])
5 = []byte ([uint32: len][bytes])
6 = int32 (4 bytes, little endian) - promoted to int64
7 = float32 (4 bytes, little endian) - promoted to float64

This format avoids reflection entirely for maximum memory efficiency.

cbor_codec.go provides CBOR encoding/decoding for Row data.

Package rowcodec provides encoding/decoding interfaces for Row data (map[string]any) with multiple implementation options.

gob_codec.go provides GOB encoding/decoding for Row data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryCodec

type BinaryCodec struct{}

BinaryCodec holds the binary encoder/decoder.

func NewBinaryCodec

func NewBinaryCodec() (*BinaryCodec, error)

NewBinaryCodec creates a new binary codec.

func (*BinaryCodec) Decode

func (c *BinaryCodec) Decode(data []byte, into map[string]any) error

Decode decodes binary bytes into the supplied map[string]any. The supplied map is cleared before decoding.

func (*BinaryCodec) DecodeRow

func (c *BinaryCodec) DecodeRow(data []byte, into pipeline.Row) error

DecodeRow decodes binary bytes into the supplied Row (map[wkk.RowKey]any). The supplied Row is cleared before decoding.

func (*BinaryCodec) Encode

func (c *BinaryCodec) Encode(row map[string]any) ([]byte, error)

Encode encodes a map[string]any to binary bytes.

func (*BinaryCodec) EncodeRow

func (c *BinaryCodec) EncodeRow(row pipeline.Row) ([]byte, error)

EncodeRow encodes a Row (map[wkk.RowKey]any) to binary bytes.

func (*BinaryCodec) NewDecoder

func (c *BinaryCodec) NewDecoder(r io.Reader) Decoder

NewDecoder creates a new binary decoder.

func (*BinaryCodec) NewEncoder

func (c *BinaryCodec) NewEncoder(w io.Writer) Encoder

NewEncoder creates a new binary encoder.

type BinaryDecoder

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

BinaryDecoder reads binary-encoded map data from an io.Reader.

func (*BinaryDecoder) Decode

func (d *BinaryDecoder) Decode(into map[string]any) error

Decode reads a map[string]any from binary format.

func (*BinaryDecoder) DecodeInto

func (d *BinaryDecoder) DecodeInto(target map[string]any) error

DecodeInto reads binary data into the provided map, which should be empty or will be cleared.

type BinaryEncoder

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

BinaryEncoder writes binary-encoded map data to an io.Writer.

func (*BinaryEncoder) Encode

func (e *BinaryEncoder) Encode(row map[string]any) error

Encode writes a map[string]any in binary format.

type CBORCodec

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

CBORCodec holds the CBOR encoder/decoder configuration.

func NewCBORCodec

func NewCBORCodec() (*CBORCodec, error)

NewCBORCodec creates a new CBOR codec.

func (*CBORCodec) Decode

func (c *CBORCodec) Decode(data []byte, into map[string]any) error

Decode decodes CBOR bytes into the supplied map[string]any. The supplied map is cleared before decoding.

func (*CBORCodec) DecodeRow

func (c *CBORCodec) DecodeRow(data []byte, into pipeline.Row) error

DecodeRow decodes CBOR bytes into the supplied Row (map[wkk.RowKey]any). The supplied Row is cleared before decoding.

func (*CBORCodec) Encode

func (c *CBORCodec) Encode(row map[string]any) ([]byte, error)

Encode encodes a map[string]any to CBOR bytes.

func (*CBORCodec) EncodeRow

func (c *CBORCodec) EncodeRow(row pipeline.Row) ([]byte, error)

EncodeRow encodes a Row (map[wkk.RowKey]any) to CBOR bytes.

func (*CBORCodec) NewDecoder

func (c *CBORCodec) NewDecoder(r io.Reader) Decoder

NewDecoder creates a new CBOR decoder.

func (*CBORCodec) NewEncoder

func (c *CBORCodec) NewEncoder(w io.Writer) Encoder

NewEncoder creates a new CBOR encoder.

type CBORDecoder

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

CBORDecoder reads CBOR-encoded map data from an io.Reader.

func (*CBORDecoder) Decode

func (d *CBORDecoder) Decode(into map[string]any) error

Decode reads into the supplied map[string]any from CBOR format. The supplied map is cleared before decoding. Returns io.EOF when no more data is available.

type CBOREncoder

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

CBOREncoder writes CBOR-encoded map data to an io.Writer.

func (*CBOREncoder) Encode

func (e *CBOREncoder) Encode(row map[string]any) error

Encode writes a map[string]any in CBOR format.

type Codec

type Codec interface {
	// Encode encodes a map[string]any to bytes.
	Encode(row map[string]any) ([]byte, error)

	// Decode decodes bytes into the supplied map[string]any.
	// The supplied map is cleared before decoding.
	Decode(data []byte, into map[string]any) error

	// EncodeRow encodes a Row (map[wkk.RowKey]any) to bytes.
	EncodeRow(row pipeline.Row) ([]byte, error)

	// DecodeRow decodes bytes into the supplied Row (map[wkk.RowKey]any).
	// The supplied Row is cleared before decoding.
	DecodeRow(data []byte, into pipeline.Row) error

	// NewEncoder creates a new encoder that writes to the given writer.
	NewEncoder(w io.Writer) Encoder

	// NewDecoder creates a new decoder that reads from the given reader.
	NewDecoder(r io.Reader) Decoder
}

Codec defines the interface for encoding/decoding row data.

func New

func New(t Type) (Codec, error)

New creates a new codec of the specified type. TypeDefault uses CBOR for better performance (smaller files, less memory).

func NewBinary

func NewBinary() (Codec, error)

NewBinary creates a new binary codec.

func NewCBOR

func NewCBOR() (Codec, error)

NewCBOR creates a new CBOR codec.

func NewGOB

func NewGOB() (Codec, error)

NewGOB creates a new GOB codec.

type Decoder

type Decoder interface {
	// Decode reads into the supplied map[string]any from the codec's format.
	// The supplied map is cleared before decoding.
	// Returns io.EOF when no more data is available.
	Decode(into map[string]any) error
}

Decoder defines the interface for streaming decoding.

type Encoder

type Encoder interface {
	// Encode writes a map[string]any in the codec's format.
	Encode(row map[string]any) error
}

Encoder defines the interface for streaming encoding.

type GOBCodec

type GOBCodec struct{}

GOBCodec holds the GOB encoder/decoder.

func NewGOBCodec

func NewGOBCodec() (*GOBCodec, error)

NewGOBCodec creates a new GOB codec.

func (*GOBCodec) Decode

func (c *GOBCodec) Decode(data []byte, into map[string]any) error

Decode decodes GOB bytes into the supplied map[string]any. The supplied map is cleared before decoding.

func (*GOBCodec) DecodeRow

func (c *GOBCodec) DecodeRow(data []byte, into pipeline.Row) error

DecodeRow decodes GOB bytes into the supplied Row (map[wkk.RowKey]any). The supplied Row is cleared before decoding.

func (*GOBCodec) Encode

func (c *GOBCodec) Encode(row map[string]any) ([]byte, error)

Encode encodes a map[string]any to GOB bytes.

func (*GOBCodec) EncodeRow

func (c *GOBCodec) EncodeRow(row pipeline.Row) ([]byte, error)

EncodeRow encodes a Row (map[wkk.RowKey]any) to GOB bytes.

func (*GOBCodec) NewDecoder

func (c *GOBCodec) NewDecoder(r io.Reader) Decoder

NewDecoder creates a new GOB decoder.

func (*GOBCodec) NewEncoder

func (c *GOBCodec) NewEncoder(w io.Writer) Encoder

NewEncoder creates a new GOB encoder.

type GOBDecoder

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

GOBDecoder reads GOB-encoded map data from an io.Reader.

func (*GOBDecoder) Decode

func (d *GOBDecoder) Decode(into map[string]any) error

Decode reads into the supplied map[string]any from GOB format. The supplied map is cleared before decoding. Returns io.EOF when no more data is available.

type GOBEncoder

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

GOBEncoder writes GOB-encoded map data to an io.Writer.

func (*GOBEncoder) Encode

func (e *GOBEncoder) Encode(row map[string]any) error

Encode writes a map[string]any in GOB format.

type RowDecoder

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

RowDecoder reads binary-encoded Row data from an io.Reader, preserving RowKey handles.

func NewRowDecoder

func NewRowDecoder(r io.Reader) *RowDecoder

NewRowDecoder creates a new Row decoder that preserves RowKey handles.

func (*RowDecoder) DecodeRow

func (d *RowDecoder) DecodeRow(into pipeline.Row) error

DecodeRow reads a pipeline.Row from binary format, preserving RowKey handles.

type RowEncoder

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

RowEncoder writes binary-encoded Row data to an io.Writer, preserving RowKey handles.

func NewRowEncoder

func NewRowEncoder(w io.Writer) *RowEncoder

NewRowEncoder creates a new Row encoder that preserves RowKey handles.

func (*RowEncoder) EncodeRow

func (e *RowEncoder) EncodeRow(row pipeline.Row) error

EncodeRow writes a pipeline.Row in binary format without converting keys to strings.

type Type

type Type string

Type represents the available codec types.

const (
	// default type
	TypeDefault Type = ""
	// TypeBinary is the custom binary codec.
	TypeBinary Type = "binary"
	// TypeCBOR is the CBOR codec.
	TypeCBOR Type = "cbor"
	// TypeGOB is the GOB codec.
	TypeGOB Type = "gob"
)

Jump to

Keyboard shortcuts

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