Zane Pei
Zane Pei

Reputation: 51

How to parse a text file into a protobuf MessageLite object in C++?

Generally, I can call the google::protobuf::TextFormat::Parse to parse a prototxt file into a Message. But now I have to use MessageLite for some reason. Since TextFormat takes only Message*, the conversion fails. Is there any way to do this?

Upvotes: 1

Views: 1755

Answers (2)

Alex Che
Alex Che

Reputation: 7112

Protobuf Lite does not support reflection, which is needed for implementing human-readable text format parser. Therefore it's not possible to read a message in this format using the Lite version.

Upvotes: 1

P.W
P.W

Reputation: 26800

The MessageLite class has a ParseFromString member with the following signature.

bool MessageLite::ParseFromString(const string & data)

This parses a protocol buffer contained in a string.
For more details, you can refer to the documentation on this.

Upvotes: 0

Related Questions