PackedBuffer { static void writeReqFrame(ByteBuffer bb, int methodId, long seq, int length) throws IOException { int oldPos = bb.position(); boolean success = false; try { bb.order(ByteOrder.LITTLE_ENDIAN); bb.putInt(HRPC_MAGIC); bb.putInt(methodId); bb.putLong(seq); bb.putInt(length); success = true; } finally { if (!success) { bb.position(oldPos); } } } PackedBuffer(ByteBuffer bb); String toHexString();  }
@Test(timeout = 60000) public void testWriteReqFrame() throws Exception { byte[] arr = new byte[PackedBuffer.HRPC_REQ_FRAME_LENGTH]; ByteBuffer bb = ByteBuffer.wrap(arr); PackedBuffer buf = new PackedBuffer(bb); PackedBuffer.writeReqFrame(bb, 1, 123, 456); Assert.assertEquals(PackedBuffer.HRPC_REQ_FRAME_LENGTH, bb.position()); Assert.assertEquals("48 54 52 43 " + "01 00 00 00 " + "7b 00 00 00 00 00 00 00 " + "c8 01 00 00", buf.toHexString()); }