// we need to remove the amount of overhead to write the
// partial command
// lets write the flags in there
BooleanStream bs = null;
if (wireFormat.isTightEncodingEnabled()) {
bs = new BooleanStream();
bs.writeBoolean(true); // the partial data byte[] is
// never null
}
// lets remove the header of the partial command
// which is the byte for the type and an int for the size of
// the byte[]
chunkSize -= 1 // the data type
+ 4 // the command ID
+ 4; // the size of the partial data
// the boolean flags
if (bs != null) {
chunkSize -= bs.marshalledSize();
}
else {
chunkSize -= 1;
}
if (!wireFormat.isSizePrefixDisabled()) {
// lets write the size of the command buffer
writeBuffer.putInt(chunkSize);
chunkSize -= 4;
}
lastFragment = offset + chunkSize >= length;
if (chunkSize + offset > length) {
chunkSize = length - offset;
}
if (lastFragment) {
writeBuffer.put(LastPartialCommand.DATA_STRUCTURE_TYPE);
}
else {
writeBuffer.put(PartialCommand.DATA_STRUCTURE_TYPE);
}
if (bs != null) {
bs.marshal(writeBuffer);
}
int commandId = command.getCommandId();
if (fragment > 0) {
commandId = sequenceGenerator.getNextSequenceId();