tags:

views:

23

answers:

1

I'm using to do some serialization stuff "as it can be seen here". That worked fine, but I couldn't figure how to get the size of the written buffer.I've searched on boost documentation and apparently there is no way to do this aside of building a sink/source by myself?

Thanks

+1  A: 

boost::iostreams::basic_array_sink models a SinkDevice only, which gives you write-only semantics and no way of telling how many bytes have been written.

OTOH, its sibling boost::iostreams::basic_array models a SeekableDevice allowing to utilize the seek() member function of your stream:

namespace io = boost::iostreams;

char buffer[4096]; 
io::stream<io::basic_array<char> > source(buffer, buffer_size); 

boost::archive::binary_oarchive oa(source); 
oa << serializable_object;  

// move current stream position to the end, io::seek() returns new position 
std::cout << "Bytes written: " 
          << io::seek(source, 0, std::ios_base::end) 
          << std::endl;
hkaiser
thanks, worked perfectly!
scooterman