Fix non-proto3 JSON format double decoding (#1043)

When the field type is a proto `float` or `double` we always use a Dart
`double` for the value. Trying to set the field an `int` causes an assertion
failure in `FieldSet`.

This code is also a bit inconsistent in itself: when the jspblite2 value is a
string it decodes as `double`, but when it's a number it tries to convert to an
`int`. So if the value is a string `"1"` it stores as `double` but if it's the
number `1` it tries to convert to double.

This isn't an issue with dart2js as with dart2js `int` and `double` are the
same thing, but it causes assertion failures when this library is used with
dart2wasm which distinguishes `int`s and `double`s.

Fix by always storing proto `float`s and `double`s as Dart `double`s.

Note: this code is currently not used in dart2wasm, instead dart2wasm uses the
VM's library. However if I start using this library instead (for benchmarking,
to potentially switch to this library) then it breaks. So currently this change
is not a user-visible change because dart2wasm doesn't use this library.

cl/799924250
1 file changed
tree: d67b5df81d2240eadb2f79711936eff3e31e252e
  1. .github/
  2. benchmarks/
  3. protobuf/
  4. protoc_plugin/
  5. tool/
  6. .gitignore
  7. analysis_options.yaml
  8. AUTHORS
  9. LICENSE
  10. pubspec.yaml
  11. README.md
README.md

Protobuf support for Dart

Protocol Buffers (protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.

This repository is home to packages related to protobuf support for Dart.

PackageDescriptionPublished Version
protobufRuntime library for protocol buffers support.pub package
protoc_pluginA protobuf protoc compiler plugin used to generate Dart code.pub package
benchmarksBenchmarks for various protobuf functions.

Publishing automation

For information about our publishing automation and release process, see https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.