ahamez / protox

A fast, easy to use and 100% conformant Elixir library for Google Protocol Buffers (aka protobuf)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Supporting FileOptions

akash-akya opened this issue ยท comments

Hi, thank you for the protox.

Just wanted to know if there is any chance of adding support for FileOptions? I see a commit to remove FileOptions long time back so wanted to know the rationale

Thank you

Hi!
I removed it because it seemed to me that Elixir wasn't concerned by FileOptions. But if you think it can be useful for you, sure no problem, I can reinstate it if necessary ๐Ÿ˜‰.

Yes please!
In our case we set some metadata about the proto (such as primary kafka topic associated with the proto) in .proto file. And we want to be able to read those dynamically

Can you try the branch file_option? You should be able to call on each message a function file_options/0 that returns a FileOptions structure.
You can see an example here.

Tell me if it works as expected ๐Ÿ˜‰.

Thanks!
I'll test it out tomorrow and let you know ๐Ÿ‘๐Ÿผ

@ahamez I'm seeing file_options function which contains the file-options. But it appears it is not getting set correctly when multiple files are involved.

Example:
test/samples/foo.proto

syntax = "proto3";

option java_package = "com.foo";

message Foo {
  string x = 1;
}

test/samples/bar.proto

syntax = "proto3";

option java_package = "com.bar";

message Bar {
  string y = 1;
}

Generating modules via

mix protox.generate --output-path=./ --multiple-files test/samples/foo.proto test/samples/bar.proto

Now both generated modules has same file options, instead of setting file-options based on file.
In this case, both modules has java_package: "com.bar"

$ iex -S mix
Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> c "elixir_foo.ex"
[Foo]
iex(2)> c "elixir_bar.ex"
[Bar]
iex(3)> Foo.file_options
%Protox.Google.Protobuf.FileOptions{
  __uf__: [],
  cc_enable_arenas: nil,
  cc_generic_services: nil,
  csharp_namespace: nil,
  deprecated: nil,
  go_package: nil,
  java_generate_equals_and_hash: nil,
  java_generic_services: nil,
  java_multiple_files: nil,
  java_outer_classname: nil,
  java_package: "com.bar",
  java_string_check_utf8: nil,
  objc_class_prefix: nil,
  optimize_for: nil,
  php_class_prefix: nil,
  php_generic_services: nil,
  php_metadata_namespace: nil,
  php_namespace: nil,
  py_generic_services: nil,
  ruby_package: nil,
  swift_prefix: nil,
  uninterpreted_option: []
}
iex(4)> Bar.file_options
%Protox.Google.Protobuf.FileOptions{
  __uf__: [],
  cc_enable_arenas: nil,
  cc_generic_services: nil,
  csharp_namespace: nil,
  deprecated: nil,
  go_package: nil,
  java_generate_equals_and_hash: nil,
  java_generic_services: nil,
  java_multiple_files: nil,
  java_outer_classname: nil,
  java_package: "com.bar",
  java_string_check_utf8: nil,
  objc_class_prefix: nil,
  optimize_for: nil,
  php_class_prefix: nil,
  php_generic_services: nil,
  php_metadata_namespace: nil,
  php_namespace: nil,
  py_generic_services: nil,
  ruby_package: nil,
  swift_prefix: nil,
  uninterpreted_option: []
}

OK, thanks, I've found the problem!

The bug fo the use case you provided is now fixed, can you give it a try?

Fix seems to be working. Thanks @ahamez.

I released version 1.7.0 that supports FileOptions. Thanks for your input!