google/protobuf.dart

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

buchen opened this issue · 1 comments

buchen commented

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.

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/fixnum#107). With "inline classes" (upcoming language feature) this should even be very efficient.