{ "@context": "https://schema.org", "@type": "Article", "headline": "当我尝试在 golang 中编译 Protobuf 时,它显示“int”未定义。", "datePublished": "2024-04-13T09:00:39", "dateModified": "2024-04-13T09:00:39", "description": "在IT行业这个发展更新速度很快的行业,只有不停止的学习,才不会被行业所淘汰。如果你是Golang学习者,那么本文《当我尝试在 golang 中编译 Protobuf 时,它显示“int”未定义。》就很适合你!本篇内容主要包括##content_title##,希望对大家的知识积累有所帮助,助力实战开发!问题内容在编译 proto 文件时,我收到““int”未定义”。“test.proto”文件syntax = proto3;package test;option go_package = /;tes", "publisher": { "@type": "Organization", "name": "Golang学习网", "url": "https://m.17golang.com" }, "mainEntityOfPage": { "@type": "WebPage", "@id": "https://m.17golang.com/article/123100.html" } }
登录
首页 >  Golang >  Go问答

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

来源:stackoverflow

时间:2024-04-13 09:00:39 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学习网公众号。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>