MCPcopy Create free account
hub / github.com/google/go-cloud / decodeStruct

Function decodeStruct

docstore/driver/codec.go:673–703  ·  view source on GitHub ↗
(v reflect.Value, d Decoder)

Source from the content-addressed store, hash-verified

671}
672
673func decodeStruct(v reflect.Value, d Decoder) error {
674 fs, err := fieldCache.Fields(v.Type())
675 if err != nil {
676 return err
677 }
678 d.DecodeMap(func(key string, d2 Decoder, exactMatch bool) bool {
679 if err != nil {
680 return false
681 }
682 var f *fields.Field
683 if exactMatch {
684 f = fs.MatchExact(key)
685 } else {
686 f = fs.MatchFold(key)
687 }
688 if f == nil {
689 err = gcerr.Newf(gcerr.InvalidArgument, nil, "no field matching %q in %s", key, v.Type())
690 return false
691 }
692 fv, ok := fieldByIndexCreate(v, f.Index)
693 if !ok {
694 err = gcerr.Newf(gcerr.InvalidArgument, nil,
695 "setting field %q in %s: cannot create embedded pointer field of unexported type",
696 key, v.Type())
697 return false
698 }
699 err = decode(fv, d2)
700 return err == nil
701 })
702 return err
703}
704
705// fieldByIndexCreate retrieves the the field of v at the given index if present,
706// creating embedded struct pointers where necessary.

Callers 2

DecodeMethod · 0.85
decodeFunction · 0.85

Calls 8

NewfFunction · 0.92
fieldByIndexCreateFunction · 0.85
FieldsMethod · 0.80
MatchExactMethod · 0.80
MatchFoldMethod · 0.80
decodeFunction · 0.70
DecodeMapMethod · 0.65
TypeMethod · 0.45

Tested by

no test coverage detected