How to know whether the currently processed file is proto2 or proto3 in protobuf_codegen::CustomizeCallback?

I need to add some annotations which are serde on fields.

the value would be wrapped by Option if it is in proto2. so diff from proto3

// proto2
foo: ::std::option::Option<u32>

// proto3
foo: u32

so params in the handler fn should be determined by syntax proto 2 or 3?

fn with_fn(f: &Option<u32>, s: S) 

fn with_fn(f: u32, s: S) 

How to know whether the currently processed file is proto2 or proto3 in CustomizeCallback?

I found out.

  fn field(&self, field: &FieldDescriptor) -> Customize {
        let msg = field.containing_message();
        let syntax = msg.file_descriptor().proto().syntax();

        println!("syntax is {}", syntax);
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.