encodeLength function

List<int> encodeLength(
  1. int length
)

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;
}