3 #include "../conversion/conversionexception.h" 22 BinaryWriter::BinaryWriter(ostream *stream)
33 : m_stream(other.m_stream)
80 const uint64 size = value.size();
82 byte prefixLength = 1;
83 for (; boundCheck != 0x8000000000000000; boundCheck <<= 7, ++prefixLength) {
84 if (size < boundCheck) {
85 BE::getBytes(size | boundCheck, m_buffer);
89 if (prefixLength == 9) {
92 m_stream->write(m_buffer + 8 - prefixLength, prefixLength);
93 m_stream->write(value.data(),
static_cast<streamsize
>(size));
BinaryWriter(std::ostream *stream)
Constructs a new BinaryWriter.
Writes primitive data types to a std::ostream.
The ConversionException class is thrown by the various conversion functions of this library when a co...
std::uint64_t uint64
unsigned 64-bit integer
void giveOwnership()
The writer will take ownership over the assigned stream.
void writeLengthPrefixedString(const std::string &value)
Writes the length of a string and the string itself to the current stream.
Contains utility classes helping to read and write streams.
void setStream(std::ostream *stream, bool giveOwnership=false)
Assigns the stream the writer will write to when calling one of the write-methods.
Contains several functions providing conversions between different data types.
~BinaryWriter()
Destroys the BinaryWriter.
const std::ostream * stream() const
Returns a pointer to the stream the writer will write to when calling one of the write-methods.
std::uint8_t byte
unsigned byte