getRemainingLengthBytes method

Uint8Buffer getRemainingLengthBytes()

Calculates and return the bytes that represent the remaining length of the message.

Implementation

typed.Uint8Buffer getRemainingLengthBytes() {
  final lengthBytes = typed.Uint8Buffer();
  var payloadCalc = _messageSize;

  // Generate a byte array based on the message size, splitting it up into
  // 7 bit chunks, with the 8th bit being used to indicate 'one more to come'
  do {
    var nextByteValue = payloadCalc % 128;
    payloadCalc = payloadCalc ~/ 128;
    if (payloadCalc > 0) {
      nextByteValue = nextByteValue | 0x80;
    }
    lengthBytes.add(nextByteValue);
  } while (payloadCalc > 0);

  return lengthBytes;
}