MCPcopy Create free account
hub / github.com/Restream/reindexer / encodeStruct

Method encodeStruct

cjson/encoder.go:127–212  ·  view source on GitHub ↗
(v reflect.Value, rdser *Serializer, cache *ctagsWCache)

Source from the content-addressed store, hash-verified

125}
126
127func (enc *Encoder) encodeStruct(v reflect.Value, rdser *Serializer, cache *ctagsWCache) error {
128 t := v.Type()
129 numField := v.NumField()
130 var entries []ctagsWCacheEntry
131 if cache != nil {
132 entries = *cache
133 }
134 for field := range numField {
135 if cache != nil {
136 // We have not interface fields on top level, so using cache.
137 if field < len(entries) {
138 ce := &entries[field]
139 if ce.ctagName != 0 || ce.isPrivate {
140 if !ce.isPrivate {
141 // process field, except private unexported fields
142 err := enc.encodeValue(v.Field(field), rdser, ce.fieldInfo, &ce.subCache)
143 if err != nil {
144 return err
145 }
146 }
147 continue
148 }
149 }
150
151 ce := cache.LookupField(field)
152 if ce.ctagName != 0 || ce.isPrivate {
153 if !ce.isPrivate {
154 // process field, except private unexported fields
155 err := enc.encodeValue(v.Field(field), rdser, ce.fieldInfo, &ce.subCache)
156 if err != nil {
157 return err
158 }
159 }
160 continue
161 }
162
163 // No data in cache: use reflect to get data about field.
164 vv := v.Field(field)
165 f := t.Field(field)
166 name, skip, omitempty := parseStructField(f)
167 ctagName := 0
168 if !skip {
169 ctagName = enc.name2tag(name)
170 }
171
172 fi := mkFieldInfo(vv, ctagName, f)
173 fi.isPrivate = len(f.PkgPath) != 0 || skip
174 fi.isOmitEmpty = omitempty
175
176 var subCache *ctagsWCache
177 if !enc.tmUpdated {
178 ce.fieldInfo = fi
179 if !fi.isPrivate {
180 subCache = &ce.subCache
181 }
182 }
183 if !fi.isPrivate {
184 // process field, except private unexported fields

Callers 1

encodeValueMethod · 0.95

Calls 7

encodeValueMethod · 0.95
name2tagMethod · 0.95
parseStructFieldFunction · 0.85
mkFieldInfoFunction · 0.85
LookupFieldMethod · 0.80
TypeMethod · 0.65
FieldMethod · 0.45

Tested by

no test coverage detected