首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
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

Stack Overflow用户

发布于 2021-03-18 18:59:18

在同样的情况下,我最终要做的是

代码语言:javascript
运行
复制
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的系统安装,而不需要从源代码安装。

票数 -3
EN
查看全部 6 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56031098

复制
相关文章

相似问题

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