Boost logo

Boost :

From: troy d. straszheim (troy_at_[hidden])
Date: 2005-09-13 19:57:04

Hi Robert, boost...

I've implemented a portable binary archive, wondering if there is
general interest. I've tested (very thoroughly) on our target
platforms, which are 32 and 64 bit linux, and osx on a g5, each platform
reads and writes archives written by the others, down to the bit.

The archive itself is stored little-endian (as the vast majority of my
users are on intel hardware) so big-endian platforms are responsible for
byteswapping, though this could be configurable. The problem types are
(unsigned) long int and long double. For long int, the archive checks
to see if it is small enough to fit into 32 bits, if so it stores it in
32 bits, otherwise it throws. For long double, it just throws, as
that's 12 bytes on some platforms, 16 on others, no good way to handle
this, and the type is seldom used anyhow. Float and double are assumed
to be ieee754, and are just handled as blocks of 32 or 64 bytes. So if
the write succeeds, the read is guaranteed to.

Part of the idea here is that without resorting to widespread use of
int32_t and friends, 4-byte-long platforms are always be able to write
archives readable on 8-byte-long platforms. On 8-byte-long platforms,
you could write archives readable on the smaller machines, but best to
choose either int or long long int or a typedef thereof (int32_t or

The code is at, in


Issues that come to mind:
The test isn't boost-test, that'd need rewriting. Haven't tried any of
this on microsoft. Maybe there is some preferred way to detect
endianness. The decision to go little-endian was relatively arbitrary,
maybe the byte-swapping should be configurable. A possibility I
considered was to upgrade all 32 bit longs to 64 bit and do the
range-check/throw when *reading* (We nixed this idea, preferring to have
the error come up sooner rather than later), maybe this should be
configurable as well. There's surely platforms out there with other
differences that aren't handled, I don't have a good feel for whether
they would make the archive useless to a wider audience. The tests
require having access to binary archives written on other platforms,
haven't yet thought about how to put that together in the boost
build/test context.

So have a look, let me know if you're interested. Thanks again for a
great lib.

troy d. straszheim

Boost list run by bdawes at, gregod at, cpdaniel at, john at