decode function
int
decode
(Uint8List buffer, [ int offset ])
Implementation
int decode (Uint8List buffer, [int offset]) {
offset = offset ?? 0;
ByteData bytes = buffer.buffer.asByteData();
final first = bytes.getUint8(offset);
// 8 bit
if (first < 0xfd) {
return first;
// 16 bit
} else if (first == 0xfd) {
return bytes.getUint16(offset + 1, Endian.little);
// 32 bit
} else if (first == 0xfe) {
return bytes.getUint32(offset + 1, Endian.little);
// 64 bit
} else {
var lo = bytes.getUint32(offset + 1, Endian.little);
var hi = bytes.getUint32(offset + 5, Endian.little);
var number = hi * 0x0100000000 + lo;
if (!isUint(number, 53)) throw ArgumentError("Expected UInt53");
return number;
}
}