One way to do this, that I have done in the past as to have a top level 
protobuf object that has and enum (or uint...) and just a byte array (or 
what ever the correct type is here).
This defines the basic container. You can use an enum to specify what the 
payload will be, then you can just switch on this to properally decode the 
rest of the object.



message Container {
enum TypeId
{
  UNDEFINED = 0;
  FRUIT = 1;
  CAR = 2;
}
required enum TypeId = 1;
required bytes Payload = 2;
}

Then in your own proto file

message PayloadFruit
{
  required uint Version  =1;
  required string Name = 2;
}

You get the drift.....



On Monday, 16 November 2015 00:05:22 UTC, 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