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