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

Handling of large integers in bytes fields is inconsistent between serializers #731

Open
osa1 opened this issue Aug 11, 2022 · 0 comments
Open

Comments

@osa1
Copy link
Member

osa1 commented Aug 11, 2022

Originally reported in #219 (comment)

If I have a bytes field and set the value something like <int>[999999] (i.e. an integer list with integers larger than max value of a byte), binary serializer silently truncates the integer value, but JSON map and proto3 JSON serializers throw an exception.

Exception thrown by JSON map encoder:

Invalid argument (Not a byte value at index 0: 0x1869f): Instance(length:1) of '_GrowableList'
#0      _Base64Encoder.encodeChunk (dart:convert/base64.dart:374:5)
#1      _Base64Encoder.encode (dart:convert/base64.dart:328:9)
#2      Base64Encoder.convert (dart:convert/base64.dart:243:26)
#3      Codec.encode (dart:convert/codec.dart:21:32)
#4      base64Encode (dart:convert/base64.dart:41:48)
#5      _writeToJsonMap.convertToMap (package:protobuf/src/protobuf/json.dart:40:16)
#6      _writeToJsonMap (package:protobuf/src/protobuf/json.dart:79:33)
#7      GeneratedMessage.writeToJsonMap (package:protobuf/src/protobuf/generated_message.dart:203:44)
#8      GeneratedMessage.writeToJson (package:protobuf/src/protobuf/generated_message.dart:218:38)

Exception thrown by proto3 JSON encoder:

Unhandled exception:
Invalid argument (Not a byte value at index 0: 0x1869f): Instance(length:1) of '_GrowableList'
#0      _Base64Encoder.encodeChunk (dart:convert/base64.dart:374:5)
#1      _Base64Encoder.encode (dart:convert/base64.dart:328:9)
#2      Base64Encoder.convert (dart:convert/base64.dart:243:26)
#3      Codec.encode (dart:convert/codec.dart:21:32)
#4      base64Encode (dart:convert/base64.dart:41:48)
#5      _writeToProto3Json.valueToProto3Json (package:protobuf/src/protobuf/proto3_json.dart:77:18)
#6      _writeToProto3Json (package:protobuf/src/protobuf/proto3_json.dart:108:19)
#7      GeneratedMessage.toProto3Json (package:protobuf/src/protobuf/generated_message.dart:235:7)
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

1 participant