Question

I'm using ZK gem to read data from ZooKeeper. It works well when I get the string data in znode but if it's a long data, I get a byte array and couldn't convert into a long variable. I have tried Array#pack but it didn't work.

The data is stored as big-endian byte array in Java.

Was it helpful?

Solution

Finally, I can convert the bytes into long in my way.

l = 0
bytes.each_byte do |byte|
  l = l << 8
  l ^= byte & 0xff
end  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top