我有两个 .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"