use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class RaftState method loadState.
/**
* Deserialize state from an inputstream
*
* @param in inputstream
* @throws IOException on any IO error
*/
@Override
public void loadState(InputStream in) throws IOException {
int len = Util.readVarInt(in);
Buffer buf = new Buffer(len);
in.read(buf.array(), 0, len);
buf.position(len);
buf.flip();
int count = buf.getVarInt();
for (int i = 0; i < count; i++) {
Session session = new Session(buf);
sessions.put(session.getName(), session);
}
record = new ClusterRecord(buf);
}
use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class ConfigCommand method encode.
/**
* Encode the command to a raw buffer
*/
@Override
public void encode() {
if (!rawReady) {
int len = ProtoUtil.byteLen(RegisterCommand.TYPE) + record.encodedLen();
rawMsg = new Buffer(len + ProtoUtil.varIntLen(len));
rawMsg.putVarInt(len);
rawMsg.put(ConfigCommand.TYPE);
record.encode(rawMsg);
rawMsg.flip();
rawReady = true;
}
}
use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class NoOPCommand method encode.
/**
* Encode the command
*/
@Override
public void encode() {
if (!rawReady) {
int len = ProtoUtil.byteLen(TYPE);
rawMsg = new Buffer(len + ProtoUtil.varIntLen(len));
rawMsg.putVarInt(len);
rawMsg.put(TYPE);
rawMsg.flip();
rawReady = true;
}
}
use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class RegisterCommand method encode.
/**
* Encode the command
*/
@Override
public void encode() {
if (!rawReady) {
int len = ProtoUtil.byteLen(RegisterCommand.TYPE) + ProtoUtil.stringLen(name);
rawMsg = new Buffer(len + ProtoUtil.varIntLen(len));
rawMsg.putVarInt(len);
rawMsg.put(RegisterCommand.TYPE);
rawMsg.putString(name);
rawMsg.flip();
rawReady = true;
}
}
use of tezc.base.common.Buffer in project tezcRaft by tezc.
the class UnregisterCommand method encode.
/**
* Encode the command
*/
@Override
public void encode() {
if (!rawReady) {
int len = ProtoUtil.byteLen(UnregisterCommand.TYPE) + ProtoUtil.varIntLen(id);
rawMsg = new Buffer(len + ProtoUtil.varIntLen(len));
rawMsg.putVarInt(len);
rawMsg.put(RegisterCommand.TYPE);
rawMsg.putVarInt(id);
rawMsg.flip();
rawReady = true;
}
}
Aggregations