PduCodec { public static Pdu decodePdu(ByteBuf in) throws IOException { byte version = in.getByte(0); if (version == VERSION_3) { byte flags = in.getByte(1); byte type = in.getByte(2); long messageId = in.getLong(3); return Pdu.newPdu(in, type, flags, messageId); } throw new IOException("Cannot decode version " + version); }  static Pdu decodePdu(ByteBuf in); static Object readObject(ByteBuf dii); static final byte VERSION_3; static final byte TYPE_STRING; static final byte TYPE_LONG; static final byte TYPE_INTEGER; static final byte TYPE_BYTEARRAY; static final byte TYPE_TIMESTAMP; static final byte TYPE_NULL; static final byte TYPE_DOUBLE; static final byte TYPE_BOOLEAN; static final byte TYPE_SHORT; static final byte TYPE_BYTE; }
@Test public void readObjectsTrailer() throws Exception { long msgId = 1234; String ts = "dsfs"; String query = "q"; long scannerId = 2332; long tx = 353; List<Object> params = Arrays.asList("1", 12L, 3d); long statementId = 2342; int fetchSize = 12313; int maxRows = 1239; boolean keepReadLocks = false; ByteBuf write = PduCodec.OpenScanner.write(msgId, ts, query, scannerId, tx, params, statementId, fetchSize, maxRows, keepReadLocks); try (Pdu pdu = PduCodec.decodePdu(write);) { assertEquals(msgId, pdu.messageId); assertEquals(Pdu.TYPE_OPENSCANNER, pdu.type); assertEquals(ts, PduCodec.OpenScanner.readTablespace(pdu)); assertEquals(query, PduCodec.OpenScanner.readQuery(pdu)); assertEquals(scannerId, PduCodec.OpenScanner.readScannerId(pdu)); assertEquals(tx, PduCodec.OpenScanner.readTx(pdu)); assertEquals(statementId, PduCodec.OpenScanner.readStatementId(pdu)); assertEquals(fetchSize, PduCodec.OpenScanner.readFetchSize(pdu)); assertEquals(maxRows, PduCodec.OpenScanner.readMaxRows(pdu)); PduCodec.ObjectListReader paramsReader = PduCodec.OpenScanner.startReadParameters(pdu); assertEquals(params.size(), paramsReader.getNumParams()); assertEquals(RawString.of((String) params.get(0)), paramsReader.nextObject()); assertEquals(params.get(1), paramsReader.nextObject()); assertEquals(params.get(2), paramsReader.nextObject()); byte trailer = paramsReader.readTrailer(); assertTrue(isDontKeepReadLocks(trailer)); } keepReadLocks = true; write = PduCodec.OpenScanner.write(msgId, ts, query, scannerId, tx, params, statementId, fetchSize, maxRows, keepReadLocks); try (Pdu pdu = PduCodec.decodePdu(write);) { assertEquals(msgId, pdu.messageId); assertEquals(Pdu.TYPE_OPENSCANNER, pdu.type); assertEquals(ts, PduCodec.OpenScanner.readTablespace(pdu)); assertEquals(query, PduCodec.OpenScanner.readQuery(pdu)); assertEquals(scannerId, PduCodec.OpenScanner.readScannerId(pdu)); assertEquals(tx, PduCodec.OpenScanner.readTx(pdu)); assertEquals(statementId, PduCodec.OpenScanner.readStatementId(pdu)); assertEquals(fetchSize, PduCodec.OpenScanner.readFetchSize(pdu)); assertEquals(maxRows, PduCodec.OpenScanner.readMaxRows(pdu)); PduCodec.ObjectListReader paramsReader = PduCodec.OpenScanner.startReadParameters(pdu); assertEquals(params.size(), paramsReader.getNumParams()); assertEquals(RawString.of((String) params.get(0)), paramsReader.nextObject()); assertEquals(params.get(1), paramsReader.nextObject()); assertEquals(params.get(2), paramsReader.nextObject()); byte trailer = paramsReader.readTrailer(); assertEquals(0, trailer); assertFalse(isDontKeepReadLocks(trailer)); } }