unpackString method
Unpack value if it exist. Otherwise returns null
.
Empty Throws FormatException if value is not a String.
Implementation
String? unpackString() {
final b = _d.getUint8(_offset);
if (b == 0xc0) {
_offset += 1;
return null;
}
int len;
/// fixstr 101XXXXX stores a byte array whose len is upto 31 bytes:
if (b & 0xE0 == 0xA0) {
len = b & 0x1F;
_offset += 1;
} else if (b == 0xd9) {
len = _d.getUint8(++_offset);
_offset += 1;
} else if (b == 0xda) {
len = _d.getUint16(++_offset);
_offset += 2;
} else if (b == 0xdb) {
len = _d.getUint32(++_offset);
_offset += 4;
} else {
throw _formatException('String', b);
}
final data =
Uint8List.view(_list.buffer, _list.offsetInBytes + _offset, len);
_offset += len;
return _strCodec.decode(data);
}