首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >未找到Protobuf时间戳

未找到Protobuf时间戳
EN

Stack Overflow用户
提问于 2019-05-08 06:12:19
回答 6查看 15.3K关注 0票数 8

我对GRPC比较陌生,并且在我的proto文件中发现了一个错误,我似乎无法理解。我想使用"google.protobuf.Timestamp“在消息中发送时间。我似乎不能导入它。我做错了什么?

代码语言:javascript
运行
复制
    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和编译器中(使用下面的命令),我都会得到错误

代码语言:javascript
运行
复制
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.

要运行的命令:

代码语言:javascript
运行
复制
protoc -I profile/ profile/profile.proto --go_out=plugins=grpc:profile

Protoc --版本

代码语言:javascript
运行
复制
libprotoc 3.0.0
EN

回答 6

Stack Overflow用户

发布于 2019-11-28 20:26:36

我遇到了这个问题--我使用apt包管理器(ubuntu)安装了protoc编译器,它把protoc编译器放在了像/usr/local/bin这样的地方,在默认情况下,protoc期望并要求导入存在于与这个.e.g相关的包含路径中。/usr/local/bin/protoc旁边的/usr/local/bin/include/*

为了修复这个问题,我使用apt删除了安装的版本,并从github页面下载了最新的版本- github.com/protocolbuffers/protobuf/releases,查找适用于您的os/arch的protoc下载(例如protoc-3.13.0-linux-x86_64.zip),该下载包含所需的内容(在inlcude文件夹中)。只需将include文件夹放在路径中二进制文件的旁边。

票数 3
EN

Stack Overflow用户

发布于 2019-05-08 12:57:25

我的问题很简单...

我没有在本地下载timestamp.proto,因此它找不到它。

我克隆了:

代码语言:javascript
运行
复制
https://github.com/protocolbuffers/protobuf/tree/master/src/google/protobuf

然后,当我运行我的编译器时,我必须给它提供定位timestamp.proto文件的位置。

对我来说这是..。

代码语言:javascript
运行
复制
protoc -I profile/ -I MY_CLONED_REPO_LOCATION/protobuf/src profile/profile.proto --go_out=plugins=grpc:profile

一旦它知道它在哪里有通向源代码的路径,它就可以毫不费力地找到它。

票数 1
EN

Stack Overflow用户

发布于 2020-04-01 17:57:14

我从ubuntu repo安装的protoc 3.0.0也遇到了同样的问题。我找到了另一个解决方案,不用像@SwiftD建议的那样重新安装protobuf,使用--proto_path proto选项。在您的.proto导入中应如下所示(即没有路径):

代码语言:javascript
运行
复制
syntax = "proto3";

import "timestamp.proto"

然后,在protoc调用中,使用--proto_path选项将绝对路径传递到包含timestamp.proto的包目录(我使用github.com/golang/protobuf/ptype/timestamp)。

代码语言:javascript
运行
复制
protoc kcproto.proto --go_out=./  --proto_path=/home/my_home_dir_name/go/src/github.com/golang/protobuf/ptypes/timestamp --proto_path=./

将/home/my_home_dir_name/替换为go包目录

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56031098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档