Function encodeInt

Encodes an int into a variable number of bytes in a given buffer.

ulong encodeInt (
  int input,
  ref ubyte[5] output
) nothrow @safe;

Example

ubyte[12] bytes;
size_t n;
n = encodeInt( 0, bytes[0..5]);
assert(bytes[0..n] == [0b00000000]);

n = encodeInt( 1, bytes[0..5]);
assert(bytes[0..n] == [0b00000010]);

n = encodeInt(-2, bytes[0..5]);
assert(bytes[0..n] == [0b00000011]);

n = encodeInt( 2147483647, bytes[0..5]);
assert(bytes[0..n] == [0b11111110, 0b11111111, 0b11111111, 0b11111111, 0b00001111]);

n = encodeInt(-2147483648, bytes[0..5]);
assert(bytes[0..n] == [0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b00001111]);