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 Jones
http://evanjones.ca/
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,