MCPcopy
hub / github.com/golang/protobuf / unmarshalValue

Method unmarshalValue

jsonpb/decode.go:410–456  ·  view source on GitHub ↗
(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor)

Source from the content-addressed store, hash-verified

408}
409
410func (u *Unmarshaler) unmarshalValue(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
411 switch {
412 case fd.IsList():
413 var jsonArray []json.RawMessage
414 if err := json.Unmarshal(in, &jsonArray); err != nil {
415 return v, err
416 }
417 lv := v.List()
418 for _, raw := range jsonArray {
419 ve, err := u.unmarshalSingularValue(lv.NewElement(), raw, fd)
420 if err != nil {
421 return v, err
422 }
423 lv.Append(ve)
424 }
425 return v, nil
426 case fd.IsMap():
427 var jsonObject map[string]json.RawMessage
428 if err := json.Unmarshal(in, &jsonObject); err != nil {
429 return v, err
430 }
431 kfd := fd.MapKey()
432 vfd := fd.MapValue()
433 mv := v.Map()
434 for key, raw := range jsonObject {
435 var kv protoreflect.MapKey
436 if kfd.Kind() == protoreflect.StringKind {
437 kv = protoreflect.ValueOf(key).MapKey()
438 } else {
439 v, err := u.unmarshalSingularValue(kfd.Default(), []byte(key), kfd)
440 if err != nil {
441 return v, err
442 }
443 kv = v.MapKey()
444 }
445
446 vv, err := u.unmarshalSingularValue(mv.NewValue(), raw, vfd)
447 if err != nil {
448 return v, err
449 }
450 mv.Set(kv, vv)
451 }
452 return v, nil
453 default:
454 return u.unmarshalSingularValue(v, in, fd)
455 }
456}
457
458var nonFinite = map[string]float64{
459 `"NaN"`: math.NaN(),

Callers 1

unmarshalMessageMethod · 0.95

Implementers 3

Bufferproto/buffer.go
InternalMessageInfoproto/deprecated.go
Unmarshalerjsonpb/decode.go

Calls 2

UnmarshalMethod · 0.65

Tested by

no test coverage detected