小编dmi*_*iry的帖子

解析文本格式的protobuf消息时如何忽略错误的字段

我在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)

c++ parsing protocol-buffers

5
推荐指数
1
解决办法
1142
查看次数

标签 统计

c++ ×1

parsing ×1

protocol-buffers ×1