英文:
Protoc protoc-gen-go "timestamp" is not defined
问题
我需要使用Protocol Buffers将从Google Drive的drives:list方法接收到的JSON消息序列化,并将其写入BigQuery Storage Write API(GRPC)。对于除了时间戳之外的所有字段类型,这都是有效的。但是,我无论如何都无法生成包含时间戳的Go类。首先,我遵循这个文档,但也尝试了网上找到的所有方法,包括在stackoverflow上,但都没有成功。
在MacOS 12.6上,我从这个zip文件中安装了protoc到/usr/local/bin,并将zip文件中的include目录安装到了/usr/local/include。
这是我需要为之创建类的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;
google.protobuf.Timestamp createdTime = 7;
message Restrictions {
bool adminManagedRestrictions = 1;
bool domainUsersOnly = 2;
bool copyRequiresWriterPermission = 3;
bool driveMembersOnly = 4;
}
}
如果我移除类型为timestamp的字段,该工具会创建一个名为./driveBuffers/drives.pb.go的文件。但是,如果包含timestamp类型,就会抛出以下错误:
% protoc --go_out=. -I ./ -I /usr/local/include/ drives.proto
drives.proto:11:3: "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). This is working for all field types except timestamp. I cannot for the life of me generate go classes that include timestamps. To begin, I'm following this document, although have also tried everything I can find online including here on stackoverflow to no avail.
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.
This is the drives.proto file I need to create a class for:
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. 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.
答案1
得分: 3
你应该将类型指定为google.protobuf.Timestamp
。例如:
string orgUnitId = 6;
google.protobuf.Timestamp createdTime = 7;
英文:
You should refer the type as google.protobuf.Timestamp
. As example:
string orgUnitId = 6;
google.protobuf.Timestamp createdTime = 7;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论