in string.go [169:202]
func (d *Decoder) getStringLength(tag byte) (int, error) {
var length int
switch {
case tag >= BC_STRING_DIRECT && tag <= STRING_DIRECT_MAX:
return int(tag - 0x00), nil
case tag >= 0x30 && tag <= 0x33:
b, err := d.ReadByte()
if err != nil {
return -1, perrors.WithStack(err)
}
length = int(tag-0x30)<<8 + int(b)
return length, nil
case tag == BC_STRING_CHUNK || tag == BC_STRING:
b0, err := d.ReadByte()
if err != nil {
return -1, perrors.WithStack(err)
}
b1, err := d.ReadByte()
if err != nil {
return -1, perrors.WithStack(err)
}
length = int(b0)<<8 + int(b1)
return length, nil
default:
return -1, perrors.Errorf("string decode: unknown tag %b", tag)
}
}