unmarshalMap unmarshals into given protoreflect.Map. A map value is a textproto message containing {key: , value: }.
(fd protoreflect.FieldDescriptor, mmap protoreflect.Map)
| 437 | // unmarshalMap unmarshals into given protoreflect.Map. A map value is a |
| 438 | // textproto message containing {key: <kvalue>, value: <mvalue>}. |
| 439 | func (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>}. |
no test coverage detected