// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
//     Comparator<LogKey> COMPARATOR = (k1, k2) -> {
//         final int termCompare = Integer.compare(k1.term(), k2.term());
//         return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
//     };
// 
//     int term();
//     LogKey term(int term);
// 
//     long index();
//     LogKey index(long index);
// 
//     @Override
//     default int compareTo(final LogKey other) {
//         return COMPARATOR.compare(this, other);
//     }
// 
//     default LogContainment containedIn(final CommandLog commandLog) {
//         return LogContainment.containmentFor(this, commandLog);
//     }
// 
// }
// 
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
//     VOTE_REQUEST {
//         @Override
//         public Message create(final DirectFactory factory) {
//             return factory.voteRequest();
//         }
//     },
//     VOTE_RESPONSE {
//         @Override
//         public Message create(final DirectFactory factory) {
//             return factory.voteResponse();
//         }
//     },
//     APPEND_REQUEST {
//         @Override
//         public Message create(final DirectFactory factory) {
//             return factory.appendRequest();
//         }
//     },
//     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);
//     }
// 
// 
// }
// 
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
// 
//     int term();
// 
//     VoteRequest term(int term);
// 
//     int candidateId();
// 
//     VoteRequest candidateId(int candidateId);
// 
//     LogKey lastLogKey();
// 
//     @Override
//     default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
//         return eventHandler.onVoteRequest(serverContext, this);
//     }
// }


import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.message.VoteRequest;
/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.tools4j.hoverraft.message.direct;


public final class DirectVoteRequest extends AbstractDirectMessage implements VoteRequest {

    private static final int TERM_OFF = TYPE_OFF + TYPE_LEN;
    private static final int TERM_LEN = 4;
    private static final int CANDIDATE_ID_OFF = TERM_OFF + TERM_LEN;
    private static final int CANDIDATE_ID_LEN = 4;
    private static final int LAST_LOG_KEY_OFF = CANDIDATE_ID_OFF + CANDIDATE_ID_LEN;
    private static final int LAST_LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;

    public static final int BYTE_LENGTH = LAST_LOG_KEY_OFF + LAST_LOG_KEY_LEN;

    private final DirectLogKey lastLogKey = new DirectLogKey() ;

    @Override
    public MessageType type() {
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
//     Comparator<LogKey> COMPARATOR = (k1, k2) -> {
//         final int termCompare = Integer.compare(k1.term(), k2.term());
//         return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
//     };
// 
//     int term();
//     LogKey term(int term);
// 
//     long index();
//     LogKey index(long index);
// 
//     @Override
//     default int compareTo(final LogKey other) {
//         return COMPARATOR.compare(this, other);
//     }
// 
//     default LogContainment containedIn(final CommandLog commandLog) {
//         return LogContainment.containmentFor(this, commandLog);
//     }
// 
// }
// 
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
//     VOTE_REQUEST {
//         @Override
//         public Message create(final DirectFactory factory) {
//             return factory.voteRequest();
//         }
//     },
//     VOTE_RESPONSE {
//         @Override
//         public Message create(final DirectFactory factory) {
//             return factory.voteResponse();
//         }
//     },
//     APPEND_REQUEST {
//         @Override
//         public Message create(final DirectFactory factory) {
//             return factory.appendRequest();
//         }
//     },
//     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);
//     }
// 
// 
// }
// 
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
// 
//     int term();
// 
//     VoteRequest term(int term);
// 
//     int candidateId();
// 
//     VoteRequest candidateId(int candidateId);
// 
//     LogKey lastLogKey();
// 
//     @Override
//     default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
//         return eventHandler.onVoteRequest(serverContext, this);
//     }
// }


// Path: src/main/java/org/tools4j/hoverraft/message/direct/DirectVoteRequest.java
import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.message.VoteRequest;

/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.tools4j.hoverraft.message.direct;


public final class DirectVoteRequest extends AbstractDirectMessage implements VoteRequest {

    private static final int TERM_OFF = TYPE_OFF + TYPE_LEN;
    private static final int TERM_LEN = 4;
    private static final int CANDIDATE_ID_OFF = TERM_OFF + TERM_LEN;
    private static final int CANDIDATE_ID_LEN = 4;
    private static final int LAST_LOG_KEY_OFF = CANDIDATE_ID_OFF + CANDIDATE_ID_LEN;
    private static final int LAST_LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;

    public static final int BYTE_LENGTH = LAST_LOG_KEY_OFF + LAST_LOG_KEY_LEN;

    private final DirectLogKey lastLogKey = new DirectLogKey() ;

    @Override
    public MessageType type() {
        return MessageType.VOTE_REQUEST;