flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Attribute deprecated_readonly

Open Zguy opened this issue 1 year ago • 4 comments

Adds support for a deprecated_readonly attribute.

While deprecated removes the field entirely from generated code, both getters and setters, deprecated_readonly only removes the setters and keeps the getters.

It's useful for backwards compatibility in some cases. A program might read a buffer written before the deprecation, read the deprecated field if it has a value, do some applicable conversion, and write to a non-deprecated field.

Fixes https://github.com/google/flatbuffers/issues/7940

Some things to look out for

  • I have not fully tested the code generation of all languages. I have tested C++ and C#, the rest I've only visually inspected the generated code of. There might be edge cases I've missed, especially in languages I'm not familiar with.
  • I took the liberty of adding the deprecated_readonly attribute to the color field in the monster.fbs sample. Let me know if I should revert this.
  • I added deprecated_readonly to the middle of reflection.fbs next to deprecated. I'm not sure if this file needs to keep backwards conformity. If it does, let me know, and I'll move it to the end.
  • I wanted to have the C# json serializer support honor the deprecated_readonly attribute. There was no easy way to do this and the solution I came up with I find a bit invasive. I put it in a separate commit for easy removal, if it comes to that.

Zguy avatar Dec 20 '23 22:12 Zguy

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Dec 20 '23 22:12 google-cla[bot]

@dbaileychess Not sure what the proper etiquette is here, so apologies if tagging you like this is out of line, but I'd love to get this PR reviewed.

Zguy avatar Mar 26 '24 17:03 Zguy