Search code examples
c++protocol-buffers

Can ::google::protobuf::MessageLite be serialized by ::google::protobuf::Message


Can wire data, written by ::google::protobuf::MessageLite-based runtime, be serialized by ::google::protobuf::Message(which is a derived class of MessageLite), provided both use same form of message definintion?


Solution

  • Yes. The protobuf wire format is independent of the runtime—or even the programming language—used to encode or decode it. You could serialize a message in C++ and parse it back in Java, or do the same with the lite and full C++ runtimes.

    Within a given binary, most of the member functions that deal with serialization (like ParseFromString and SerializeToString, which the classes generated by protoc override) are defined in MessageLite, so you'd run the same code whether you call them on a Message or a MessageLite.