[protobuf] Re: Generic Message Dispatch and Message Handler

2010-10-27 Thread Jimm
Evan,
How are you parsing arbitrary PB bytes into a Generated Message ? I am
finding no class in API that can deserialize  PB byte buffer into
GeneratedMessage?

On Oct 27, 6:27 am, Evan Jones ev...@mit.edu wrote:
 On Oct 26, 2010, at 15:45 , maninder batth wrote:

  My generic Handler would create a GeneratedMessage and look for the
  field messageType. Based on the value of the messageType, a particular
  handler will be invoked.

 This is basically what I have done, for my protobuf RPC  
 implementation. If you only need to choose between a limited set of  
 types, you may want a union type or extensions instead:

 http://code.google.com/apis/protocolbuffers/docs/techniques.html#union

 http://code.google.com/apis/protocolbuffers/docs/proto.html#extensions

 Evan

 --
 Evan Joneshttp://evanjones.ca/

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] Re: Generic Message Dispatch and Message Handler

2010-10-27 Thread Evan Jones

On Oct 27, 2010, at 11:36 , Jimm wrote:

How are you parsing arbitrary PB bytes into a Generated Message ? I am
finding no class in API that can deserialize  PB byte buffer into  
GeneratedMessage?


I'm using the generic Service API that is included with protocol  
buffers, so I'm not using GeneratedMessage. Rather, I'm using a  
message instance itself. The register does something ilke this:


serviceRegister.registerCall(MyCustomMessage.getDefaultInstance());


Then you can parse this with code like the following:

Message requestPrototype = ...;  // stored in registerCall  
implementation

Message.Builder builder = requestPrototype.newBuilderForType();
builder.mergeFrom(requestByteString);


My code is actually available in the following hg repository. I don't   
recommend that people use it directly, since it is a bit hacky, but it  
could serve as an example:


http://people.csail.mit.edu/evanj/hg/index.cgi/javatxn/file/tip/src/ca/evanjones/protorpc/ServiceRegistry.java
http://people.csail.mit.edu/evanj/hg/index.cgi/javatxn/file/tip/src/ca/evanjones/protorpc/ProtoMethodInvoker.java


Good luck,

Evan

--
Evan Jones
http://evanjones.ca/

--
You received this message because you are subscribed to the Google Groups Protocol 
Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.