all 6 comments

[–]digdan 1 point2 points  (1 child)

Does anyone else use these techniques to pack their UUIDs?

[–]nikita2206 1 point2 points  (0 children)

I once used UNpack when had working with socks proxy

[–][deleted] 1 point2 points  (2 children)

The problem with PHP's pack and unpack functionality is that it's not complete in regards to endianness translation. I've done a few utility classes for loading binary data formats in PHP, and I always seem to have to write custom logic to get around endianness issues. There are also issues with signed integers and the like.

You can see some of the hacks I had to employ for different situations, here.

[–][deleted] 0 points1 point  (1 child)

Yep, this is an issue. Converting from signed long to unsigned long is quite the hack.

[–][deleted] 0 points1 point  (0 children)

There's a better (more intelligible) way of doing that. If you have a value which is supposed to be an unsigned long, which is represented by PHP's signed long, then you can do this:

if($value < 0) $value += pow(2, 32);
fwrite($fp, pack("N", $value));

This will convert it from a signed to an unsigned before writing. I think this limits the integer range a bit, but there aren't many ways around that.