dizews / php-ubjson

Universal Binary JSON for PHP
9 stars 7 forks source link

Problem using endianness #1

Closed rafsalvioni closed 9 years ago

rafsalvioni commented 9 years ago

Hello Vladimir

Firstly, congratulations by your excellent class!

I'm working in a project that uses many serializers formats. I catched your class to work with UBJSON. However, I found a little problem when I work with numbers.

In UBJSON specification is written that all numbers should be encoded using big-endian byte order. However, you are using flags of pack() function ("s", "l", "f") that depends of the machine's byte order. Considering that your machine should be Intel or AMD, these CPUs uses little-endian byte order. So, all numbers are encoded with your class are using this byte order.

I solved this problem and I modified your class. I created a constant that informs the machine's byte order and I swap the bytes order when is necessary.

If you want, I can send you the modifications.

Bye

dizews commented 9 years ago

Hello, thanks for your submit. Your can always send a pull request.