fromBytes static method
Parses an 8-byte unsigned integer directly into hi/lo limbs without using
BigInt.
Reads 8 bytes starting at offset from bytes. Accepts any List<int>
(e.g. Uint8List, List<int>, etc.).
Throws ArgumentException if there are fewer than 8 bytes available starting
at offset.
Implementation
static Uint64 fromBytes(
List<int> bytes, {
int offset = 0,
Endian endian = Endian.big,
}) {
if (offset < 0 || bytes.length - offset < 8) {
throw ArgumentException.invalidOperationArguments(
"Uint64.fromBytes",
reason: 'Need at least 8 bytes from offset.',
details: {
"offset": offset.toString(),
"length": bytes.length.toString(),
},
);
}
int hi, lo;
if (endian == Endian.big) {
hi =
(bytes[offset] << 24) |
(bytes[offset + 1] << 16) |
(bytes[offset + 2] << 8) |
bytes[offset + 3];
lo =
(bytes[offset + 4] << 24) |
(bytes[offset + 5] << 16) |
(bytes[offset + 6] << 8) |
bytes[offset + 7];
} else {
lo =
(bytes[offset + 3] << 24) |
(bytes[offset + 2] << 16) |
(bytes[offset + 1] << 8) |
bytes[offset];
hi =
(bytes[offset + 7] << 24) |
(bytes[offset + 6] << 16) |
(bytes[offset + 5] << 8) |
bytes[offset + 4];
}
return Uint64._(hi & _mask32, lo & _mask32);
}