func (cb *Buffer) ReadGroup(alloc bool) ([]byte, error) {
	var groupEnd, dataEnd int
	groupEnd, dataEnd, err := cb.findGroupEnd()
	if err != nil {
		return nil, err
	}
	var results []byte
	if !alloc {
		results = cb.buf[cb.index:dataEnd]
	} else {
		results = make([]byte, dataEnd-cb.index)
		copy(results, cb.buf[cb.index:])
	}
	cb.index = groupEnd
	return results, nil
}
ReadGroup reads the input until a "group end" tag is found
and returns the data up to that point. Subsequent reads from
the buffer will read data after the group end tag. If alloc
is true, the data is copied to a new slice before being returned.
Otherwise, the returned slice is a view into the buffer's
underlying byte slice.

This function correctly handles nested groups: if a "group start"
tag is found, then that group's end tag will be included in the
returned data.
package codec
import (
	"errors"
	"fmt"
	"io"
)
var ErrOverflow = errors.New("proto: integer overflow")
var ErrBadWireType = errors.New("proto: bad wiretype")
var varintTypes = map[FieldType]bool{}
var fixed32Types = map[FieldType]bool{}
var fixed64Types = map[FieldType]bool{}
func init() {
	varintTypes[FieldType_BOOL] = true
	varintTypes[FieldType_INT32] = true
	varintTypes[FieldType_INT64] = true
	varintTypes[FieldType_UINT32] = true
	varintTypes[FieldType_UINT64] = true
	varintTypes[FieldType_SINT32] = true
	varintTypes[FieldType_SINT64] = true
	varintTypes[FieldType_ENUM] = true
	fixed32Types[FieldType_FIXED32] = true
	fixed32Types[FieldType_SFIXED32] = true
	fixed32Types[FieldType_FLOAT] = true
	fixed64Types[FieldType_FIXED64] = true
	fixed64Types[FieldType_SFIXED64] = true
	fixed64Types[FieldType_DOUBLE] = true
}
func (cb *Buffer) DecodeVarint() (uint64, error) {
	if cb.len == 0 {
		return 0, io.ErrUnexpectedEOF
	}
	const (
		step = 7
		bit  = 1 << 7
		mask = bit - 1
	)
	if cb.len >= 10 {
		b := cb.buf[cb.index]
		if b < bit {
			cb.index++
			return uint64(b), nil
		}
		x := uint64(b & mask)
		var s uint = step
		b = cb.buf[cb.index+1]
		if b < bit {
			cb.index += 2
			return x | uint64(b)<<s, nil
		}
		x |= uint64(b&mask) << s
		s += step
		b = cb.buf[cb.index+2]
		if b < bit {
			cb.index += 3
			return x | uint64(b)<<s, nil
		}
		x |= uint64(b&mask) << s
		s += step
		b = cb.buf[cb.index+3]
		if b < bit {
			cb.index += 4
			return x | uint64(b)<<s, nil
		}
		x |= uint64(b&mask) << s
		s += step
		b = cb.buf[cb.index+4]
		if b < bit {
			cb.index += 5
			return x | uint64(b)<<s, nil
		}
		x |= uint64(b&mask) << s
		s += step
		b = cb.buf[cb.index+5]
		if b < bit {
			cb.index += 6
			return x | uint64(b)<<s, nil
		}
		x |= uint64(b&mask) << s
		s += step
		b = cb.buf[cb.index+6]
		if b < bit {
			cb.index += 7
			return x | uint64(b)<<s, nil
		}
		x |= uint64(b&mask) << s
		s += step
		b = cb.buf[cb.index+7]
		if b < bit {
			cb.index += 8
			return x | uint64(b)<<s, nil
		}
		x |= uint64(b&mask) << s
		s += step
		b = cb.buf[cb.index+8]
		if b < bit {
			cb.index += 9
			return x | uint64(b)<<s, nil
		}
		x |= uint64(b&mask) << s
		s += step
		b = cb.buf[cb.index+9]
		if b < bit {
			if b > 1 {
				return 0, ErrOverflow
			}
			cb.index += 10
			return x | uint64(b)<<s, nil
		} else if cb.len == 10 {
			return 0, io.ErrUnexpectedEOF
		}
		for _, b := range cb.buf[cb.index+10:] {
			if b < bit {
				return 0, ErrOverflow
			}
		}
		return 0, io.ErrUnexpectedEOF
	}
	b := cb.buf[cb.index]
	if b < bit {
		cb.index++
		return uint64(b), nil
	} else if cb.len == 1 {
		return 0, io.ErrUnexpectedEOF
	}
	x := uint64(b & mask)
	var s uint = step
	b = cb.buf[cb.index+1]
	if b < bit {
		cb.index += 2
		return x | uint64(b)<<s, nil
	} else if cb.len == 2 {
		return 0, io.ErrUnexpectedEOF
	}
	x |= uint64(b&mask) << s
	s += step
	b = cb.buf[cb.index+2]
	if b < bit {
		cb.index += 3
		return x | uint64(b)<<s, nil
	} else if cb.len == 3 {
		return 0, io.ErrUnexpectedEOF
	}
	x |= uint64(b&mask) << s
	s += step
	b = cb.buf[cb.index+3]
	if b < bit {
		cb.index += 4
		return x | uint64(b)<<s, nil
	} else if cb.len == 4 {
		return 0, io.ErrUnexpectedEOF
	}
	x |= uint64(b&mask) << s
	s += step
	b = cb.buf[cb.index+4]
	if b < bit {
		cb.index += 5
		return x | uint64(b)<<s, nil
	} else if cb.len == 5 {
		return 0, io.ErrUnexpectedEOF
	}
	x |= uint64(b&mask) << s
	s += step
	b = cb.buf[cb.index+5]
	if b < bit {
		cb.index += 6
		return x | uint64(b)<<s, nil
	} else if cb.len == 6 {
		return 0, io.ErrUnexpectedEOF
	}
	x |= uint64(b&mask) << s
	s += step
	b = cb.buf[cb.index+6]
	if b < bit {
		cb.index += 7
		return x | uint64(b)<<s, nil
	} else if cb.len == 7 {
		return 0, io.ErrUnexpectedEOF
	}
	x |= uint64(b&mask) << s
	s += step
	b = cb.buf[cb.index+7]
	if b < bit {
		cb.index += 8
		return x | uint64(b)<<s, nil
	} else if cb.len == 8 {
		return 0, io.ErrUnexpectedEOF
	}
	x |= uint64(b&mask) << s
	s += step
	b = cb.buf[cb.index+8]
	if b < bit {
		cb.index += 9
		return x | uint64(b)<<s, nil
	} else if cb.len == 9 {
		return 0, io.ErrUnexpectedEOF
	}
	x |= uint64(b&mask) << s
	s += step
	b = cb.buf[cb.index+9]
	if b < bit {
		if b > 1 {
			return 0, ErrOverflow
		}
		cb.index += 10
		return x | uint64(b)<<s, nil
	} else if cb.len == 10 {
		return 0, io.ErrUnexpectedEOF
	}
	for _, b := range cb.buf[cb.index+10:] {
		if b < bit {
			return 0, ErrOverflow
		}
	}
	return 0, io.ErrUnexpectedEOF
}
func (cb *Buffer) DecodeFixed64() (x uint64, err error) {
	i := cb.index + 8
	if i < 0 || i > cb.len {
		err = io.ErrUnexpectedEOF
		return
	}
	cb.index = i
	x = uint64(cb.buf[i-8])
	x |= uint64(cb.buf[i-7]) << 8
	x |= uint64(cb.buf[i-6]) << 16
	x |= uint64(cb.buf[i-5]) << 24
	x |= uint64(cb.buf[i-4]) << 32
	x |= uint64(cb.buf[i-3]) << 40
	x |= uint64(cb.buf[i-2]) << 48
	x |= uint64(cb.buf[i-1]) << 56
	return
}
func (cb *Buffer) DecodeFixed32() (x uint64, err error) {
	i := cb.index + 4
	if i < 0 || i > cb.len {
		err = io.ErrUnexpectedEOF
		return
	}
	cb.index = i
	x = uint64(cb.buf[i-4])
	x |= uint64(cb.buf[i-3]) << 8
	x |= uint64(cb.buf[i-2]) << 16
	x |= uint64(cb.buf[i-1]) << 24
	return
}
func DecodeZigZag32(v uint64) int32 {
	return int32((uint32(v) >> 1) ^ uint32((int32(v&1)<<31)>>31))
}
func DecodeZigZag64(v uint64) int64 {
	return int64((v >> 1) ^ uint64((int64(v&1)<<63)>>63))
}
func (cb *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) {
	n, err := cb.DecodeVarint()
	if err != nil {
		return nil, err
	}
	nb := int(n)
	if nb < 0 {
		return nil, fmt.Errorf("proto: bad byte length %d", nb)
	}
	end := cb.index + nb
	if end < cb.index || end > cb.len {
		return nil, io.ErrUnexpectedEOF
	}
	if !alloc {
		buf = cb.buf[cb.index:end]
		cb.index = end
		return
	}
	buf = make([]byte, nb)
	copy(buf, cb.buf[cb.index:])
	cb.index = end
	return
}