/
structMap.go
46 lines (37 loc) · 1.38 KB
/
structMap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package atlas
import "reflect"
type StructMap struct {
// A slice of descriptions of each field in the type.
// Each entry specifies the name by which each field should be referenced
// when serialized, and defines a way to get an address to the field.
Fields []StructMapEntry
}
type StructMapEntry struct {
// The field name; will be emitted as token during marshal, and used for
// lookup during unmarshal. Required.
SerialName string
// If true, a key token with this SerialName will be ignored during unmarshal.
// (By default, if there's no StructMapEntry for a key token, it's an error.)
// If true, the ReflectRoute, Type, etc fields are irrelevant and may be nil.
Ignore bool
ReflectRoute ReflectRoute // reflection generates these.
Type reflect.Type // type to expect on the far side of the ReflectRoute.
tagged bool // used during autogen.
// Theoretical feature which would be alternative to ReflectRoute. Support dropped for the moment.
//addrFunc func(interface{}) interface{} // custom user function.
// If true, marshalling will skip this field if it's the zero value.
OmitEmpty bool
}
type ReflectRoute []int
func (rr ReflectRoute) TraverseToValue(v reflect.Value) reflect.Value {
for _, i := range rr {
if v.Kind() == reflect.Ptr {
if v.IsNil() {
return reflect.Value{}
}
v = v.Elem()
}
v = v.Field(i)
}
return v
}