我需要使用协议缓冲区来序列化从Google驱动器接收到的JSON消息:list方法,并将它们写入BigQuery存储写入API (GRPC)。这适用于除时间戳以外的所有字段类型。我一生都无法生成包含时间戳的go类。首先,我正在跟踪本文件,尽管我也尝试了所有我可以在网上找到的东西,包括这里的堆栈溢出,但都没有效果。
在MacOS 12.6上,协议从这个拉链安装到/usr/local/bin,并将这个拉链的内容安装到/usr/local/这个拉链。
这是我需要创建一个类的drives.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;
}
}如果我删除带有时间戳类型的字段,该工具将创建一个名为./driveBuffers/drives.pb.go的文件。使用时间戳类型,将引发此错误:
% protoc --go_out=. -I ./ -I /usr/local/include/ drives.proto
drives.proto:11:3: "timestamp" is not defined.谢谢。
发布于 2022-09-19 12:46:11
您应该将该类型称为google.protobuf.Timestamp。例如:
string orgUnitId = 6;
google.protobuf.Timestamp createdTime = 7;https://stackoverflow.com/questions/73773164
复制相似问题