UnmarshalText parses a proto text formatted string into m.
(s string, m Message)
| 41 | |
| 42 | // UnmarshalText parses a proto text formatted string into m. |
| 43 | func 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 | |
| 67 | type textParser struct { |
| 68 | s string // remaining input |
searching dependent graphs…