in internal/encoding/types.go [1316:1372]
func (a *arrayBinary) Unmarshal(r *buffer.Buffer) error {
length, err := readArrayHeader(r)
if err != nil {
return err
}
const typeSize = 2 // assume all binary is at least 2 bytes
if length*typeSize > int64(r.Len()) {
return fmt.Errorf("invalid length %d", length)
}
aa := (*a)[:0]
if int64(cap(aa)) < length {
aa = make([][]byte, length)
} else {
aa = aa[:length]
}
type_, err := readType(r)
if err != nil {
return err
}
switch type_ {
case TypeCodeVbin8:
for i := range aa {
size, err := r.ReadByte()
if err != nil {
return err
}
buf, ok := r.Next(int64(size))
if !ok {
return fmt.Errorf("invalid length %d", length)
}
aa[i] = append([]byte(nil), buf...)
}
case TypeCodeVbin32:
for i := range aa {
buf, ok := r.Next(4)
if !ok {
return errors.New("invalid length")
}
size := binary.BigEndian.Uint32(buf)
buf, ok = r.Next(int64(size))
if !ok {
return errors.New("invalid length")
}
aa[i] = append([]byte(nil), buf...)
}
default:
return fmt.Errorf("invalid type for [][]byte %02x", type_)
}
*a = aa
return nil
}