I'm wondering whether boost has binary streams (or whether the standard library does and i missed it). I had a quick look at boost serialisation. looks like it maybe too involved for my needs. my only needs would be something as follows: outstream s; s << (int)3; s << (float)4.0; s << std::string("hello"); void* data = s.buffer(); int size = s.size(); instream s(data, size); int a << s; float b << s; std::string b << s; I plan on sending the data over TCP. Portability would also be handy (ie endian issues). I may use asio when it is avail in the next boost release. does that support binary streams?
On 7/19/06, bringiton bringiton
I'm wondering whether boost has binary streams (or whether the standard library does and i missed it).
Neither boost nor the standard library has support for portable binary serialisation, afaik. I understand it to be bad style to use << and >> for anything other than textual representation, so I don't think your approach is the best. I did experiment with using < and > for binary I/O once, but handling endianness and lengths and such made it a bit of a mess and it wasn't header-only. One thing you might be interested in is Beman's proposed Boost.Endian library, available in the vault : http://www.boost-consulting.com/vault/index.php?directory=Integer . Though not quite as simple as the interface you mention, it does a better job of handling some of the trickier points. Of course it only works for integers, but you can build binary I/O for everything else out of those, pretty much.
I may use asio when it is avail in the next boost release. does that support binary streams?
ASIO does have an iostream with a socket backend, but it's a stream like any other, not a special "binary" one. The above-mentioned library will work fine with it, however. ~ Scott McMurray
participants (2)
-
bringiton bringiton
-
me22