@Test public void shouldEncodeCorrectly() { final ByteBuffer encodedMsgBuffer = ByteBuffer.allocateDirect(MSG_BUFFER_CAPACITY); encodeTestMessage(encodedMsgBuffer); final DirectBuffer decodeBuffer = new UnsafeBuffer(encodedMsgBuffer); int offset = 0; assertThat(decodeBuffer.getShort(offset), is((short) 22)); offset += BitUtil.SIZE_OF_SHORT; assertThat(decodeBuffer.getShort(offset), is((short) 1)); offset += BitUtil.SIZE_OF_SHORT; assertThat(decodeBuffer.getShort(offset), is((short) 3)); offset += BitUtil.SIZE_OF_SHORT; assertThat(decodeBuffer.getShort(offset), is((short) 0)); offset += BitUtil.SIZE_OF_SHORT; assertThat(decodeBuffer.getByte(offset), is((byte) 10)); offset += BitUtil.SIZE_OF_BYTE; assertThat(decodeBuffer.getByte(offset), is((byte) 42)); offset += BitUtil.SIZE_OF_BYTE; assertThat(decodeBuffer.getInt(offset), is(0x00_01_00_00)); offset += BitUtil.SIZE_OF_INT; assertThat(decodeBuffer.getLong(offset), is(101L)); offset += BitUtil.SIZE_OF_LONG; assertThat(decodeBuffer.getLong(offset), is(202L)); }
public static int keepaliveInterval(final DirectBuffer directBuffer, final int offset) { return directBuffer.getInt(offset + KEEPALIVE_INTERVAL_FIELD_OFFSET, ByteOrder.BIG_ENDIAN); }
public static int version(final DirectBuffer directBuffer, final int offset) { return directBuffer.getInt(offset + VERSION_FIELD_OFFSET, ByteOrder.BIG_ENDIAN); }
public static int maxLifetime(final DirectBuffer directBuffer, final int offset) { return directBuffer.getInt(offset + MAX_LIFETIME_FIELD_OFFSET, ByteOrder.BIG_ENDIAN); }
public void wrap(final DirectBuffer buffer, final int offset) { if (buffer.getInt(offset) != type().ordinal()) { throw new IllegalArgumentException("Buffer must contain message type " + type()); } super.wrap(buffer, offset); }