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

Function encodeFuncStructOf

thrift/encode.go:344–376  ·  view source on GitHub ↗
(t reflect.Type, seen encodeFuncCache)

Source from the content-addressed store, hash-verified

342}
343
344func encodeFuncStructOf(t reflect.Type, seen encodeFuncCache) encodeFunc {
345 enc := &structEncoder{
346 fields: make([]structEncoderField, 0, t.NumField()),
347 }
348 encode := enc.encode
349 seen[t] = encode
350
351 forEachStructField(t, nil, func(f structField) {
352 if f.flags.have(union) {
353 enc.union = true
354 } else {
355 enc.fields = append(enc.fields, structEncoderField{
356 index: f.index,
357 id: f.id,
358 flags: f.flags,
359 typ: TypeOf(f.typ),
360 encode: encodeFuncStructFieldOf(f, seen),
361 })
362 }
363 })
364
365 sort.SliceStable(enc.fields, func(i, j int) bool {
366 return enc.fields[i].id < enc.fields[j].id
367 })
368
369 for i := len(enc.fields) - 1; i > 0; i-- {
370 if enc.fields[i-1].id == enc.fields[i].id {
371 panic(fmt.Errorf("thrift struct field id %d is present multiple times", enc.fields[i].id))
372 }
373 }
374
375 return encode
376}
377
378func encodeFuncStructFieldOf(f structField, seen encodeFuncCache) encodeFunc {
379 if f.flags.have(enum) {

Callers 1

encodeFuncOfFunction · 0.85

Calls 5

forEachStructFieldFunction · 0.85
encodeFuncStructFieldOfFunction · 0.85
haveMethod · 0.80
TypeOfFunction · 0.70
NumFieldMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…