Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically created message descriptors do not track field presence for proto3 optional fields #692

Open
ruiQQ opened this issue Dec 13, 2023 · 0 comments

Comments

@ruiQQ
Copy link

ruiQQ commented Dec 13, 2023

Hi,

I am building a dynamic message from a dynamic file descriptor, and I noticed that the dynamic fds seem to ignore proto3 optional settings

Steps to reproduce:

  1. Build FileDescriptorProto using FileDescriptor#new_dynamic_fds
  2. Get MessageDescriptor and create a new instance of the message
  3. Set a proto3 optional field to 0
  4. Serialize message into bytes using MessageDyn.html#write_to_bytes_dyn, observed that 0 is not encoded, field presence is not tracked

In my FileDescriptorProto, I have this MessageDescriptorProto, where I set the proto3_optional to true, and added a synthetic oneof descriptor to make this field explicitly optional

    message_type: {
        name: "Foo",
        field: {
                label: LABEL_OPTIONAL,
                type: TYPE_INT32,
                name: "bar",
                number: 1
                proto3_optional: true,
                oneof_index: 0,
        },
        oneof_decl: {
            name: "bar",
        }
    },

Is there an error in my MessageDescriptor proto set up? How can I make the dynamic message from dynamic fds track field presence?

Thank you!

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

No branches or pull requests

1 participant