protected static <T extends AbstractBftMessageData> T fromMessageData(
      final MessageData messageData,
      final int messageCode,
      final Class<T> clazz,
      final Function<Bytes, T> constructor) {
    if (clazz.isInstance(messageData)) {
      @SuppressWarnings("unchecked")
      T castMessage = (T) messageData;
      return castMessage;
    }
    final int code = messageData.getCode();
    if (code != messageCode) {
      throw new IllegalArgumentException(
          String.format(
              "MessageData has code %d and thus is not a %s", code, clazz.getSimpleName()));
    }

    return constructor.apply(messageData.getData());
  }
From message data to type of AbstractBftMessageData.

@param <T> the type parameter AbstractBftMessageData
@param messageData the message data
@param messageCode the message code
@param clazz the clazz
@param constructor the constructor
@return the type of AbstractBftMessageData
consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/messagedata/AbstractBftMessageData.java