DecodeTag decodes a field tag and Protobuf wire type from the stream and returns the values. io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
()
| 128 | // |
| 129 | // io.ErrUnexpectedEOF is returned if the operation would read past the end of the data. |
| 130 | func (d *Decoder) DecodeTag() (tag int, wireType WireType, err error) { |
| 131 | if d.offset >= len(d.p) { |
| 132 | return 0, WireTypeVarint, io.ErrUnexpectedEOF |
| 133 | } |
| 134 | v, n, err := DecodeVarint(d.p[d.offset:]) |
| 135 | if err != nil { |
| 136 | return 0, -1, fmt.Errorf("invalid data at byte %d: %w", d.offset, err) |
| 137 | } |
| 138 | if n < 1 || v < 1 || v > MaxTagValue { |
| 139 | return 0, -1, fmt.Errorf("invalid tag value (%d) at byte %d: %w", v, d.offset, ErrInvalidFieldTag) |
| 140 | } |
| 141 | d.offset += n |
| 142 | return int(v >> 3), WireType(v & 0x7), nil |
| 143 | } |
| 144 | |
| 145 | // DecodeBool decodes a boolean value from the stream and returns the value. |
| 146 | // |