in internal/encoding/decode.go [445:480]
func readBinary(r *buffer.Buffer) ([]byte, error) {
type_, err := readType(r)
if err != nil {
return nil, err
}
var length int64
switch type_ {
case TypeCodeVbin8:
n, err := r.ReadByte()
if err != nil {
return nil, err
}
length = int64(n)
case TypeCodeVbin32:
buf, ok := r.Next(4)
if !ok {
return nil, fmt.Errorf("invalid length for type %#02x", type_)
}
length = int64(binary.BigEndian.Uint32(buf))
default:
return nil, fmt.Errorf("type code %#02x is not a recognized binary type", type_)
}
if length == 0 {
// An empty value and a nil value are distinct,
// ensure that the returned value is not nil in this case.
return make([]byte, 0), nil
}
buf, ok := r.Next(length)
if !ok {
return nil, errors.New("invalid length")
}
return append([]byte(nil), buf...), nil
}