Documentation
¶
Index ¶
- Constants
- Variables
- func AlignedBuffer(size int) []byte
- func CloneAny(v any) any
- func HashKey(key string) uint32
- func MarshalAny(v any) ([]byte, uint8, error)
- func SliceSwizzle[T any](buf []byte, offset uintptr, length int) []T
- func StringSwizzle(buf []byte, offset uintptr, length int) string
- func StringSwizzleUnchecked(buf []byte, offset uintptr, length int) string
- type Dynamic
- func (d *Dynamic) Bool() bool
- func (d *Dynamic) Bytes() []byte
- func (d *Dynamic) Float() float64
- func (d *Dynamic) Get(key string) *Dynamic
- func (d *Dynamic) GetOK(key string) (*Dynamic, bool)
- func (d *Dynamic) Int() int64
- func (d *Dynamic) Interface() any
- func (d *Dynamic) IsNil() bool
- func (d *Dynamic) Keys() []string
- func (d *Dynamic) Len() int
- func (d *Dynamic) Map(keys []string) map[string]*Dynamic
- func (d *Dynamic) Raw() []byte
- func (d *Dynamic) Slice() []*Dynamic
- func (d *Dynamic) String() string
- func (d *Dynamic) ToMap() (map[string]any, error)
- func (d *Dynamic) ToSlice() ([]any, error)
- func (d *Dynamic) Type() uint8
- func (d *Dynamic) Uint() uint64
- type Pool
Constants ¶
const ( TypeNull uint8 = iota TypeInt TypeFloat TypeBool TypeString TypeBytes TypeMap TypeSlice TypeUint )
HIBI Type Constants
const Version = "v0.1.5"
Version is the current version of the Litz serialization library.
Variables ¶
var ( ErrBufferTooShort = errors.New("litz.Unmarshal: buffer too short for fixed part") ErrStringOutOfBounds = errors.New("litz.Unmarshal: string out of bounds") ErrSliceOutOfBounds = errors.New("litz.Unmarshal: slice out of bounds") ErrPointerOutOfBounds = errors.New("litz.Unmarshal: nested pointer out of bounds") ErrSizeOverflow = errors.New("litz.Marshal: size integer overflow") ErrInvalidHeader = errors.New("litz.Unmarshal: invalid format signature or version") ErrInvalidHIBIType = errors.New("litz.Dynamic: invalid type for this operation") )
Sentinel Errors to avoid heap allocations on error paths
Functions ¶
func AlignedBuffer ¶
AlignedBuffer allocates a byte slice. Go's runtime allocator aligns heap allocations to 8-byte boundaries automatically for sizes >= 8 bytes.
func CloneAny ¶
CloneAny performs a deep copy of common interface{} types to prevent use-after-free.
func MarshalAny ¶
MarshalAny serializes any Go value into the HIBI format. Returns the serialized bytes, type identifier, and error.
func SliceSwizzle ¶
SliceSwizzle converts an offset in buf to a valid Go slice. WARNING: The returned slice points directly into the buffer memory.
func StringSwizzle ¶
StringSwizzle converts an offset in buf to a valid Go string. WARNING: The returned string points directly into the buffer memory. The buffer MUST outlive the returned string to avoid use-after-free corruption.
func StringSwizzleUnchecked ¶
StringSwizzleUnchecked is an unchecked variant of StringSwizzle. Re-uses direct string backing arrays without runtime bounds checking. WARNING: Calling this with a corrupted or malicious offset will trigger a segmentation fault or memory read violation.
Types ¶
type Dynamic ¶
type Dynamic struct {
// contains filtered or unexported fields
}
Dynamic represents unstructured schema-less data backed by raw bytes. It implements the Hash-Indexed Binary Index (HIBI) protocol.
func NewDynamic ¶
NewDynamic creates a new Dynamic reader wrapping the given HIBI buffer and type code.
func (*Dynamic) Get ¶
Get performs an O(log N) binary search lookup for a key inside a HIBI map. Crucially, it resolves hash collisions by verifying the full key string.
func (*Dynamic) GetOK ¶ added in v0.1.4
GetOK is like Get, but also returns a boolean indicating whether the key was found.
func (*Dynamic) Interface ¶ added in v0.1.4
Interface converts the Dynamic value back to a standard Go interface representation.
func (*Dynamic) Map ¶
Map converts the HIBI payload into a standard Go map[string]*Dynamic. Validates that this Dynamic object is actually a Map.
func (*Dynamic) Slice ¶
Slice returns the dynamic elements if this Dynamic object is a slice. Validates that this Dynamic object is actually a Slice and resolves the dynamic element type from the slice header.
func (*Dynamic) ToMap ¶ added in v0.1.4
ToMap converts the Dynamic object back to a standard Go map[string]any. Returns an error if the underlying value is not a HIBI map.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a wrapper around sync.Pool for reusing serialization buffers.
func (*Pool) Put ¶
Put returns a buffer back to the pool. To prevent memory bloat during massive payload spikes, buffers with capacity larger than 16MB are discarded rather than returned to the pool. Note: We accept and return *[]byte (pointer to slice header) rather than []byte to prevent the Go runtime from allocating interface boxing containers on sync.Pool.Put, maintaining true zero-allocation execution on recycled paths.