I have imported an other proto which having different package name than mine. For usage of messages from other package, have accessed that message with package name.
For Example :
other.proto
package muthu.other; message Other{ required float val = 1; }
myproto.proto
package muthu.test; import "other.proto"; message MyProto{ required string str = 1; optional muthu.other.Other.val = 2; }
Is there a way to use val of muthu.other package directly like optional val = 2; instead of using muthu.other.Other.val ?
Couldn't find any help document regarding this. Help me out.
It's possible to import proto3 message types and use them in your proto2 messages, and vice versa. However, proto2 enums cannot be used in proto3 syntax.
proto file starts with a package declaration, which helps to prevent naming conflicts between different projects.
A . proto file is similar to a JSON file in that it represents structured data, but you can run a compiler on the . proto file to generate code that can read and write the data in the programming language of your choice.
Protocol Buffer (Protobuf) provides two simpler options for dealing with values that might be of more than one type. The Any type can represent any known Protobuf message type. And you can use the oneof keyword to specify that only one of a range of fields can be set in any message.
If the package name is same then you can omit the package name from the field declaration but otherwise there is no other way. if you can include muthu.test in the same package by specifying "package muthu.other" then it is allowed.
From Google documentation of protobuf:
You can add an optional package specifier to a .proto file to prevent name clashes between protocol message types.
package foo.bar; message Open { ... }
You can then use the package specifier when defining fields of your message type:
message Foo { ... required foo.bar.Open open = 1; ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With