I'm trying to fix a bug in Audio::OSC, where values are packed/unpacked incorrectly on some platforms and I've run into a problem I can't really solve:
According to the OSC Spec examples, a float value of 440.0 should be encoded as 43 dc 00 00. Using pack('f', 440.0'), I get these results:
- Mac: 43 dc 00 00 - correct according to spec.
- PC: 00 00 43 dc - incorrect.
A user suggested the somewhat unsightly combination pack("N", unpack("l", pack("f", 440.0))), but that yielded
- Mac: 43 dc 00 00 - still correct
- PC: dc 43 00 00 - still incorrect, but differently
Can somebody help me to come up with a good and fast solution for this? Even if it only works on PCs, it's okay -- I can check the endian-ness on startup and make aliases for the correct function to use. The main point is that it should be correct and fast.