diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-26 13:59:35 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-29 02:14:35 -0700 |
commit | cf062e09037c7e54a821b05ef50b3e86683090f8 (patch) | |
tree | 2774971350856aba2c0607827eece0cabd63de52 /struct.go | |
parent | 403c22024921af1d66c6a3de7ee6431043465c39 (diff) |
Improve/fix documentation and comments
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() |