当我尝试在 golang 中编译 Protobuf 时,它显示“int”未定义。
时间:2024-04-13
浏览:303
作者:佚名
在IT行业这个发展更新速度很快的行业,只有不停止的学习,才不会被行业所淘汰。如果你是Golang学习者,那么本文《当我尝试在 golang 中编译 Protobuf 时,它显示“int”未定义。》就很适合你!本篇内容主要包括##content_title##,希望对大家的知识积累有所帮助,助力实战开发!
问题内容
在编译 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;
}
Output: test.proto:11:5: "int" is not defined.
正确答案
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;
}
以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
站内热门
最新文章
12.02
12.02
热门专题
