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.