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

Function UnmarshalText

proto/text_decode.go:43–65  ·  view source on GitHub ↗

UnmarshalText parses a proto text formatted string into m.

(s string, m Message)

Source from the content-addressed store, hash-verified

41
42// UnmarshalText parses a proto text formatted string into m.
43func UnmarshalText(s string, m Message) error {
44 if u, ok := m.(encoding.TextUnmarshaler); ok {
45 return u.UnmarshalText([]byte(s))
46 }
47
48 m.Reset()
49 mi := MessageV2(m)
50
51 if wrapTextUnmarshalV2 {
52 err := prototext.UnmarshalOptions{
53 AllowPartial: true,
54 }.Unmarshal([]byte(s), mi)
55 if err != nil {
56 return &ParseError{Message: err.Error()}
57 }
58 return checkRequiredNotSet(mi)
59 } else {
60 if err := newTextParser(s).unmarshalMessage(mi.ProtoReflect(), ""); err != nil {
61 return err
62 }
63 return checkRequiredNotSet(mi)
64 }
65}
66
67type textParser struct {
68 s string // remaining input

Callers 12

TestUnmarshalGoldenFunction · 0.92
TestAmbiguousAnyFunction · 0.92
TestStringEscapingFunction · 0.92
TestUnmarshalTextFunction · 0.92
TestRepeatedEnumFunction · 0.92
TestProto3TextParsingFunction · 0.92
TestMapParsingFunction · 0.92
TestOneofParsingFunction · 0.92
json_test.goFile · 0.92

Calls 9

MessageV2Function · 0.85
checkRequiredNotSetFunction · 0.85
newTextParserFunction · 0.85
UnmarshalTextMethod · 0.80
ProtoReflectMethod · 0.80
UnmarshalMethod · 0.65
ResetMethod · 0.45
ErrorMethod · 0.45
unmarshalMessageMethod · 0.45

Tested by 11

TestUnmarshalGoldenFunction · 0.74
TestAmbiguousAnyFunction · 0.74
TestStringEscapingFunction · 0.74
TestUnmarshalTextFunction · 0.74
TestRepeatedEnumFunction · 0.74
TestProto3TextParsingFunction · 0.74
TestMapParsingFunction · 0.74
TestOneofParsingFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…