doutidi5037
doutidi5037
2016-02-01 22:31

从golang的fixed64 protobuf字段读取int64

  • IT行业问题
  • 计算机技术
  • it技术
  • 编程语言问答
  • 互联网问答
已采纳

I have a field that is of type fixed64 in a .proto file.

I want to read it as an int64 field:

score := int64(pb_obj.Score)

When I try to compile the line agove I get the error message cannot convert pb_obj.Score (type *uint64) to type int64. I tried converting the a uint64 as well, and got an almost identical message.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douchang8758 douchang8758 5年前

    pb_obj.Score's type seems to be *uint64 (pointer to uint64), not uint64. You just need to access to the value the pointer is referencing:

    score := int64(*pb_obj.Score)
    

    (See the * prefix as the difference)

    点赞 评论 复制链接分享
  • donglu1971 donglu1971 5年前

    Based on the compile error you're working with a uint64 pointer and not a uint64 value. You may get what you want by referencing the value directly using the * operator. I've never worked with protobuf, so I could be off but that should get you moving. Here's a nice reference that may help golang pointers

    点赞 评论 复制链接分享

为你推荐