kallaspriit / Cassandra-PHP-Client-Library

Cassandra PHP-based client library for managing and querying your Cassandra cluster
http://cassandra-php-client-library.com
103 stars 25 forks source link

unpackInteger() fails for negative Integers #23

Open joerguib opened 12 years ago

joerguib commented 12 years ago

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.