Re: [Boost-users] Boost iostreams for binary data
On 01/31/2017 09:25 PM, Robert Dailey wrote:
I have my own BinaryInputStream and BinaryOutputStream classes that simply take a reference to some container that meets the requirements of random access and contiguous internal memory. It doesn't own this container, but rather serves as an adapter to the container to allow stream operators to be used for streaming out data. For example, you can stream a `std::uint32_t` to the binary stream, and it will insert 4 elements into an internal byte vector which is just `std::vectorstd::uint8_t`.
Do they work with arrays?
On Sun, Feb 5, 2017 at 5:55 AM, Bjorn Reese
On 01/31/2017 09:25 PM, Robert Dailey wrote:
I have my own BinaryInputStream and BinaryOutputStream classes that simply take a reference to some container that meets the requirements of random access and contiguous internal memory. It doesn't own this container, but rather serves as an adapter to the container to allow stream operators to be used for streaming out data. For example, you can stream a `std::uint32_t` to the binary stream, and it will insert 4 elements into an internal byte vector which is just `std::vectorstd::uint8_t`.
Do they work with arrays?
Yes, albeit a bit awkwardly. The input stream is as follows: using ByteVector = std::vectorstd::uint8_t; ByteVector data{/* some real data */}; BinaryInputStream stream{data}; ByteVector read_bytes = stream.ReadBytes(100); // read 100 bytes into a ByteVector // Output stream: ByteVector data; BinaryOutputStream stream{data}; ByteVector stuff{0x10, 0x20, 0x30}; // bytes to write out stream << stuff; I can't use stream operators for input stream since there is no delimiter in the data to indicate how many bytes to read.
On 02/06/2017 06:03 PM, Robert Dailey wrote:
using ByteVector = std::vectorstd::uint8_t;
I meant, can BinaryInputStream read data from an array, and can BinaryOutputStream write data into an array?
On Mon, Feb 6, 2017 at 12:06 PM, Bjorn Reese
On 02/06/2017 06:03 PM, Robert Dailey wrote:
using ByteVector = std::vectorstd::uint8_t;
I meant, can BinaryInputStream read data from an array, and can BinaryOutputStream write data into an array?
If by array you mean: std::uint8_t bytes[100]; Not in my current implementation. I do not use arrays in my code, so I haven't needed to support it. But my stream classes use iterators and algorithms for writing/reading data, so shouldn't be hard to add. What, if I may ask, are you trying to get at?
participants (2)
-
Bjorn Reese
-
Robert Dailey