toInt method Null safety
- Uint8List compactSize
Converts a compact size Uint8List
into int
.
Implementation
static int toInt(Uint8List compactSize) {
int size = compactSize[0];
Uint8List bytes;
if (size <= 252) {
return size;
} else if (size == 253) {
bytes = compactSize.sublist(1, 3);
} else if (size == 254) {
bytes = compactSize.sublist(1, 5);
} else {
bytes = compactSize.sublist(1, 9);
}
int value = 0;
for (int i = bytes.length - 1; i >= 0; i--) {
value = value << 8;
value = value | bytes[i];
}
return value;
}