Skip to content

feat(generator/dart): rewrite json encoding+decoding to capture edge cases#1807

Merged
devoncarew merged 3 commits intogoogleapis:mainfrom
devoncarew:rewrite_encoding
Apr 15, 2025
Merged

feat(generator/dart): rewrite json encoding+decoding to capture edge cases#1807
devoncarew merged 3 commits intogoogleapis:mainfrom
devoncarew:rewrite_encoding

Conversation

@devoncarew
Copy link
Copy Markdown
Contributor

Rewrite the JSON encoding+decoding to capture edge cases:

  • rewrite json encoding + decoding to simplify the generation logic a bit and to address several edges cases in encoding (64 bit ints, maps of enums, maps of bytes, ...)
  • the encoding/decoding of each type is generally handled by a specific dart function; the generator's job is mostly to select the right function
  • encoding logic is now in a new file, google_cloud_gax/lib/src/encoding.dart
  • existing round trip tests (mostly using types from the rpc package) continue to work
  • some dart unit tests added to test the new corner cases
  • fix Implement the mapping of uint64 and int64 in JSON #1568
  • fix handle encoding of a map of bytes #1658
  • libraries regenerated in a 2nd commit for easier review

Comment on lines +31 to +34
/// Decode a `double` value.
double? decodeDouble(Object? value) {
return (value as num?)?.toDouble();
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProtoJSON uses strings to represent NaN, Infinity and -Infinity. Consider opening a bug to handle these cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.09%. Comparing base (a7c42d2) to head (44f92a5).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1807   +/-   ##
=======================================
  Coverage   96.09%   96.09%           
=======================================
  Files          54       54           
  Lines        1998     1998           
=======================================
  Hits         1920     1920           
  Misses         78       78           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor Author

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! updated

Comment on lines +31 to +34
/// Decode a `double` value.
double? decodeDouble(Object? value) {
return (value as num?)?.toDouble();
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@devoncarew devoncarew merged commit 490c23c into googleapis:main Apr 15, 2025
21 checks passed
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

Successfully merging this pull request may close these issues.

handle encoding of a map of bytes Implement the mapping of uint64 and int64 in JSON

2 participants