Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

unpackInteger() fails for negative Integers #23

Open
joerguib opened this Issue Oct 4, 2012 · 0 comments

Comments

Projects
None yet
1 participant

joerguib commented Oct 4, 2012

Hello,

the unpackInteger() function uses

unpack('N', $value);

which parses $value as unsigned 32bit Big Endian Integer, although 32bit Integers in Cassandra are always signed. This breaks reading negative Integers from Cassandra.
Unfortunately PHP's unpack function seems to lack a mode for 32bit signed Big Endian. If your PHP-Code is running on a Little Endian plattform you can use

unpack('l', strrev($value));

to fix this. Another (endian safe) possible solution is to check if the returned value is >= 2^31 and substract 2^32 in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment