use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class Connection method decode.
/**
* Decode received messages
* @param buf received data from socket
* @return decoded message
*/
public Msg decode(ByteBuffer buf) {
if (raw == null) {
header.put(buf);
if (header.remaining() != 0) {
return null;
}
header.flip();
raw = new Buffer(header.getVarInt() + header.position());
header.rewind();
raw.put(header);
header.clear();
}
raw.put(buf);
if (raw.remaining() == 0) {
raw.flip();
Buffer msg = raw;
raw = null;
return Msg.create(msg);
}
return null;
}
use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class ClientResp method encode.
/**
* Encode message
*/
@Override
public void encode() {
if (!rawReady) {
int headerLen = ProtoUtil.byteLen(TYPE) + ProtoUtil.booleanLen(result) + ProtoUtil.longLen(sequence);
length = headerLen + data.remaining();
headerLen += ProtoUtil.varIntLen(length);
if (rawMsg == null) {
rawMsg = new Buffer(headerLen);
}
rawMsg.clear();
rawMsg.putVarInt(length);
rawMsg.put(ClientResp.TYPE);
rawMsg.putBoolean(result);
rawMsg.putLong(sequence);
rawMsg.flip();
rawReady = true;
assert (rawMsg.remaining() >= Msg.MIN_MSG_SIZE);
}
}
use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class ConnectReq method encode.
/**
* Encode message
*/
@Override
public void encode() {
if (!rawReady) {
length = ProtoUtil.byteLen(ConnectReq.TYPE) + ProtoUtil.stringLen(clusterName) + ProtoUtil.stringLen(name) + ProtoUtil.booleanLen(client);
if (rawMsg == null) {
rawMsg = new Buffer(length + ProtoUtil.varIntLen(length));
}
rawMsg.clear();
rawMsg.putVarInt(length);
rawMsg.put(ConnectReq.TYPE);
rawMsg.putString(clusterName);
rawMsg.putString(name);
rawMsg.putBoolean(client);
rawMsg.flip();
rawReady = true;
assert (rawMsg.remaining() >= Msg.MIN_MSG_SIZE);
}
}
use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class JoinReq method encode.
/**
* Encode JoinReq
*/
@Override
public void encode() {
if (!rawReady) {
length = 1 + record.encodedLen();
if (rawMsg == null) {
rawMsg = new Buffer(length + ProtoUtil.varIntLen(length));
}
rawMsg.clear();
rawMsg.putVarInt(length);
rawMsg.put(JoinReq.TYPE);
record.encode(rawMsg);
rawMsg.flip();
rawReady = true;
assert (rawMsg.remaining() >= Msg.MIN_MSG_SIZE);
}
}
use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class JoinResp method encode.
/**
* Encode JoinResp
*/
@Override
public void encode() {
if (!rawReady) {
length = 1 + +ProtoUtil.booleanLen(result) + record.encodedLen();
if (rawMsg == null) {
rawMsg = new Buffer(length + ProtoUtil.varIntLen(length));
}
rawMsg.clear();
rawMsg.putVarInt(length);
rawMsg.put(JoinReq.TYPE);
record.encode(rawMsg);
rawMsg.putBoolean(result);
rawMsg.flip();
rawReady = true;
assert (rawMsg.remaining() >= Msg.MIN_MSG_SIZE);
}
}
Aggregations