From just a message's bytes you can't turn it into a Message. The
serialized format doesn't include type information.
You've got a couple choices. First, if you can send the message's
Descriptor along with the message, then you can use
DynamicMessage.parseFrom(Descriptor, byte[]) to deserialize it. If
you can't send the message's Descriptor along, then you can use
UnknownFieldSet.parseFrom(byte[]), but that's not going to give you
very much at all, just tag numbers, their wiretype, and their value.
- Adam
All the different kinds of descriptors have associated protocol
messages available through their toProto() methods, so you can
serialize them, send them over the wire, and deserialize them on the
other end. You have to deserialize a FileDescriptorProto, though, so
you can either send the appropriate FileDescriptorProto or just send a
DescriptorProto and build the file on the receiving end.
- Adam