Function encodeLong
Encodes a long into a variable number of bytes in a given buffer.
ulong encodeLong
(
long input,
ref ubyte[10] output
) nothrow @safe;
Example
ubyte[12] bytes;
size_t n;
n = encodeLong( 0, bytes[0..10]);
assert(bytes[0..n] == [0b00000000]);
n = encodeLong( 1, bytes[0..10]);
assert(bytes[0..n] == [0b00000010]);
n = encodeLong(-2, bytes[0..10]);
assert(bytes[0..n] == [0b00000011]);
n = encodeLong( 2147483647, bytes[0..10]);
assert(bytes[0..n] == [0b11111110, 0b11111111, 0b11111111, 0b11111111, 0b00001111]);
n = encodeLong(-2147483648, bytes[0..10]);
assert(bytes[0..n] == [0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b00001111]);
n = encodeLong(9223372036854775807, bytes[0..10]);
assert(bytes[0..n] == [
0b11111110, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b00000001]);
n = encodeLong(-9223372036854775808, bytes[0..10]);
assert(bytes[0..n] == [
0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b00000001]);