Skip to content
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

long (Java) --> int64 (protoc) --> Dart: possible to use int instead of Int64? #830

Open
buchen opened this issue May 11, 2023 · 1 comment

Comments

@buchen
Copy link

buchen commented May 11, 2023

So far, I have been using protobuf to read and write data from a Java program.
The buffer includes thousands of "long" which are specified as "int64" in the protobuf file.

Now I want to read the same protobuf encoded file in my native dart (flutter) program.
The generated code uses Int64 from the fixnum package.

Looking at long in Java (with minimum -2^63 to maximum 2^63-1) it has the same precision as Dart's native int.
I am trying to understand why it is using Int64 (javascript?) and if there is a way to have the generated classes use int.

Thanks for your time. Any hint would be helpful.

@sigurdm
Copy link
Collaborator

sigurdm commented May 12, 2023

The reason for using package:fixnum is that dart on web (when compiled to javascript) uses javascript numbers which are double-precision floating points. These can only represent up to 53 bits of integer values without loss of precision.

Package:fixnum could on have an implementation of Int64 on native that used a single int as underlying representation - and switching with conditional imports. (dart-lang/core#172). With "inline classes" (upcoming language feature) this should even be very efficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants