code: static ByteBuf doEncode(ByteBufAllocator byteBufAllocator, MqttMessage message) {
  
          switch (message.fixedHeader().messageType()) {
              case CONNECT:
                  return encodeConnectMessage(byteBufAllocator, (MqttConnectMessage) message);
  
              case CONNACK:
                  return encodeConnAckMessage(byteBufAllocator, (MqttConnAckMessage) message);
  
              case PUBLISH:
                  return encodePublishMessage(byteBufAllocator, (MqttPublishMessage) message);
  
              case SUBSCRIBE:
                  return encodeSubscribeMessage(byteBufAllocator, (MqttSubscribeMessage) message);
  
              case UNSUBSCRIBE:
                  return encodeUnsubscribeMessage(byteBufAllocator, (MqttUnsubscribeMessage) message);
  
              case SUBACK:
                  return encodeSubAckMessage(byteBufAllocator, (MqttSubAckMessage) message);
  
              case UNSUBACK:
              case PUBACK:
              case PUBREC:
              case PUBREL:
              case PUBCOMP:
                  return encodeMessageWithOnlySingleByteFixedHeaderAndMessageId(byteBufAllocator, message);
  
              case PINGREQ:
              case PINGRESP:
              case DISCONNECT:
                  return encodeMessageWithOnlySingleByteFixedHeader(byteBufAllocator, message);
  
              default:
                  throw new IllegalArgumentException(
                          "Unknown message type: " + message.fixedHeader().messageType().value());
          }
      }
docs: This is the main encoding method.
  It's only visible for testing.
  
  @param byteBufAllocator Allocates ByteBuf
  @param message MQTT message to encode
  @return ByteBuf with encoded bytes