Documentation
¶
Overview ¶
Package atom provides type-segregated atomic value storage.
Index ¶
- Variables
- type Atom
- type Atomizable
- type Atomizer
- func (a *Atomizer[T]) Atomize(obj *T) *Atom
- func (a *Atomizer[T]) Deatomize(atom *Atom) (*T, error)
- func (a *Atomizer[T]) Fields() []Field
- func (a *Atomizer[T]) FieldsIn(table Table) []string
- func (a *Atomizer[T]) NewAtom() *Atom
- func (a *Atomizer[T]) Spec() Spec
- func (a *Atomizer[T]) TableFor(field string) (Table, bool)
- type Deatomizable
- type Field
- type Spec
- type Table
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOverflow indicates a numeric value exceeds the target type's range. // Returned during Deatomize when an int64/uint64/float64 value cannot fit // in a narrower type (e.g., int8, uint16, float32). ErrOverflow = errors.New("numeric overflow") // ErrUnsupportedType indicates a struct field has a type that cannot be atomized. // Returned during Use[T]() registration for types like channels, functions, // interfaces, or maps with non-string keys. ErrUnsupportedType = errors.New("unsupported type") // ErrSizeMismatch indicates a byte slice length doesn't match a fixed-size array. // Returned during Deatomize when a []byte value is assigned to a [N]byte field // but the lengths differ. ErrSizeMismatch = errors.New("size mismatch") )
Sentinel errors for programmatic error handling. Use errors.Is() to check for these error types.
Functions ¶
This section is empty.
Types ¶
type Atom ¶
type Atom struct {
// Scalars
Strings map[string]string
Ints map[string]int64
Uints map[string]uint64
Floats map[string]float64
Bools map[string]bool
Times map[string]time.Time
Bytes map[string][]byte
// Pointers (nullable)
StringPtrs map[string]*string
IntPtrs map[string]*int64
UintPtrs map[string]*uint64
FloatPtrs map[string]*float64
BoolPtrs map[string]*bool
TimePtrs map[string]*time.Time
BytePtrs map[string]*[]byte
// Slices
StringSlices map[string][]string
IntSlices map[string][]int64
UintSlices map[string][]uint64
FloatSlices map[string][]float64
BoolSlices map[string][]bool
TimeSlices map[string][]time.Time
ByteSlices map[string][][]byte
// Maps (string-keyed)
StringMaps map[string]map[string]string
IntMaps map[string]map[string]int64
UintMaps map[string]map[string]uint64
FloatMaps map[string]map[string]float64
BoolMaps map[string]map[string]bool
TimeMaps map[string]map[string]time.Time
ByteMaps map[string]map[string][]byte
// Nested
Nested map[string]Atom
NestedSlices map[string][]Atom
NestedMaps map[string]map[string]Atom
// Metadata (placed last for optimal alignment)
Spec Spec
}
Atom holds decomposed atomic values by type.
type Atomizable ¶
type Atomizable interface {
Atomize(*Atom)
}
Atomizable allows types to provide custom atomization logic. If a type implements this interface, it will be used instead of reflection. This enables code generation to avoid reflection overhead.
type Atomizer ¶
type Atomizer[T any] struct { // contains filtered or unexported fields }
Atomizer provides typed bidirectional resolution for type T.
func Use ¶
Use registers and returns an Atomizer for type T. First call builds the atomizer; subsequent calls return the cached instance. Returns an error if the type contains unsupported field types.
func (*Atomizer[T]) Atomize ¶
Atomize converts an object to its atomic representation. If T implements Atomizable, that method is used instead of reflection.
func (*Atomizer[T]) Deatomize ¶
Deatomize reconstructs an object from an Atom. If T implements Deatomizable, that method is used instead of reflection.
type Deatomizable ¶
Deatomizable allows types to provide custom deatomization logic. If a type implements this interface, it will be used instead of reflection. This enables code generation to avoid reflection overhead.
type Spec ¶
Spec is metadata describing a struct type. Aliased from sentinel.Metadata to decouple downstream users from sentinel.
type Table ¶
type Table string
Table identifies the segregated storage table for atomic values.
const ( TableStrings Table = "strings" TableInts Table = "ints" TableUints Table = "uints" TableFloats Table = "floats" TableBools Table = "bools" TableTimes Table = "times" TableBytes Table = "bytes" TableBytePtrs Table = "byte_ptrs" TableStringPtrs Table = "string_ptrs" TableIntPtrs Table = "int_ptrs" TableUintPtrs Table = "uint_ptrs" TableFloatPtrs Table = "float_ptrs" TableBoolPtrs Table = "bool_ptrs" TableTimePtrs Table = "time_ptrs" TableStringSlices Table = "string_slices" TableIntSlices Table = "int_slices" TableUintSlices Table = "uint_slices" TableFloatSlices Table = "float_slices" TableBoolSlices Table = "bool_slices" TableTimeSlices Table = "time_slices" TableByteSlices Table = "byte_slices" TableStringMaps Table = "string_maps" TableIntMaps Table = "int_maps" TableUintMaps Table = "uint_maps" TableFloatMaps Table = "float_maps" TableBoolMaps Table = "bool_maps" TableTimeMaps Table = "time_maps" TableByteMaps Table = "byte_maps" TableNestedMaps Table = "nested_maps" )
Table constants for type-segregated storage.
func TableForField ¶
TableForField returns the storage table for a field by Spec lookup. Requires the type to have been registered via Use[T]().