MCPcopy Create free account
hub / github.com/segmentio/encoding / structSizeFuncOf

Function structSizeFuncOf

proto/struct.go:166–212  ·  view source on GitHub ↗
(t reflect.Type, fields []structField)

Source from the content-addressed store, hash-verified

164}
165
166func structSizeFuncOf(t reflect.Type, fields []structField) sizeFunc {
167 inlined := inlined(t)
168 var unique, repeated []*structField
169
170 for i := range fields {
171 f := &fields[i]
172 if f.repeated() {
173 repeated = append(repeated, f)
174 } else {
175 unique = append(unique, f)
176 }
177 }
178
179 return func(p unsafe.Pointer, flags flags) int {
180 if p == nil {
181 return 0
182 }
183
184 if !inlined {
185 flags = flags.without(inline | toplevel)
186 } else {
187 flags = flags.without(toplevel)
188 }
189 n := 0
190
191 for _, f := range unique {
192 size := f.codec.size(f.pointer(p), f.makeFlags(flags))
193 if size > 0 {
194 n += int(f.tagsize) + size
195 if f.embedded() {
196 n += sizeOfVarint(uint64(size))
197 }
198 flags = flags.without(wantzero)
199 }
200 }
201
202 for _, f := range repeated {
203 size := f.codec.size(f.pointer(p), f.makeFlags(flags))
204 if size > 0 {
205 n += size
206 flags = flags.without(wantzero)
207 }
208 }
209
210 return n
211 }
212}
213
214func structEncodeFuncOf(t reflect.Type, fields []structField) encodeFunc {
215 inlined := inlined(t)

Callers 1

structCodecOfFunction · 0.85

Calls 7

sizeOfVarintFunction · 0.85
repeatedMethod · 0.80
pointerMethod · 0.80
makeFlagsMethod · 0.80
embeddedMethod · 0.80
inlinedFunction · 0.70
withoutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…