Search in sources :

Example 26 with Buffer

use of tezc.base.common.Buffer in project tezcRaft by tezc.

the class ConnectResp method encode.

/**
 * Encode message
 */
@Override
public void encode() {
    if (!rawReady) {
        length = ProtoUtil.byteLen(ConnectResp.TYPE) + ProtoUtil.varIntLen(id) + ProtoUtil.varLongLen(sequence) + ProtoUtil.booleanLen(result) + cluster.encodedLen();
        if (rawMsg == null) {
            rawMsg = new Buffer(length + ProtoUtil.varIntLen(length));
        }
        rawMsg.clear();
        rawMsg.putVarInt(length);
        rawMsg.put(ConnectResp.TYPE);
        cluster.encode(rawMsg);
        rawMsg.putVarInt(id);
        rawMsg.putVarLong(sequence);
        rawMsg.putBoolean(result);
        rawMsg.flip();
        rawReady = true;
        assert (rawMsg.remaining() >= Msg.MIN_MSG_SIZE);
    }
}
Also used : Buffer(tezc.base.common.Buffer)

Example 27 with Buffer

use of tezc.base.common.Buffer in project tezcRaft by tezc.

the class Entry method calculateBufs.

/**
 * Calculate and prepare header raw buffer
 */
private void calculateBufs() {
    int headerLen = ProtoUtil.varIntLen(stateId) + ProtoUtil.varLongLen(clientId) + ProtoUtil.varLongLen(sequence) + ProtoUtil.varLongLen(term);
    headerLen += ProtoUtil.varIntLen(headerLen + ProtoUtil.bufferLen(data));
    header = new Buffer(headerLen);
    header.putVarInt(headerLen + ProtoUtil.bufferLen(data));
    header.putVarInt(stateId);
    header.putVarLong(clientId);
    header.putVarLong(sequence);
    header.putVarLong(term);
    header.flip();
}
Also used : Buffer(tezc.base.common.Buffer) ByteBuffer(java.nio.ByteBuffer)

Example 28 with Buffer

use of tezc.base.common.Buffer in project tezcRaft by tezc.

the class ReqVoteReq method encode.

/**
 * Decode message
 */
@Override
public void encode() {
    if (!rawReady) {
        length = ProtoUtil.byteLen(ReqVoteReq.TYPE) + ProtoUtil.varLongLen(term) + ProtoUtil.varIntLen(candidateId) + ProtoUtil.varLongLen(lastLogIndex) + ProtoUtil.varLongLen(lastLogTerm);
        if (rawMsg == null) {
            rawMsg = new Buffer(length + ProtoUtil.varIntLen(length));
        }
        rawMsg.clear();
        rawMsg.putVarInt(length);
        rawMsg.put(ReqVoteReq.TYPE);
        rawMsg.putVarLong(term);
        rawMsg.putVarInt(candidateId);
        rawMsg.putVarLong(lastLogIndex);
        rawMsg.putVarLong(lastLogTerm);
        rawMsg.flip();
        rawReady = true;
        assert (rawMsg.remaining() >= Msg.MIN_MSG_SIZE);
    }
}
Also used : Buffer(tezc.base.common.Buffer)

Aggregations

Buffer (tezc.base.common.Buffer)28 ByteBuffer (java.nio.ByteBuffer)16 FileChannel (java.nio.channels.FileChannel)2 Path (java.nio.file.Path)2 StandardOpenOption (java.nio.file.StandardOpenOption)2 Session (tezc.core.cluster.Session)2 ClusterRecord (tezc.core.record.ClusterRecord)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 State (tezc.State)1