3 #include "../conversion/conversionexception.h" 22 BinaryWriter::BinaryWriter(ostream *stream)
33 : m_stream(other.m_stream)
80 size_t length = value.length();
82 m_buffer[0] = 0x80 | length;
83 m_stream->write(m_buffer, 1);
84 }
else if (length < 0x4000) {
85 BE::getBytes(static_cast<uint16>(0x4000 | length), m_buffer);
86 m_stream->write(m_buffer, 2);
87 }
else if (length < 0x200000) {
88 BE::getBytes(static_cast<uint32>(0x200000 | length), m_buffer);
89 m_stream->write(m_buffer + 1, 3);
90 }
else if (length < 0x10000000) {
91 BE::getBytes(static_cast<uint32>(0x10000000 | length), m_buffer);
92 m_stream->write(m_buffer, 4);
96 m_stream->write(value.c_str(), length);
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...
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.