Populate min_version BrushFamily proto field.#511
Open
copybara-service[bot] wants to merge 1 commit intomainfrom
Open
Populate min_version BrushFamily proto field.#511copybara-service[bot] wants to merge 1 commit intomainfrom
copybara-service[bot] wants to merge 1 commit intomainfrom
Conversation
0a5e876 to
0d1a2eb
Compare
Introduces code to calculate the minimum required version of Ink for a BrushFamily (and each part of a BrushFamily). The code is used during serialization to compute the value to store in the `min_version` field. During deserialization, the `min_version` field is used to determine if a BrushFamily is compatible with the current version of Ink; if it isn't, decoding it is aborted. To ensure the code in the web of `CalculateMinimumRequiredVersion` functions lines up with expectations, protobuf options are used to build consistency check tests. `CalculateMinimumRequiredVersion` serves as the enforcement of the expectations set in the protobuf itself. The tests are: * A fuzz test to generate valid brush families and serialize them. Then, it checks the value in `min_version` against all the options set for the fields, messages, and enum values, to ensure it is equal to the highest value set for the relevant options. This ensures `CalculateMinimumRequiredVersion` is consistent with the protobuf options. * A test to iterate over all the messages, fields, and enum values in `brush_family.proto`, starting at the top-level `BrushFamily` message, and verify that they all have a relevant `field_min_version`, `message_min_version`, or `enum_value_min_version` set, and that this value set is less than or equal to the maximum compatible version (`version::kMax`). * A test to verify that decoding a `proto::Version` out of the acceptable range (higher than `version::kMax`, lower than `version::kMin`, any version with `release < 1`, any stable version with `release != 1`) will fail. * A test to verify that decoding a `proto::Version` with an unrecognized `proto::Version::Cycle` enum value will fail. * A test to verify that decoding a `proto::BrushFamily` with no value set for its `min_version` field will ***not*** fail, to ensure older brushes are still able to be loaded. A more direct implementation, using reflection to examine the descriptors of the protobuf directly during serialization, was considered, but ultimately rejected. It would have required both static and runtime reflection, and increased `libink.so` size by ~2%. PiperOrigin-RevId: 872916698
0d1a2eb to
396c618
Compare
min_version field. During deserialization, the min_version field is used to determine if a BrushFamily is compatible with the current version of Ink; if it isn't, decoding it is aborted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Populate min_version BrushFamily proto field.
Introduces code to calculate the minimum required version of Ink for a BrushFamily (and each part of a BrushFamily). The code is used during serialization to compute the value to store in the
min_versionfield. During deserialization, themin_versionfield is used to determine if a BrushFamily is compatible with the current version of Ink; if it isn't, decoding it is aborted.To ensure the code in the web of
CalculateMinimumRequiredVersionfunctions lines up with expectations, protobuf options are used to build consistency check tests.CalculateMinimumRequiredVersionserves as the enforcement of the expectations set in the protobuf itself. The tests are:min_versionagainst all the options set for the fields, messages, and enum values, to ensure it is equal to the highest value set for the relevant options. This ensuresCalculateMinimumRequiredVersionis consistent with the protobuf options.brush_family.proto, starting at the top-levelBrushFamilymessage, and verify that they all have a relevantfield_min_version,message_min_version, orenum_value_min_versionset, and that this value set is less than or equal to the maximum compatible version (version::kMax).proto::Versionout of the acceptable range (higher thanversion::kMax, lower thanversion::kMin, any version withrelease < 1, any stable version withrelease != 1) will fail.proto::Versionwith an unrecognizedproto::Version::Cycleenum value will fail.proto::BrushFamilywith no value set for itsmin_versionfield will not fail, to ensure older brushes are still able to be loaded.A more direct implementation, using reflection to examine the descriptors of the protobuf directly during serialization, was considered, but ultimately rejected. It would have required both static and runtime reflection, and increased
libink.sosize by ~2%.