consumeGroup parses b until it finds an end group marker, returning the raw bytes of the message (excluding the end group marker) and the the total length of the message (including the end group marker).
(b []byte)
| 286 | // the raw bytes of the message (excluding the end group marker) and the |
| 287 | // the total length of the message (including the end group marker). |
| 288 | func consumeGroup(b []byte) ([]byte, int, error) { |
| 289 | b0 := b |
| 290 | depth := 1 // assume this follows a start group marker |
| 291 | for { |
| 292 | _, wtyp, tagLen := protowire.ConsumeTag(b) |
| 293 | if tagLen < 0 { |
| 294 | return nil, 0, protowire.ParseError(tagLen) |
| 295 | } |
| 296 | b = b[tagLen:] |
| 297 | |
| 298 | var valLen int |
| 299 | switch wtyp { |
| 300 | case protowire.VarintType: |
| 301 | _, valLen = protowire.ConsumeVarint(b) |
| 302 | case protowire.Fixed32Type: |
| 303 | _, valLen = protowire.ConsumeFixed32(b) |
| 304 | case protowire.Fixed64Type: |
| 305 | _, valLen = protowire.ConsumeFixed64(b) |
| 306 | case protowire.BytesType: |
| 307 | _, valLen = protowire.ConsumeBytes(b) |
| 308 | case protowire.StartGroupType: |
| 309 | depth++ |
| 310 | case protowire.EndGroupType: |
| 311 | depth-- |
| 312 | default: |
| 313 | return nil, 0, errors.New("proto: cannot parse reserved wire type") |
| 314 | } |
| 315 | if valLen < 0 { |
| 316 | return nil, 0, protowire.ParseError(valLen) |
| 317 | } |
| 318 | b = b[valLen:] |
| 319 | |
| 320 | if depth == 0 { |
| 321 | return b0[:len(b0)-len(b)-tagLen], len(b0) - len(b), nil |
| 322 | } |
| 323 | } |
| 324 | } |