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);
}
}
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();
}
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);
}
}
Aggregations