public byte[] serializeBatch(BatchTuple batch) { if (batch == null || batch.currBatchSize() == 0) return null; _kryoOut.clear(); for (Tuple tuple : batch.getTuples()) { /* * byte structure: * 1st tuple: length + tuple bytes * 2nd tuple: length + tuple bytes * ...... */ int startPos = _kryoOut.position(); // Set initial value of tuple length, which will be updated accordingly after serialization _kryoOut.writeInt(0); serializeTuple(_kryoOut, tuple); // Update the tuple length int endPos = _kryoOut.position(); _kryoOut.setPosition(startPos); _kryoOut.writeInt(endPos - startPos - 4); _kryoOut.setPosition(endPos); } return _kryoOut.toBytes(); }