|
Boost : |
From: Olaf van der Spek (olafvdspek_at_[hidden])
Date: 2006-03-28 10:06:40
On 3/28/06, Caleb Epstein <caleb.epstein_at_[hidden]> wrote:
> On 3/28/06, Olaf van der Spek <olafvdspek_at_[hidden]> wrote:
>
> When reading/writing binary streams, you often need to read/write an
> > (unaligned) integer in big, little or native endian. Is there support
> > for this in Boost?
>
> The closest thing I'm aware of is the portable_binary_oarchive (and
> iarchive) in the Boost.Serialization examples directory. This has logic to
> save integers and longs in little-endian format regardless of the hardware
> architecture, saving a single byte length + binary data that represents the
> value. For example, 42 would be saved as \x01\x2a and 1024 would be saved
> as \x02\x00\x04
That's not good enough.
> What do other Boost developers/users use/recommend?
> > Wouldn't this make a nice additional to the new asio library?
>
>
> Having machine word conversion logic is indeed very handy for network
> programming. The C library will always (?) provide the primitive hton[ls]
That's not standard C (AFAIK) but BSD sockets.
> and ntoh[ls] routines, but these are not always sufficient in today's
> world. Many protocols are strictly little-endian, or utilize
> receiver-makes-right semantics, wherein the receiver of the data converts
> the data to the correct format for their architecture. General purpose
> byte-swapping routines for varying "word" sizes (2, 4, 8, 16) are invaluable
Other sizes (3, 6, others) may also be nice, although those are far less common.
> when implementing these sorts of protocols.
>
> Its not entirely clear (to me at least) where this sort of logic belongs in
> Boost, as it is potentially useful in more places than just a networking
> library.
True. But it seems asio's future includes other IO too.
> Perhaps this should be just a single header in the boost
> directory?
That would be good.
Olaf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk