readLengthBytes method Null safety

Uint8Buffer readLengthBytes(
  1. MqttByteBuffer headerStream
)

Reads the length bytes of an MqttHeader from the supplied stream.

Implementation

static typed.Uint8Buffer readLengthBytes(MqttByteBuffer headerStream) {
  final lengthBytes = typed.Uint8Buffer();
  // Read until we've got the entire size, or the 4 byte limit is reached
  int sizeByte;
  var byteCount = 0;
  do {
    sizeByte = headerStream.readByte();
    lengthBytes.add(sizeByte);
  } while (++byteCount <= 4 && (sizeByte & 0x80) == 0x80);
  return lengthBytes;
}