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

Function decodeFuncStructOf

thrift/decode.go:457–508  ·  view source on GitHub ↗
(t reflect.Type, seen decodeFuncCache)

Source from the content-addressed store, hash-verified

455}
456
457func decodeFuncStructOf(t reflect.Type, seen decodeFuncCache) decodeFunc {
458 dec := &structDecoder{
459 zero: reflect.Zero(t),
460 }
461 decode := dec.decode
462 seen[t] = decode
463
464 fields := make([]structDecoderField, 0, t.NumField())
465 forEachStructField(t, nil, func(f structField) {
466 if f.flags.have(union) {
467 dec.union = f.index
468 } else {
469 fields = append(fields, structDecoderField{
470 index: f.index,
471 id: f.id,
472 flags: f.flags,
473 typ: TypeOf(f.typ),
474 decode: decodeFuncStructFieldOf(f, seen),
475 })
476 }
477 })
478
479 minID := int16(0)
480 maxID := int16(0)
481
482 for _, f := range fields {
483 if f.id < minID || minID == 0 {
484 minID = f.id
485 }
486 if f.id > maxID {
487 maxID = f.id
488 }
489 }
490
491 dec.fields = make([]structDecoderField, (maxID-minID)+1)
492 dec.minID = minID
493 dec.required = make([]uint64, len(fields)/64+1)
494
495 for _, f := range fields {
496 i := f.id - minID
497 p := dec.fields[i]
498 if p.decode != nil {
499 panic(fmt.Errorf("thrift struct field id %d is present multiple times in %s with types %s and %s", f.id, t, p.typ, f.typ))
500 }
501 dec.fields[i] = f
502 if f.flags.have(required) {
503 dec.required[i/64] |= 1 << (i % 64)
504 }
505 }
506
507 return decode
508}
509
510func decodeFuncStructFieldOf(f structField, seen decodeFuncCache) decodeFunc {
511 if f.flags.have(enum) {

Callers 1

decodeFuncOfFunction · 0.85

Calls 5

forEachStructFieldFunction · 0.85
decodeFuncStructFieldOfFunction · 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…