code: private static MqttFixedHeader decodeFixedHeader(ByteBuf buffer) {
          short b1 = buffer.readUnsignedByte();
  
          MqttMessageType messageType = MqttMessageType.valueOf(b1 >> 4);
          boolean dupFlag = (b1 & 0x08) == 0x08;
          int qosLevel = (b1 & 0x06) >> 1;
          boolean retain = (b1 & 0x01) != 0;
  
          int remainingLength = 0;
          int multiplier = 1;
          short digit;
          int loops = 0;
          do {
              digit = buffer.readUnsignedByte();
              remainingLength += (digit & 127) * multiplier;
              multiplier *= 128;
              loops++;
          } while ((digit & 128) != 0 && loops < 4);
  
          // MQTT protocol limits Remaining Length to 4 bytes
          if (loops == 4 && (digit & 128) != 0) {
              throw new DecoderException("remaining length exceeds 4 digits (" + messageType + ')');
          }
          MqttFixedHeader decodedFixedHeader =
                  new MqttFixedHeader(messageType, dupFlag, MqttQoS.valueOf(qosLevel), retain, remainingLength);
          return validateFixedHeader(resetUnusedFields(decodedFixedHeader));
      }
docs: Decodes the fixed header. It's one byte for the flags and then variable bytes for the remaining length.
  
  @param buffer the buffer to decode from
  @return the fixed header