简体   繁体   English

未定义 protoc protoc-gen-go “时间戳”

[英]Protoc protoc-gen-go "timestamp" is not defined

I need to use Protocol Buffers to serialize JSON messages received from the Google Drive drives:list method and write them to the BigQuery Storage Write API (GRPC).我需要使用协议缓冲区序列化从 Google Drive drive:list 方法收到的 JSON 消息,并将它们写入 BigQuery Storage Write API (GRPC)。 This is working for all field types except timestamp.这适用于除时间戳之外的所有字段类型。 I cannot for the life of me generate go classes that include timestamps.我一生都无法生成包含时间戳的 go 类。 To begin, I'm following this document , although have also tried everything I can find online including here on stackoverflow to no avail.首先,我正在关注此文档,尽管我也尝试了我可以在网上找到的所有内容,包括在 stackoverflow 上的所有内容,但均无济于事。

On MacOS 12.6, protoc is installed from this zip to /usr/local/bin and the contents of include from the zip are installed to /usr/local/include.在 MacOS 12.6 上, protoc 从此 zip安装到 /usr/local/bin,并将 zip 中的 include 内容安装到 /usr/local/include。

This is the drives.proto file I need to create a class for:这是我需要创建 class 的 drive.proto 文件:

syntax = "proto3";
option go_package = "./driveBuffers";
import "google/protobuf/timestamp.proto";
message Drive {
  string id =1;
  string name =2;
  string colorRgb = 3;
  string backgroundImageLink =4;
  bool hidden = 5;
  string orgUnitId = 6;
  timestamp createdTime = 7;
  message restrictions {
    bool adminManagedRestrictions = 1;
    bool domainUsersOnly = 2;
    bool copyRequiresWriterPermission = 3;
    bool driveMembersOnly = 4;
  }
}

If I remove the field with type timestamp, the tool creates a file named./driveBuffers/drives.pb.go.如果我删除时间戳类型的字段,该工具会创建一个名为./driveBuffers/drives.pb.go 的文件。 With the timestamp type, this error is thrown:使用时间戳类型,将引发此错误:

% protoc --go_out=. -I ./ -I /usr/local/include/ drives.proto
drives.proto:11:3: "timestamp" is not defined.

Thank you.谢谢你。

You should refer the type as google.protobuf.Timestamp .您应该将类型称为google.protobuf.Timestamp As example:例如:

  string orgUnitId = 6;
  google.protobuf.Timestamp createdTime = 7;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM