44void BinaryWriter::writeVariableLengthInteger(std::uint64_t value,
void (*getBytes)(std::uint64_t,
char *))
46 std::uint64_t boundCheck = 0x80;
47 std::uint8_t prefixLength = 1;
48 for (; boundCheck != 0x8000000000000000; boundCheck <<= 7, ++prefixLength) {
49 if (value < boundCheck) {
50 getBytes(value | boundCheck, m_buffer);
54 if (prefixLength == 9) {
55 throw ConversionException(
"The variable-length integer to be written exceeds the maximum.");
57 m_stream->write(m_buffer + 8 - prefixLength, prefixLength);
void giveOwnership()
The writer will take ownership over the assigned stream.
void setStream(std::ostream *stream, bool giveOwnership=false)
Assigns the stream the writer will write to when calling one of the write-methods.
const std::ostream * stream() const
Returns a pointer to the stream the writer will write to when calling one of the write-methods.
Contains all utilities provided by the c++utilities library.