【发布时间】:2020-07-13 11:01:44
【问题描述】:
我正在尝试使用 Timestamp 并将其导入到 protobuf 消息中 -
import "google/protobuf/timestamp.proto";
message TriggerDataMsg {
google.protobuf.Timestamp start_time = 1;
google.protobuf.Timestamp end_time = 2;
google.protobuf.Timestamp next_fire_time = 3;
google.protobuf.Timestamp previous_fire_time = 4;
sint32 priority = 13;
}
当尝试使用 protoc 编译器进行编译以生成 Java 类时,失败并出现以下错误 -
[echo] compiling proto sources...
[exec] google/protobuf/timestamp.proto:35:8: Option "csharp_namespace" unknown.
[exec] com/vmware/nsx/management/backup/model/trigger_data.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
[exec] com/vmware/nsx/management/backup/model/trigger_data.proto:24:5: "google.protobuf.Timestamp" is not defined.
[exec] com/vmware/nsx/management/backup/model/trigger_data.proto:25:5: "google.protobuf.Timestamp" is not defined.
[exec] com/vmware/nsx/management/backup/model/trigger_data.proto:26:5: "google.protobuf.Timestamp" is not defined.
[exec] com/vmware/nsx/management/backup/model/trigger_data.proto:27:5: "google.protobuf.Timestamp" is not defined.
我不确定为什么它会检查“csharp_namespace”,即使我正在生成 Java 类。 我可以尝试摆脱此错误的任何解决方法?
【问题讨论】:
-
“我不确定它为什么要检查“csharp_namespace””因为那在 timestamp.proto 文件中。
-
是的,但它为什么要找那个。而且我不想为 csharp 生成任何类。那么如何摆脱这个错误呢?
-
我怀疑这是红鲱鱼,问题真的是
"google.protobuf.Timestamp" is not defined。生成源代码时,您需要在--proto_path中引用google/protobuf/timestamp.proto。时间戳与./include/google/protobuf/timestamp.proto中的protoc 捆绑在一起。然后你需要在你的实现中导入Timestamps。 -
@RahulVedpathak 它正在通过 import 语句导入您要求它导入的文件。该文件包含可能与您相关或不相关的内容,但所有内容均已处理,因为无法知道它们与您无关。
标签: java protocol-buffers grpc protoc