Documentation
¶
Index ¶
- func AddrByTraversal(base unsafe.Pointer, steps []Step) unsafe.Pointer
- func Deref(t reflect.Type) reflect.Type
- func FieldByIndexes(v reflect.Value, indexes []int) reflect.Value
- func FieldByIndexesReadOnly(v reflect.Value, indexes []int) reflect.Value
- type FieldInfo
- type Mapper
- func (m *Mapper) FieldByName(v reflect.Value, name string) reflect.Value
- func (m *Mapper) FieldMap(t reflect.Type) map[string]*FieldInfo
- func (m *Mapper) TraversalsByName(t reflect.Type, names []string) [][]int
- func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error
- func (m *Mapper) TypeMap(t reflect.Type) *StructMap
- type Step
- type StructMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddrByTraversal ¶
AddrByTraversal returns the address of a field within a struct using pre-calculated steps.
SAFETY: This function operates on raw unsafe.Pointer addresses and allocates intermediate pointer fields via reflect.NewAt().Elem().Set() to maintain GC write barrier visibility. The caller MUST ensure:
- 'base' is derived from a heap-allocated reflect.New() Value (not a stack local).
- The reflect.Value that produced 'base' (via .Pointer()) remains rooted by a runtime.KeepAlive() call AFTER the Scan that writes through these pointers.
- The Steps slice was produced by the same Mapper.TypeMap that analysed the struct type, guaranteeing offset correctness.
Rooting chain: caller's vp (reflect.Value) → runtime.KeepAlive(vp) after Scan → base is reachable → all interior pointers allocated here are reachable.
func FieldByIndexes ¶
FieldByIndexes returns a value within a struct for the given index path.
Types ¶
type FieldInfo ¶
type FieldInfo struct {
Index []int
Path string
Field reflect.StructField
Zero reflect.Value
Name string
Options map[string]string
Embedded bool
Children []*FieldInfo
Parent *FieldInfo
Traversal []Step // Legacy support/pointer resolution
Offset uintptr // Linear offset relative to base struct (0 for top-level pointer embeds)
TargetType reflect.Type // The terminal type to scan into
IsPtrPath bool // True if any node in the path (e.g. parent) was accessed via pointer
}
FieldInfo is metadata for a struct field.
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper is a general purpose mapper of names to struct fields. A Mapper behaves like most other mappers in the Go ecosystem, mapping column names to struct fields using a set of rules.
func NewMapperFunc ¶
NewMapperFunc returns a new Mapper with a given struct tag and name mapping function.
func NewMapperFuncStrict ¶
NewMapperFuncStrict returns a new Mapper with strict tag validation enabled. When strict is true, struct tags are validated for correctness during TypeMap.
func NewMapperTagFunc ¶
func NewMapperTagFunc(tagName string, f func(string) string, tagMapFunc func(string) string) *Mapper
NewMapperTagFunc returns a new Mapper with a given struct tag, a name mapping function and a tag mapping function. The name mapping function (f) is used to transform field names when no tag is present. The tag mapping function (tagMapFunc) is applied to tag values after parsing.
func (*Mapper) FieldByName ¶
FieldByName returns a FieldInfo for the given column name.
func (*Mapper) TraversalsByName ¶
TraversalsByName returns a slice index-path slices for the struct type and the given names.
func (*Mapper) TraversalsByNameFunc ¶
func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error
TraversalsByNameFunc traverses the mapped names and calls fn with the index of each name and the struct traversal represented by that name. Panics if the struct cannot be mapped or if fn panics.
type Step ¶
type Step struct {
Offset uintptr
Type reflect.Type // If not nil, this step is a pointer that might need allocation of this Type
PtrType reflect.Type // Cache of reflect.PointerTo(Type) for zero-allocation write barrier Set
}
Step represents a single level of dereferencing or offset in a struct traversal.
type StructMap ¶
type StructMap struct {
Tree *FieldInfo
Index []*FieldInfo
Paths map[string]*FieldInfo
Names map[string]*FieldInfo
Errors []error // Populated when strict tag validation is enabled
}
StructMap represents a mapped struct, with fields flattened from embedded structs and ready for name-based lookup.