[protobuf] Decoding / Encoding Help

2014-12-03 Thread Carmelita Relles
I have the following message structures that compiles smoothly in protoc.exe
message MessageBase {
extensions 2;
required Header header = 1;
}

message Message1 {
  extends MessageBase {
optional Message1 message = 2;
  }
  optional int32 id = 1;
}

message Message2 {
  extends MessageBase {
optional Message2 message = 2;
  }
  optional int32 count = 1;
}

What is the fastest way to encode and decode Message1 and Message2?

Let's assume that from Header field, we can know if message is Message1 or 
Message2 instance. So far I have the following code (in Java):

Header header = M3apMessage.parseFrom( data ).getHeader();
switch( header.getMessageType ){
  case Message1:
//How to decode the rest of the bytes as stated in Message1 structure
  break;

  case Message2:
//How to decode the rest of the bytes as stated in Message2 structure
  break;
}

Thanks in advance!

-- 
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.


[protobuf] Reading Message Extensions

2014-12-03 Thread Carmelita Relles
I would like to know what is the fastest way to read a message extension, 
say for example, I have the following structure:
message BaseMessage 
{
   extensions 2;
   required Header header = 1;
}

message Message1 
{
   extend BaseMessage 
  {
required Message1 message = 2;   
  }
  optional int32 id = 1;
}

message Message2 
{
   extend BaseMessage 
  {
required Message1 message = 2;   
  }
  optional String name = 1;
}

Structure above is compilable by protoc.exe. 

Let's say that from the header, I know if the message is Message1 or 
Message2 instance.

How will I be able to parse this in Java? Here's the code I have so far :
Header header = M3apMessage.parseFrom( data ).getHeader();

switch( header.getMessageType() )
{
case MESSAGE1:
//HOW TO READ THE REST OF THE MESSAGE AS MESSAGE1?
break;
case MESSAGE2:
//HOW TO READ THE REST OF THE MESSAGE AS MESSAGE2?
break;
}

Thanks in advance for the help!

-- 
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.