从 golang 中的 fixed64 protobuf 字段读取 int64
read int64 from fixed64 protobuf field in golang
我在 .proto 文件中有一个 fixed64
类型的字段。
我想将其作为 int64 字段读取:
score := int64(pb_obj.Score)
当我尝试编译上述行时,我收到错误消息 cannot convert pb_obj.Score (type *uint64) to type int64
。我也尝试转换 a uint64,得到几乎相同的消息。
根据编译错误,您使用的是 uint64 指针而不是 uint64 值。您可以通过直接使用 * 运算符引用该值来获得所需的内容。我从来没有使用过 protobuf,所以我可以离开,但这应该会让你感动。这是一个很好的参考资料,可能会对 golang pointers
有所帮助
pb_obj.Score
的类型似乎是*uint64
(指向uint64
的指针),而不是uint64
。您只需要访问指针引用的值:
score := int64(*pb_obj.Score)
(区别见*
前缀)
我在 .proto 文件中有一个 fixed64
类型的字段。
我想将其作为 int64 字段读取:
score := int64(pb_obj.Score)
当我尝试编译上述行时,我收到错误消息 cannot convert pb_obj.Score (type *uint64) to type int64
。我也尝试转换 a uint64,得到几乎相同的消息。
根据编译错误,您使用的是 uint64 指针而不是 uint64 值。您可以通过直接使用 * 运算符引用该值来获得所需的内容。我从来没有使用过 protobuf,所以我可以离开,但这应该会让你感动。这是一个很好的参考资料,可能会对 golang pointers
有所帮助pb_obj.Score
的类型似乎是*uint64
(指向uint64
的指针),而不是uint64
。您只需要访问指针引用的值:
score := int64(*pb_obj.Score)
(区别见*
前缀)