Send ProtocolBuffer Message.Builder to another machine via RMI
I have the following pesudocode:
public void sendPB(ObjectId userId, Messa开发者_开发技巧ge.Builder mb) {
if (userId is logged in to server) {
set mb.ackId to random chars
lookup socket and send mb.build()
}
else {
forward message to user's server via RMI
}
}
The problem is Message.Builders do not implement Serializable, so you cannot send it directly via RMI.
Is there an easy way to do this?
I've tried building partial PB from the builder and sending that over, but in order to reconstruct it you need to know the type or the Descriptor. Descriptor doesn't implement Serializable either.
Thanks
Any reason you can't call build()
, get a Message
, and send it across in whatever the correct format is (e.g., toString()
). At the other end, you can inflate it back into a Message
, and make it back into a builder with toBuilder()
if that's required.
You may also just convert the message to binary format and send that.
Maybe I'm misunderstanding -- the whole point of ProtocolBuffers is to get Message
s into a wire representation, so there are a number of ways to do that (most of which are either Serializable
or trivially wrapped to be.)
I got it working... I had to include a typeID field in the RMI message. Then, I could take the typeID and resolve it to a Message Builder, and then mergeFrom the bytes of the partially built message.
精彩评论