(v protoreflect.Value, fd protoreflect.FieldDescriptor)
| 256 | } |
| 257 | |
| 258 | func (p *textParser) unmarshalValue(v protoreflect.Value, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) { |
| 259 | tok := p.next() |
| 260 | if tok.err != nil { |
| 261 | return v, tok.err |
| 262 | } |
| 263 | if tok.value == "" { |
| 264 | return v, p.errorf("unexpected EOF") |
| 265 | } |
| 266 | |
| 267 | switch { |
| 268 | case fd.IsList(): |
| 269 | lv := v.List() |
| 270 | var err error |
| 271 | if tok.value == "[" { |
| 272 | // Repeated field with list notation, like [1,2,3]. |
| 273 | for { |
| 274 | vv := lv.NewElement() |
| 275 | vv, err = p.unmarshalSingularValue(vv, fd) |
| 276 | if err != nil { |
| 277 | return v, err |
| 278 | } |
| 279 | lv.Append(vv) |
| 280 | |
| 281 | tok := p.next() |
| 282 | if tok.err != nil { |
| 283 | return v, tok.err |
| 284 | } |
| 285 | if tok.value == "]" { |
| 286 | break |
| 287 | } |
| 288 | if tok.value != "," { |
| 289 | return v, p.errorf("Expected ']' or ',' found %q", tok.value) |
| 290 | } |
| 291 | } |
| 292 | return v, nil |
| 293 | } |
| 294 | |
| 295 | // One value of the repeated field. |
| 296 | p.back() |
| 297 | vv := lv.NewElement() |
| 298 | vv, err = p.unmarshalSingularValue(vv, fd) |
| 299 | if err != nil { |
| 300 | return v, err |
| 301 | } |
| 302 | lv.Append(vv) |
| 303 | return v, nil |
| 304 | case fd.IsMap(): |
| 305 | // The map entry should be this sequence of tokens: |
| 306 | // < key : KEY value : VALUE > |
| 307 | // However, implementations may omit key or value, and technically |
| 308 | // we should support them in any order. |
| 309 | var terminator string |
| 310 | switch tok.value { |
| 311 | case "<": |
| 312 | terminator = ">" |
| 313 | case "{": |
| 314 | terminator = "}" |
| 315 | default: |
no test coverage detected