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

Method unmarshalSingularValue

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

Source from the content-addressed store, hash-verified

462}
463
464func (u *Unmarshaler) unmarshalSingularValue(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) {
465 switch fd.Kind() {
466 case protoreflect.BoolKind:
467 return unmarshalValue(in, new(bool))
468 case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
469 return unmarshalValue(trimQuote(in), new(int32))
470 case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
471 return unmarshalValue(trimQuote(in), new(int64))
472 case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
473 return unmarshalValue(trimQuote(in), new(uint32))
474 case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
475 return unmarshalValue(trimQuote(in), new(uint64))
476 case protoreflect.FloatKind:
477 if f, ok := nonFinite[string(in)]; ok {
478 return protoreflect.ValueOfFloat32(float32(f)), nil
479 }
480 return unmarshalValue(trimQuote(in), new(float32))
481 case protoreflect.DoubleKind:
482 if f, ok := nonFinite[string(in)]; ok {
483 return protoreflect.ValueOfFloat64(float64(f)), nil
484 }
485 return unmarshalValue(trimQuote(in), new(float64))
486 case protoreflect.StringKind:
487 return unmarshalValue(in, new(string))
488 case protoreflect.BytesKind:
489 return unmarshalValue(in, new([]byte))
490 case protoreflect.EnumKind:
491 if hasPrefixAndSuffix('"', in, '"') {
492 vd := fd.Enum().Values().ByName(protoreflect.Name(trimQuote(in)))
493 if vd == nil {
494 return v, fmt.Errorf("unknown value %q for enum %s", in, fd.Enum().FullName())
495 }
496 return protoreflect.ValueOfEnum(vd.Number()), nil
497 }
498 return unmarshalValue(in, new(protoreflect.EnumNumber))
499 case protoreflect.MessageKind, protoreflect.GroupKind:
500 err := u.unmarshalMessage(v.Message(), in)
501 return v, err
502 default:
503 panic(fmt.Sprintf("invalid kind %v", fd.Kind()))
504 }
505}
506
507func unmarshalValue(in []byte, v interface{}) (protoreflect.Value, error) {
508 err := json.Unmarshal(in, v)

Callers 1

unmarshalValueMethod · 0.95

Implementers 3

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

Calls 6

unmarshalMessageMethod · 0.95
unmarshalValueFunction · 0.85
trimQuoteFunction · 0.85
hasPrefixAndSuffixFunction · 0.85
NameMethod · 0.65
EnumMethod · 0.45

Tested by

no test coverage detected