我对GRPC比较陌生,并且在我的proto文件中发现了一个错误,我似乎无法理解。我想使用"google.protobuf.Timestamp“在消息中发送时间。我似乎不能导入它。我做错了什么?
syntax = "proto3";
import "google/protobuf/timestamp.proto";
service ProfileService {
rpc ConstructProfileStructFromUser (ConstructProfileStructFromUserRequest) returns (ConstructProfileStructFromUserResponse);
}
message ConstructProfileStructFromUserRequest {
string transactionID = 1;
string User = 2;
}
message ConstructProfileStructFromUserResponse {
string UID = 1;
string ContactEmail = 2;
google.protobuf.Timestamp DateOfBirth = 3;
}
在我的IDE和编译器中(使用下面的命令),我都会得到错误
google/protobuf/timestamp.proto: File not found.
profile.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
profile.proto:21:5: "google.protobuf.Timestamp" is not defined.
要运行的命令:
protoc -I profile/ profile/profile.proto --go_out=plugins=grpc:profile
Protoc --版本
libprotoc 3.0.0
发布于 2021-03-18 18:59:18
在同样的情况下,我最终要做的是
message google {
message protobuf {
message Timestamp {
int64 seconds = 1;
int32 nanos = 2;
}
}
}
在我的原始文件里。这足以让它被识别为众所周知的类型,所以在python中,我得到了在https://developers.google.com/protocol-buffers/docs/reference/python-generated#timestamp中描述的附加API。
主要的好处是我们都可以继续使用protoc
的系统安装,而不需要从源代码安装。
https://stackoverflow.com/questions/56031098
复制相似问题