我在c ++中模拟一个用错误字段解析的文本格式文件.
我的简单测试.proto文件:
$ cat settings.proto
package settings;
message Settings {
optional int32 param1 = 1;
optional string param2 = 2;
optional bytes param3 = 3;
}
Run Code Online (Sandbox Code Playgroud)
我的文字格式文件:
$ cat settings.txt
param1: 123
param: "some string"
param3: "another string"
Run Code Online (Sandbox Code Playgroud)
我正在使用google :: protobuf :: TextFormat :: Parser解析文件:
#include <iostream>
#include <fcntl.h>
#include <unistd.h>
#include <fstream>
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <settings.pb.h>
using namespace std;
int main( int argc, char* argv[] )
{
GOOGLE_PROTOBUF_VERIFY_VERSION;
settings::Settings settings;
int fd = open( argv[1], O_RDONLY …Run Code Online (Sandbox Code Playgroud)