Reputation: 6305
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.
Upvotes: 1
Views: 1441
Reputation: 47680
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)
Upvotes: 3
Reputation: 1088
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
Upvotes: 2