ProtocolMessage { public static byte[] create(long timestamp, byte[] hBytes, Object body) throws SerializationException, TypeMarkerException { byte[] pBytes = GarmadonSerialization.serialize(body); int mark = GarmadonSerialization.getMarker(body.getClass()); int size = ProtocolConstants.FRAME_DELIMITER_SIZE + hBytes.length + pBytes.length; return ByteBuffer .allocate(size) .putInt(mark) .putLong(timestamp) .putInt(hBytes.length) .putInt(pBytes.length) .put(hBytes) .put(pBytes) .array(); } protected  ProtocolMessage(); static byte[] create(long timestamp, byte[] hBytes, Object body);  }
@Test public void GarmadonMessageSerializer_should_implement_spec() throws TypeMarkerException, SerializationException { byte[] expectedPBytes = new byte[144]; new Random().nextBytes(expectedPBytes); TestEvent testEvent = new TestEvent(expectedPBytes); byte[] headerBytes = new byte[42]; new Random().nextBytes(headerBytes); byte[] actualBytes = ProtocolMessage.create(timestamp, headerBytes, testEvent); ByteBuffer buf = ByteBuffer.wrap(actualBytes); assertThat(buf.getInt(), is(Integer.MAX_VALUE)); assertThat(buf.getLong(), is(timestamp)); int headerLen = buf.getInt(); assertThat(buf.getInt(), is(144)); byte[] hBytes = new byte[headerLen]; buf.get(hBytes); byte[] pBytes = new byte[144]; buf.get(pBytes); assertThat(pBytes, is(expectedPBytes)); }