BinaryIO.writeLengthBytes

Advanced Writes out a length in a compact format.

More...
class BinaryIO
void
writeLengthBytes
(
size_t length
)

Detailed Description

This function aims to minimize the amount of bytes needed to write out the length of an array.

If the length is <= to 63, then a single byte is used.

If the length is <= to 16,383, then two bytes are used.

If the length is <= to 1,073,741,823, then four bytes are used.

In some cases it may be better to set a strict byte limit for an array, so this function may not be useful.

Notes: Use this function if you need to write out the length of an array (outside of the Easy functions).

The last two bits are reserved for size info, so the max value of length is (2^30)-1, or 1,073,741,823

In big endian, the last two bits are used, since they will appear first in the data output. In little endian, the number is shifted to the left by two, so the first two bits can be used, again, because the first two bits will be in the first byte of the output.

Throws

Exception if length is greater than 0x3FFFFFFF.

Meta