CE-14 change the sizes to be 2 byte unsigned shorts ( to bring it inline with chronicle network )

This commit is contained in:
Rob Austin
2015-03-11 19:08:45 +00:00
parent c5c52b2e4a
commit cd076f8b3c
3 changed files with 12 additions and 9 deletions
@@ -54,7 +54,7 @@ abstract class AbstractChannelReplicator implements Closeable {
public static final int BITS_IN_A_BYTE = 8;
public static final int SIZE_OF_SIZE = 4;
public static final int SIZE_OF_SIZE = 2;
public static final int SIZE_OF_TRANSACTION_ID = 8;
public static final int SIZE_OF_TIME_SHIFT = 2;
@@ -55,6 +55,7 @@ import java.util.function.Function;
import static java.nio.channels.SelectionKey.OP_READ;
import static java.nio.channels.SelectionKey.OP_WRITE;
import static net.openhft.chronicle.map.AbstractChannelReplicator.SIZE_OF_SIZE;
/**
* @author Rob Austin.
@@ -243,7 +244,7 @@ public class StatelessWiredConnector<K extends BytesMarshallable, V extends Byte
}
private void processMessage() {
while (inWire.bytes().remaining() > 4) {
while (inWire.bytes().remaining() > SIZE_OF_SIZE) {
final long limit = inWire.bytes().limit();
@@ -307,11 +308,13 @@ public class StatelessWiredConnector<K extends BytesMarshallable, V extends Byte
@Nullable
private Wire nextWireMessage() {
if (inWire.bytes().remaining() < 4)
if (inWire.bytes().remaining() < SIZE_OF_SIZE)
return null;
final Bytes<?> bytes = inWire.bytes();
int size = bytes.readInt(bytes.position());
// the size of the next wire message
int size = bytes.readUnsignedShort(bytes.position());
inWire.bytes().ensureCapacity(bytes.position() + size);
@@ -323,7 +326,7 @@ public class StatelessWiredConnector<K extends BytesMarshallable, V extends Byte
inWire.bytes().limit(bytes.position() + size);
// skip the size
inWire.bytes().skip(4);
inWire.bytes().skip(SIZE_OF_SIZE);
return inWire;
}
@@ -314,7 +314,7 @@ public class WiredStatelessClientTcpConnectionHub {
long pos = outWire.bytes().position();
try {
outWire.bytes().reset();
outWire.bytes().writeInt((int) position);
outWire.bytes().writeUnsignedShort((int) position);
} finally {
outWire.bytes().position(pos);
}
@@ -369,7 +369,7 @@ public class WiredStatelessClientTcpConnectionHub {
// reads just the size
readSocket(SIZE_OF_SIZE, timeoutTime);
final int messageSize = intWire.bytes().readInt(intWire.bytes().position());
final int messageSize = intWire.bytes().readUnsignedShort(intWire.bytes().position());
assert messageSize > 0 : "Invalid message size " + messageSize;
@@ -657,8 +657,8 @@ public class WiredStatelessClientTcpConnectionHub {
// this is where the size will go
outWire.bytes().mark();
// skip the 4 bytes for the size
outWire.bytes().skip(4);
// skip the 2 bytes for the size
outWire.bytes().skip(2);
}
void startTime(long startTime) {