Skip to content

Fix: Handle UInt64 and Int64 values for web compatibility in deserializer #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions lib/src/deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,32 @@ class Deserializer {
return res;
}

int _readUInt64() {
final res = _data.getUint64(_offset);
_offset += 8;
return res;
}
int _read64({bool signed = false}) {
const isWeb = bool.fromEnvironment('dart.library.html');
var value;

if (isWeb) {
final hi = signed ? _data.getInt32(_offset) : _data.getUint32(_offset);
_offset += 4;
final lo = _data.getUint32(_offset);
_offset += 4;

value = (hi * 0x100000000) + lo;
if (value > 9007199254740991 || (signed && value < -9007199254740991)) {
throw FormatError("64-bit value exceeds JavaScript's safe integer range");
}
} else {
value = signed ? _data.getInt64(_offset) : _data.getUint64(_offset);
_offset += 8;
}

int _readInt64() {
final res = _data.getInt64(_offset);
_offset += 8;
return res;
return value;
}

int _readUInt64() => _read64();

int _readInt64() => _read64(signed: true);

double _readFloat() {
final res = _data.getFloat32(_offset);
_offset += 4;
Expand Down