如何使用import语句解析Google Protocol Buffers .proto文件

时间:2017-02-10 05:12:42

标签: c++ c protocol-buffers proto

我有两个.proto文件: example1.proto:

syntax = "proto3";
package example1;
import "pkt2.proto";
...

和pkt2.proto文件。

当我尝试解析example1.proto:

DiskSourceTree source_tree;
source_tree.MapPath("", ".");
MFErrorPrinter mf_error_printer;
Importer importer(&source_tree, &mf_error_printer);
importer.AddUnusedImportTrackFile(file_name);
const FileDescriptor* parsed_file = importer.Import(fn);
...

我收到了错误:

proto/example/example1.proto.. proto/example/example1.proto:51:24: Option "(pkt2.variable)" unknown.
proto/example/example1.proto:60:22: Option "(pkt2.variable)" unknown.
proto/example/example1.proto:70:27: Option "(pkt2.variable)" unknown.
proto/example/example1.proto:11:11: Option "(pkt2.output)" unknown.
proto/example/example1.proto: warning: Import pkt2.proto but not used.

如何导入/解析文件?

已编辑:经过多次试用后,我发现了自己的错误:

以下两个陈述中的文件名:

source_tree.MapPath("", ".");
...
const FileDescriptor* parsed_file = importer.Import(fn);

文件名不正确:

"."
"proto/example/example1.proto"

因此,进口商找不到“proto / pkt2.proto”。有效值为:

"proto"
"example/example1.proto"

0 个答案:

没有答案