MCPcopy Create free account
hub / github.com/tendermint/tendermint / decodeReflectMap

Function decodeReflectMap

libs/json/decoder.go:150–174  ·  view source on GitHub ↗
(bz []byte, rv reflect.Value)

Source from the content-addressed store, hash-verified

148}
149
150func decodeReflectMap(bz []byte, rv reflect.Value) error {
151 if !rv.CanAddr() {
152 return errors.New("map value is not addressable")
153 }
154
155 // Decode into a raw JSON map, using string keys.
156 rawMap := make(map[string]json.RawMessage)
157 if err := json.Unmarshal(bz, &rawMap); err != nil {
158 return err
159 }
160 if rv.Type().Key().Kind() != reflect.String {
161 return fmt.Errorf("map keys must be strings, got %v", rv.Type().Key().String())
162 }
163
164 // Recursively decode values.
165 rv.Set(reflect.MakeMapWithSize(rv.Type(), len(rawMap)))
166 for key, bz := range rawMap {
167 value := reflect.New(rv.Type().Elem()).Elem()
168 if err := decodeReflect(bz, value); err != nil {
169 return err
170 }
171 rv.SetMapIndex(reflect.ValueOf(key), value)
172 }
173 return nil
174}
175
176func decodeReflectStruct(bz []byte, rv reflect.Value) error {
177 if !rv.CanAddr() {

Callers 1

decodeReflectFunction · 0.85

Calls 6

decodeReflectFunction · 0.85
TypeMethod · 0.65
StringMethod · 0.65
SetMethod · 0.65
UnmarshalMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…