MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / populateMapField

Function populateMapField

runtime/query.go:188–206  ·  view source on GitHub ↗
(fieldDescriptor protoreflect.FieldDescriptor, mp protoreflect.Map, values []string)

Source from the content-addressed store, hash-verified

186}
187
188func populateMapField(fieldDescriptor protoreflect.FieldDescriptor, mp protoreflect.Map, values []string) error {
189 if len(values) != 2 {
190 return fmt.Errorf("more than one value provided for key %q in map %q", values[0], fieldDescriptor.FullName())
191 }
192
193 key, err := parseField(fieldDescriptor.MapKey(), values[0])
194 if err != nil {
195 return fmt.Errorf("parsing map key %q: %w", fieldDescriptor.FullName().Name(), err)
196 }
197
198 value, err := parseField(fieldDescriptor.MapValue(), values[1])
199 if err != nil {
200 return fmt.Errorf("parsing map value %q: %w", fieldDescriptor.FullName().Name(), err)
201 }
202
203 mp.Set(key.MapKey(), value)
204
205 return nil
206}
207
208func parseField(fieldDescriptor protoreflect.FieldDescriptor, value string) (protoreflect.Value, error) {
209 switch fieldDescriptor.Kind() {

Callers 1

Calls 2

parseFieldFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected