C++ 如何将文本文件解析为C++;?
通常,我可以调用C++ 如何将文本文件解析为C++;?,c++,protocol-buffers,C++,Protocol Buffers,通常,我可以调用google::protobuf::TextFormat::Parse将prototxt文件解析为消息。但由于某种原因,我现在不得不使用MessageLite。由于TextFormat只接受Message*,因此转换失败。有什么方法可以做到这一点吗?这个MessageLite类有一个带有以下签名的ParseFromString成员 bool MessageLite::ParseFromString(const string & data) 这将解析字符串中包含的协议缓冲
google::protobuf::TextFormat::Parse
将prototxt文件解析为消息。但由于某种原因,我现在不得不使用MessageLite
。由于TextFormat只接受Message*,因此转换失败。有什么方法可以做到这一点吗?这个MessageLite
类有一个带有以下签名的ParseFromString
成员
bool MessageLite::ParseFromString(const string & data)
这将解析字符串中包含的协议缓冲区。
有关更多详细信息,请参阅
我猜你被否决了,因为TextFormat::Parse
的文档说,当你没有Message
而是MessageLite
时,要使用MessageLite::ParseFromString
。不过,将@P.W答案标记为答案是礼貌的。