diff options
Diffstat (limited to 'struct.go')
-rw-r--r-- | struct.go | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -16,11 +16,15 @@ type structField struct { Quote bool } +// A structIndex is used by Decoder.Decode() and Encoder.Encode() when +// decoding-to or encoding-from a struct. type structIndex struct { byPos []structField byName map[string]int } +// indexStruct takes a struct Type, and indexes its fields for use by +// Decoder.Decode() and Encoder.Encode(). func indexStruct(typ reflect.Type) structIndex { var byPos []structField byName := make(map[string][]int) @@ -104,6 +108,12 @@ func indexStruct(typ reflect.Type) structIndex { return ret } +// indexStructInner crawls the struct `typ`, storing information on +// all struct fields foun in to `byPos` and `byName`. If `typ` +// contains other structs as fields, indexStructInner will recurse and +// call itself; keeping track of stack information with `stackPath` +// (which identifies where we are in the parent struct) and +// `stackSeen` (which is used for detecting loops). func indexStructInner(typ reflect.Type, byPos *[]structField, byName map[string][]int, stackPath []int, stackSeen map[reflect.Type]struct{}) { if _, ok := stackSeen[typ]; ok { return @@ -161,6 +171,8 @@ func indexStructInner(typ reflect.Type, byPos *[]structField, byName map[string] } } +// isQuotable returns whether a type is eligible for `json:,string` +// quoting. func isQuotable(typ reflect.Type) bool { for typ.Kind() == reflect.Pointer { typ = typ.Elem() |