【问题标题】:Can't assign int32 protobuf to int in Go lang [duplicate]无法在 Go lang 中将 int32 protobuf 分配给 int [重复]
【发布时间】:2018-02-17 15:24:15
【问题描述】:

所以在我的 protobuf 中有一个消息对象

message HelloReply {
    int32 response = 1;
}

我尝试将响应分配给一个变量

var resp = 0
resp = helloReply.Response

我说错了

cannot use helloReply.Response (type int32) as type int in assignment

P.S 我对 Go 和 Protobuf 真的很陌生。如果这太基本了,我很抱歉。我已经在寻找解决方案,但我想我找不到正确的关键字。所以我真的需要你们的帮助:(

【问题讨论】:

  • 您可以创建var resp int32 将int32 值赋给resp 变量
  • @Himanshu OMG 谢谢!我也刚刚在另一个问题上找到了这个答案。

标签: go protocol-buffers grpc


【解决方案1】:

创建 int32 类型的 resp 变量并将 helloReply.Response 分配给 resp 变量。像这样

var resp int32
resp = helloReply.Response

【讨论】:

    猜你喜欢
    • 2014-10-10
    • 1970-01-01
    • 2022-12-19
    • 1970-01-01
    • 2020-04-19
    • 1970-01-01
    • 2016-10-25
    • 2012-02-21
    • 1970-01-01
    相关资源
    最近更新 更多