MCPcopy Index your code
hub / github.com/segmentio/encoding / appendStructFields

Function appendStructFields

json/codec.go:550–740  ·  view source on GitHub ↗
(fields []structField, t reflect.Type, offset uintptr, seen map[reflect.Type]*structType, canAddr bool)

Source from the content-addressed store, hash-verified

548}
549
550func appendStructFields(fields []structField, t reflect.Type, offset uintptr, seen map[reflect.Type]*structType, canAddr bool) []structField {
551 type embeddedField struct {
552 index int
553 offset uintptr
554 pointer bool
555 unexported bool
556 subtype *structType
557 subfield *structField
558 }
559
560 names := make(map[string]struct{})
561 embedded := make([]embeddedField, 0, 10)
562
563 for i := range t.NumField() {
564 f := t.Field(i)
565
566 var (
567 name = f.Name
568 anonymous = f.Anonymous
569 tag = false
570 omitempty = false
571 stringify = false
572 unexported = len(f.PkgPath) != 0
573 )
574
575 if unexported && !anonymous { // unexported
576 continue
577 }
578
579 if parts := strings.Split(f.Tag.Get("json"), ","); len(parts) != 0 {
580 if len(parts[0]) != 0 {
581 name, tag = parts[0], true
582 }
583
584 if name == "-" && len(parts) == 1 { // ignored
585 continue
586 }
587
588 if !isValidTag(name) {
589 name = f.Name
590 }
591
592 for _, tag := range parts[1:] {
593 switch tag {
594 case "omitempty":
595 omitempty = true
596 case "string":
597 stringify = true
598 }
599 }
600 }
601
602 if anonymous && !tag { // embedded
603 typ := f.Type
604 ptr := f.Type.Kind() == reflect.Ptr
605
606 if ptr {
607 typ = f.Type.Elem()

Callers 1

constructStructTypeFunction · 0.85

Calls 13

isValidTagFunction · 0.85
constructStructTypeFunction · 0.85
constructCodecFunction · 0.85
emptyFuncOfFunction · 0.85
encodeKeyFragmentFunction · 0.85
NumFieldMethod · 0.65
FieldMethod · 0.65
KindMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…