> An example:
> Foo.jar contains the compiled Java code for the following protobuf:
> option java_package = "com.foo";
> message FooMsg {
> optional int32 a = 1;
> optional int32 b = 2;
> ...
> }
>
> In my code, I want to do this:
> option java_package = "com.bar";
> message BarMsg {
> optional com.foo.FooMsg my_foo = 1;
> ...
> }
>
> However, for the purposes of this discussion, I do not have access to
> the proto file for FooMsg, and thus cannot simply do an "import
> FooMsg.proto".
>
> Just want to know if this is possible as it would be very convenient
> for me.
There are two ways to do this, one if you can deal with a dependency
in the other direction, and one if neither can depend on the other.
If you can allow FooMsg to depend on BarMsg, then you can use extensions:
in barmsg.proto:
message BarMsg {
extension 100 to max;
}
in foomsg.proto:
message FooMsg {
optional int32 a = 1;
optional int32 b = 2;
extend BarMsg {
optional FooMsg my_foo = 100;
}
}
Alternatively, if you can't have dependencies in either direction, you
can send opaque messages as bytes, like so:
message BarMsg {
optional bytes my_foo = 1;
}
But you have to do the serializing and deserializing manually:
BarMsg bar = BarMsg.parseFrom(whatever);
FooMsg foo = FooMsg.parseFrom(bar.getMyFoo());
- Adam
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.