encodeLength function
Encodes length
into a byte array.
Implementation
List<int> encodeLength(final int length) {
assert(length >= 0);
final List<int> bytes = [];
int remainingLength = length;
for (;;) {
int elem = remainingLength & 0x7f;
remainingLength >>= 7;
if (remainingLength == 0) {
bytes.add(elem);
break;
} else {
elem |= 0x80;
bytes.add(elem);
}
}
return bytes;
}