readFrom method
Creates a new MqttHeader based on a list of bytes.
Implementation
void readFrom(MqttByteBuffer headerStream) {
if (headerStream.length < 2) {
headerStream.reset();
throw InvalidHeaderException(
'The supplied header is invalid. Header must be at '
'least 2 bytes long.');
}
final firstHeaderByte = headerStream.readByte();
// Pull out the first byte
retain = (firstHeaderByte & 1) == 1;
qos = MqttUtilities.getQosLevel((firstHeaderByte & 6) >> 1);
duplicate = ((firstHeaderByte & 8) >> 3) == 1;
messageType = MqttMessageType.values[((firstHeaderByte & 240) >> 4)];
// Decode the remaining bytes as the remaining/payload size, input param is the 2nd to last byte of the header byte list
try {
_messageSize = readRemainingLength(headerStream);
} on Exception {
throw InvalidHeaderException(
'The header being processed contained an invalid size byte pattern. '
'Message size must take a most 4 bytes, and the last byte '
'must have bit 8 set to 0.');
} on Error {
throw InvalidHeaderException(
'The header being processed contained an invalid size byte pattern. '
'Message size must take a most 4 bytes, and the last byte '
'must have bit 8 set to 0.');
}
}