MCPcopy
hub / github.com/protocolbuffers/protobuf-go / unmarshalMap

Method unmarshalMap

encoding/prototext/decode.go:439–488  ·  view source on GitHub ↗

unmarshalMap unmarshals into given protoreflect.Map. A map value is a textproto message containing {key: , value: }.

(fd protoreflect.FieldDescriptor, mmap protoreflect.Map)

Source from the content-addressed store, hash-verified

437// unmarshalMap unmarshals into given protoreflect.Map. A map value is a
438// textproto message containing {key: <kvalue>, value: <mvalue>}.
439func (d decoder) unmarshalMap(fd protoreflect.FieldDescriptor, mmap protoreflect.Map) error {
440 // Determine ahead whether map entry is a scalar type or a message type in
441 // order to call the appropriate unmarshalMapValue func inside
442 // unmarshalMapEntry.
443 var unmarshalMapValue func() (protoreflect.Value, error)
444 switch fd.MapValue().Kind() {
445 case protoreflect.MessageKind, protoreflect.GroupKind:
446 unmarshalMapValue = func() (protoreflect.Value, error) {
447 pval := mmap.NewValue()
448 if err := d.unmarshalMessage(pval.Message(), true); err != nil {
449 return protoreflect.Value{}, err
450 }
451 return pval, nil
452 }
453 default:
454 unmarshalMapValue = func() (protoreflect.Value, error) {
455 return d.unmarshalScalar(fd.MapValue())
456 }
457 }
458
459 tok, err := d.Read()
460 if err != nil {
461 return err
462 }
463 switch tok.Kind() {
464 case text.MessageOpen:
465 return d.unmarshalMapEntry(fd, mmap, unmarshalMapValue)
466
467 case text.ListOpen:
468 for {
469 tok, err := d.Read()
470 if err != nil {
471 return err
472 }
473 switch tok.Kind() {
474 case text.ListClose:
475 return nil
476 case text.MessageOpen:
477 if err := d.unmarshalMapEntry(fd, mmap, unmarshalMapValue); err != nil {
478 return err
479 }
480 default:
481 return d.unexpectedTokenError(tok)
482 }
483 }
484
485 default:
486 return d.unexpectedTokenError(tok)
487 }
488}
489
490// unmarshalMap unmarshals into given protoreflect.Map. A map value is a
491// textproto message containing {key: <kvalue>, value: <mvalue>}.

Callers 1

unmarshalMessageMethod · 0.95

Calls 9

unmarshalMessageMethod · 0.95
MessageMethod · 0.95
unmarshalScalarMethod · 0.95
unmarshalMapEntryMethod · 0.95
unexpectedTokenErrorMethod · 0.95
KindMethod · 0.65
MapValueMethod · 0.65
NewValueMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected