// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
// public interface DirectFactory {
// 
//     AppendRequest appendRequest();
// 
//     AppendResponse appendResponse();
// 
//     VoteRequest voteRequest();
// 
//     VoteResponse voteResponse();
// 
//     TimeoutNow timeoutNow();
// 
//     CommandKey commandKey();
// 
//     Command command();
// 
//     LogEntry logEntry();
// }


import org.agrona.DirectBuffer;
import org.tools4j.hoverraft.direct.DirectFactory;
    APPEND_RESPONSE {
        @Override
        public Message create(final DirectFactory factory) {
            return factory.appendResponse();
        }
    },
    TIMEOUT_NOW {
        @Override
        public Message create(final DirectFactory factory) {
            return factory.timeoutNow();
        }
    };

    private static final MessageType[] VALUES = values();

    public static final MessageType valueByOrdinal(final int ordinal) {
        return VALUES[ordinal];
    }

    public static final int maxOrdinal() {
        return VALUES.length - 1;
    }

    abstract public Message create(DirectFactory factory);

    public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
        final int type = directBuffer.getInt(offset);
        if (type >= 0 & type <= MessageType.maxOrdinal()) {
            return MessageType.valueByOrdinal(type);
        }
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
// public interface DirectFactory {
// 
//     AppendRequest appendRequest();
// 
//     AppendResponse appendResponse();
// 
//     VoteRequest voteRequest();
// 
//     VoteResponse voteResponse();
// 
//     TimeoutNow timeoutNow();
// 
//     CommandKey commandKey();
// 
//     Command command();
// 
//     LogEntry logEntry();
// }


// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
import org.agrona.DirectBuffer;
import org.tools4j.hoverraft.direct.DirectFactory;

    APPEND_RESPONSE {
        @Override
        public Message create(final DirectFactory factory) {
            return factory.appendResponse();
        }
    },
    TIMEOUT_NOW {
        @Override
        public Message create(final DirectFactory factory) {
            return factory.timeoutNow();
        }
    };

    private static final MessageType[] VALUES = values();

    public static final MessageType valueByOrdinal(final int ordinal) {
        return VALUES[ordinal];
    }

    public static final int maxOrdinal() {
        return VALUES.length - 1;
    }

    abstract public Message create(DirectFactory factory);

    public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
        final int type = directBuffer.getInt(offset);
        if (type >= 0 & type <= MessageType.maxOrdinal()) {
            return MessageType.valueByOrdinal(type);
        }
        throw new IllegalArgumentException("Illegal message type: " + type);