MCPcopy
hub / github.com/gogo/protobuf / readStruct

Method readStruct

proto/text_parser.go:441–696  ·  view source on GitHub ↗
(sv reflect.Value, terminator string)

Source from the content-addressed store, hash-verified

439}
440
441func (p *textParser) readStruct(sv reflect.Value, terminator string) error {
442 st := sv.Type()
443 sprops := GetProperties(st)
444 reqCount := sprops.reqCount
445 var reqFieldErr error
446 fieldSet := make(map[string]bool)
447 // A struct is a sequence of "name: value", terminated by one of
448 // '>' or '}', or the end of the input. A name may also be
449 // "[extension]" or "[type/url]".
450 //
451 // The whole struct can also be an expanded Any message, like:
452 // [type/url] < ... struct contents ... >
453 for {
454 tok := p.next()
455 if tok.err != nil {
456 return tok.err
457 }
458 if tok.value == terminator {
459 break
460 }
461 if tok.value == "[" {
462 // Looks like an extension or an Any.
463 //
464 // TODO: Check whether we need to handle
465 // namespace rooted names (e.g. ".something.Foo").
466 extName, err := p.consumeExtName()
467 if err != nil {
468 return err
469 }
470
471 if s := strings.LastIndex(extName, "/"); s >= 0 {
472 // If it contains a slash, it's an Any type URL.
473 messageName := extName[s+1:]
474 mt := MessageType(messageName)
475 if mt == nil {
476 return p.errorf("unrecognized message %q in google.protobuf.Any", messageName)
477 }
478 tok = p.next()
479 if tok.err != nil {
480 return tok.err
481 }
482 // consume an optional colon
483 if tok.value == ":" {
484 tok = p.next()
485 if tok.err != nil {
486 return tok.err
487 }
488 }
489 var terminator string
490 switch tok.value {
491 case "<":
492 terminator = ">"
493 case "{":
494 terminator = "}"
495 default:
496 return p.errorf("expected '{' or '<', found %q", tok.value)
497 }
498 v := reflect.New(mt.Elem())

Callers 2

readAnyMethod · 0.95
UnmarshalTextFunction · 0.80

Calls 15

nextMethod · 0.95
consumeExtNameMethod · 0.95
errorfMethod · 0.95
ParseMethod · 0.95
checkForColonMethod · 0.95
repeatedMethod · 0.95
readAnyMethod · 0.95
consumeTokenMethod · 0.95
backMethod · 0.95
GetPropertiesFunction · 0.85

Tested by

no test coverage detected