当我尝试在Golang中编译Protobuf时,它显示“’int’未定义”。

huangapple go评论98阅读模式
英文:

When I'm trying to compile the Protobuf in golang, It's showing '"int" is not defined.'

问题

在编译proto文件时,我遇到了“'int'未定义”的错误。

'test.proto'文件

syntax = "proto3";

package test;

option go_package = "/test";

message User {
    string FirstName = 1;
    string LastName = 2;
    string Address = 3;
    int Contact = 4;
    int Age = 5;
}
输出:
test.proto:11:5: "int"未定义。
英文:

While compiling the proto file, I'm getting '"int" is not defined'.

'test.proto' file

syntax = "proto3";

package test;

option go_package = "/;test";

message User {
    string FirstName = 1;
    string LastName = 2;
    string Address = 3;
    int Contact = 4;
    int Age = 5;
}
Output:
test.proto:11:5: "int" is not defined.

答案1

得分: 5

int在proto3中不是标量类型。您必须使用指定的有效标量值类型之一:

https://developers.google.com/protocol-buffers/docs/proto3#scalar

int替换为int32

syntax = "proto3";

package test;

option go_package = "/test";

message User {
    string FirstName = 1;
    string LastName = 2;
    string Address = 3;
    int32 Contact = 4;
    int32 Age = 5;
}
英文:

int is not a scalar type in proto3. You must use one of the valid scalar value types as specified:

https://developers.google.com/protocol-buffers/docs/proto3#scalar

Replacing int with int32:

syntax = "proto3";

package test;

option go_package = "/;test";

message User {
    string FirstName = 1;
    string LastName = 2;
    string Address = 3;
    int32 Contact = 4;
    int32 Age = 5;
}

huangapple
  • 本文由 发表于 2022年7月2日 19:38:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/72838746.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定