Uint64 swapIfLittleEndian

Please could you add in the 64 bit swap inlines? The swapbyte order is there, just not the helpers.

Bruce

Sure, no problem.

Thanks.

It also looks like MemoryInputStream and OutputStream aren’t handling int64 very well? I was writing int64 as bigendian (since it’s a network app) and reading back big-endian and getting total gobbeldy-gook (on an Intel Mac).

It looks like the existing code does a poor man’s byte swap, not the real thing, and that doesn’t seem to work (although I can’t see how that would have done between platforms).

I just copied the approach from the other ints - hopefully that doesn’t break cases like float, that seems to use this method.

But now I look, all these functions are for uints, and the to/from streams are for ints. What gives? Does the sign just work out? Must do.

Bruce

[code]void OutputStream::writeInt64 (int64 value)
{
const uint64 v = swapIfBigEndian ((uint64) value);
write (&v, 8);
}

void OutputStream::writeInt64BigEndian (int64 value)
{
const uint64 v = swapIfLittleEndian ((uint64) value);
write (&v, 8);
}
[/code]

[code]int64 InputStream::readInt64()
{
char temp [8];

if (read (temp, 8) == 8)
    return (int64) swapIfBigEndian (*(uint64*)temp);
else
    return 0;

}

int64 InputStream::readInt64BigEndian()
{
char temp [8];

if (read (temp, 8) == 8)
    return (int64) swapIfLittleEndian (*(uint64*)temp);
else
    return 0;

}
[/code]

Yes, you’re quite right there. It looks like old code that I should have tidied up by now. Thanks, I’ll check in a fix shortly. I think the writeDouble method should be ok, as it’s writing it as little-endian, and only the big-endian routine had a bug.

Don’t worry about the signs - converting between uints and ints doesn’t actually do anything to the numbers themselves.