I'm not sure what version of protobuf you're using but if you're using 3 
you could try using Any. I have run into a similar issue where I was using 
a base message object to contain message type, message name as well as an 
Any that contained the message payload. This Any is typically some other 
protobuf message object that is unpacked according to the aforementioned 
variables of the base message object.

You could use an enum like Mark mentioned in his response or an int to 
determine how the Any is to be unpacked.

On Sunday, November 15, 2015 at 7:05:22 PM UTC-5, Jakob Bowyer wrote:
>
> I really like using protobuf but I cannot find a way to make this one case 
> work.
>
> I need to define a base, lets call it Transaction. Each message could be 
> implemented differently so my original implementation was
>
> message Transaction{
>     oneof type {
>         NTx n = 1;
>         TTx tx = 2;
>     }
> }
>
> message NTx {
>     required string something_else;
> }
>
> message TTx {
>     required string soemthing;
> }
>
> Now I need people outside of the project to extend Transaction.
> I realised that oneof can't be extended so I moved to doing
>
> message Transaction {
>     enum /* ... */
>     
> }
>
> This is starting to get chaotic. So I moved to 
>
> message Transaction {
>     required int32 tx_type = 1;
>     extensions 100 to max;
> }
>
> message NTx {
>     extend Transaction {
>         optional int32 tx_type = 101;
>     }
>     optional string something = 1;
> }
>
>
> This also is horrible to work with due to how extensions work in Java.
>
>
>
> I really need some help.
>
> I need a way of a generic transaction envelope. Then I need end users to 
> define their own transaction types with arbitrary data in it.
>
> And it could be two or three client modules combined together. If anyone 
> could help me I would be grateful. 
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to