Documentation
¶
Overview ¶
Package cryodecoder provides a high-performance, type-safe, extensible binary encoding/decoding system using a TLV (Tag-Length-Value) format.
Index ¶
- Constants
- type ArrayCodec
- type BoolCodec
- type Codec
- type CodecRegistry
- func (r *CodecRegistry) GetCodec(tag byte) (Codec, error)
- func (r *CodecRegistry) GetTag(value interface{}) (byte, error)
- func (r *CodecRegistry) RegisterCodec(tag byte, codec Codec, exampleType interface{})
- func (r *CodecRegistry) RegisterPrimitives()
- func (r *CodecRegistry) RegisterStruct(exampleType interface{}) (byte, error)
- type Complex128Codec
- type Complex64Codec
- type Decoder
- type Encoder
- type Float32Codec
- type Float64Codec
- type Int16Codec
- type Int32Codec
- type Int64Codec
- type Int8Codec
- type IntCodec
- type InterfaceCodec
- type LocationCodec
- type MapCodec
- type MapStringAnyCodec
- type MarshalerCodec
- type PointerCodec
- type SliceCodec
- type StringCodec
- type StructCodec
- type Uint16Codec
- type Uint32Codec
- type Uint64Codec
- type Uint8Codec
- type UintCodec
- type UintptrCodec
Constants ¶
const ( BOF = 0xAB // Beginning of Frame EOF = 0xCD // End of Frame )
BOF and EOF are markers that frame a complete object in the binary stream.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayCodec ¶ added in v1.1.0
type ArrayCodec struct {
// contains filtered or unexported fields
}
ArrayCodec handles array types [N]T. It stores each encoded element in order.
func (*ArrayCodec) Decode ¶ added in v1.1.0
func (c *ArrayCodec) Decode(data []byte) (interface{}, error)
func (*ArrayCodec) Encode ¶ added in v1.1.0
func (c *ArrayCodec) Encode(value interface{}) ([]byte, error)
type Codec ¶
type Codec interface {
Encode(value interface{}) ([]byte, error)
Decode(data []byte) (interface{}, error)
}
Codec defines the interface for any type that can encode and decode a specific data type.
type CodecRegistry ¶
type CodecRegistry struct {
// contains filtered or unexported fields
}
CodecRegistry maps a single-byte tag to a Codec implementation and a Go type. It handles automatic registration of struct fields via reflection.
func NewCodecRegistry ¶
func NewCodecRegistry() *CodecRegistry
NewCodecRegistry creates and returns an empty CodecRegistry.
func (*CodecRegistry) GetCodec ¶
func (r *CodecRegistry) GetCodec(tag byte) (Codec, error)
GetCodec retrieves the Codec associated with a given tag.
func (*CodecRegistry) GetTag ¶
func (r *CodecRegistry) GetTag(value interface{}) (byte, error)
GetTag retrieves the tag associated with a given value's type.
func (*CodecRegistry) RegisterCodec ¶
func (r *CodecRegistry) RegisterCodec(tag byte, codec Codec, exampleType interface{})
RegisterCodec is a low-level method to associate a tag with a Codec and a Go type.
func (*CodecRegistry) RegisterPrimitives ¶
func (r *CodecRegistry) RegisterPrimitives()
RegisterPrimitives is a convenience method to register the built-in primitive codecs. MODIFIED: Added tags 20 (time.Location) and updated interface/map tags.
func (*CodecRegistry) RegisterStruct ¶
func (r *CodecRegistry) RegisterStruct(exampleType interface{}) (byte, error)
RegisterStruct automatically registers a custom struct and all of its nested structs. MODIFIED: Uses resolveType to handle pointers, nested structs, and specific types automatically.
type Complex128Codec ¶
type Complex128Codec struct{} // Two float64s
func (*Complex128Codec) Decode ¶
func (c *Complex128Codec) Decode(data []byte) (interface{}, error)
func (*Complex128Codec) Encode ¶
func (c *Complex128Codec) Encode(value interface{}) ([]byte, error)
type Complex64Codec ¶
type Complex64Codec struct{} // Two float32s
Complex Number Codecs
func (*Complex64Codec) Decode ¶
func (c *Complex64Codec) Decode(data []byte) (interface{}, error)
func (*Complex64Codec) Encode ¶
func (c *Complex64Codec) Encode(value interface{}) ([]byte, error)
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func NewDecoder(registry *CodecRegistry, reader io.Reader) *Decoder
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func NewEncoder(registry *CodecRegistry) *Encoder
type Float32Codec ¶
type Float32Codec struct{}
Floating-point Codecs
func (*Float32Codec) Decode ¶
func (c *Float32Codec) Decode(data []byte) (interface{}, error)
func (*Float32Codec) Encode ¶
func (c *Float32Codec) Encode(value interface{}) ([]byte, error)
type Float64Codec ¶
type Float64Codec struct{}
func (*Float64Codec) Decode ¶
func (c *Float64Codec) Decode(data []byte) (interface{}, error)
func (*Float64Codec) Encode ¶
func (c *Float64Codec) Encode(value interface{}) ([]byte, error)
type Int16Codec ¶
type Int16Codec struct{}
func (*Int16Codec) Decode ¶
func (c *Int16Codec) Decode(data []byte) (interface{}, error)
func (*Int16Codec) Encode ¶
func (c *Int16Codec) Encode(value interface{}) ([]byte, error)
type Int32Codec ¶
type Int32Codec struct{}
Integer Codecs
func (*Int32Codec) Decode ¶
func (c *Int32Codec) Decode(data []byte) (interface{}, error)
func (*Int32Codec) Encode ¶
func (c *Int32Codec) Encode(value interface{}) ([]byte, error)
type Int64Codec ¶
type Int64Codec struct{}
func (*Int64Codec) Decode ¶
func (c *Int64Codec) Decode(data []byte) (interface{}, error)
func (*Int64Codec) Encode ¶
func (c *Int64Codec) Encode(value interface{}) ([]byte, error)
type InterfaceCodec ¶
type InterfaceCodec struct {
// contains filtered or unexported fields
}
func (*InterfaceCodec) Decode ¶
func (c *InterfaceCodec) Decode(data []byte) (interface{}, error)
func (*InterfaceCodec) Encode ¶
func (c *InterfaceCodec) Encode(value interface{}) ([]byte, error)
type LocationCodec ¶
type LocationCodec struct{}
LocationCodec handles time.Location. It serializes the location name (e.g., "UTC", "America/New_York"). Note: This is best-effort. Custom locations created via FixedZone might not be portable.
func (*LocationCodec) Decode ¶
func (c *LocationCodec) Decode(data []byte) (interface{}, error)
func (*LocationCodec) Encode ¶
func (c *LocationCodec) Encode(value interface{}) ([]byte, error)
type MapCodec ¶ added in v1.1.0
type MapCodec struct {
// contains filtered or unexported fields
}
MapCodec handles map types map[K]V. It stores the count of entries followed by each key-value pair.
type MapStringAnyCodec ¶
type MapStringAnyCodec struct {
// contains filtered or unexported fields
}
func (*MapStringAnyCodec) Decode ¶
func (c *MapStringAnyCodec) Decode(data []byte) (interface{}, error)
func (*MapStringAnyCodec) Encode ¶
func (c *MapStringAnyCodec) Encode(value interface{}) ([]byte, error)
type MarshalerCodec ¶
type MarshalerCodec struct {
// contains filtered or unexported fields
}
func (*MarshalerCodec) Decode ¶
func (c *MarshalerCodec) Decode(data []byte) (interface{}, error)
func (*MarshalerCodec) Encode ¶
func (c *MarshalerCodec) Encode(value interface{}) ([]byte, error)
type PointerCodec ¶
type PointerCodec struct {
// contains filtered or unexported fields
}
PointerCodec handles pointer types (*T). It wraps the codec for T and adds logic to handle nil pointers.
func (*PointerCodec) Decode ¶
func (c *PointerCodec) Decode(data []byte) (interface{}, error)
func (*PointerCodec) Encode ¶
func (c *PointerCodec) Encode(value interface{}) ([]byte, error)
type SliceCodec ¶ added in v1.1.0
type SliceCodec struct {
// contains filtered or unexported fields
}
SliceCodec handles slice types []T. It stores the count of elements followed by each encoded element.
func (*SliceCodec) Decode ¶ added in v1.1.0
func (c *SliceCodec) Decode(data []byte) (interface{}, error)
func (*SliceCodec) Encode ¶ added in v1.1.0
func (c *SliceCodec) Encode(value interface{}) ([]byte, error)
type StringCodec ¶
type StringCodec struct{}
func (*StringCodec) Decode ¶
func (c *StringCodec) Decode(data []byte) (interface{}, error)
func (*StringCodec) Encode ¶
func (c *StringCodec) Encode(value interface{}) ([]byte, error)
type StructCodec ¶
type StructCodec struct {
// contains filtered or unexported fields
}
func NewStructCodec ¶
func NewStructCodec(registry *CodecRegistry, exampleType interface{}) *StructCodec
func (*StructCodec) Decode ¶
func (c *StructCodec) Decode(data []byte) (interface{}, error)
func (*StructCodec) Encode ¶
func (c *StructCodec) Encode(value interface{}) ([]byte, error)
func (*StructCodec) RegisterField ¶
func (c *StructCodec) RegisterField(fieldName string, typeTag byte)
type Uint16Codec ¶
type Uint16Codec struct{}
func (*Uint16Codec) Decode ¶
func (c *Uint16Codec) Decode(data []byte) (interface{}, error)
func (*Uint16Codec) Encode ¶
func (c *Uint16Codec) Encode(value interface{}) ([]byte, error)
type Uint32Codec ¶
type Uint32Codec struct{}
func (*Uint32Codec) Decode ¶
func (c *Uint32Codec) Decode(data []byte) (interface{}, error)
func (*Uint32Codec) Encode ¶
func (c *Uint32Codec) Encode(value interface{}) ([]byte, error)
type Uint64Codec ¶
type Uint64Codec struct{}
func (*Uint64Codec) Decode ¶
func (c *Uint64Codec) Decode(data []byte) (interface{}, error)
func (*Uint64Codec) Encode ¶
func (c *Uint64Codec) Encode(value interface{}) ([]byte, error)
type Uint8Codec ¶
type Uint8Codec struct{} // Also handles byte
Unsigned Integer Codecs
func (*Uint8Codec) Decode ¶
func (c *Uint8Codec) Decode(data []byte) (interface{}, error)
func (*Uint8Codec) Encode ¶
func (c *Uint8Codec) Encode(value interface{}) ([]byte, error)
type UintptrCodec ¶
type UintptrCodec struct{} // Serialized as uint64 for compatibility
func (*UintptrCodec) Decode ¶
func (c *UintptrCodec) Decode(data []byte) (interface{}, error)
func (*UintptrCodec) Encode ¶
func (c *UintptrCodec) Encode(value interface{}) ([]byte, error)