fix Rfp_wrapped_option (num optional > max_bits)#263
Merged
c-cube merged 4 commits intomransan:masterfrom Dec 31, 2025
Merged
Conversation
When the number of optional fields exceeds the size of a bitfield,
presence is encoded using the option type (`Rfp_wrapped_option`). The
generated OCaml code does not compile. An example is given below; see
also `src/tests/integration-tests/test28.proto`.
```
syntax = "proto2";
message Person {
optional bool ofield00 = 100 [default=true];
optional bool ofield01 = 101 [default=true];
...
optional bool ofield61 = 161 [default=true];
optional bool ofield62 = 162 [default=true];
}
```
This commit fixes the problems.
Contributor
Author
|
Thank you for ocaml-protoc and all the maintenance work. It is a very useful project. I found a bug for protocols with many optional fields. This pull request is my attempted fix, but I'm new to the project and possibly made mistakes. I know that a special case is needed for |
Collaborator
|
Thank you, I failed to check this particular corner case! |
Contributor
Author
|
Thanks @c-cube . It came up for the Google OR-Tools cp_model.proto definition, while I was working on https://github.com/INRIA/ocaml-ortools. |
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.
When the number of optional fields exceeds the size of a bitfield, presence is encoded using the option type (
Rfp_wrapped_option). The generated OCaml code does not compile. An example is given below; see alsosrc/tests/integration-tests/test28.proto.This commit fixes the problems.