### Question:
HelloInputMessageFactory implements OFSerializer<HelloInput> { @Override public void serialize(HelloInput message, ByteBuf outBuffer) { int startWriterIndex = outBuffer.writerIndex(); ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); serializeElementsList(message, outBuffer); int endWriterIndex = outBuffer.writerIndex(); int paddingRemainder = (endWriterIndex - startWriterIndex) % EncodeConstants.PADDING; if (paddingRemainder != 0) { outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder); } ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void serialize(HelloInput message, ByteBuf outBuffer);  }### Answer:
@Test public void testWithoutElementsSet() throws Exception { HelloInputBuilder hib = new HelloInputBuilder(); BufferHelper.setupHeader(hib, EncodeConstants.OF13_VERSION_ID); HelloInput hi = hib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); helloFactory.serialize(hi, out); BufferHelper.checkHeaderV13(out,(byte) 0, EncodeConstants.OFHEADER_SIZE); }
@Test public void testWith4BitVersionBitmap() throws Exception { int lengthOfBitmap = 4; HelloInputBuilder builder = new HelloInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); List<Elements> expectedElement = createElement(lengthOfBitmap); builder.setElements(expectedElement); HelloInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); helloFactory.serialize(message, out); if (LOG.isDebugEnabled()) { LOG.debug("bytebuf: {}", ByteBufUtils.byteBufToHexString(out)); } BufferHelper.checkHeaderV13(out, (byte) 0, 16); Elements element = readElement(out).get(0); Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType()); Elements comparation = createComparationElement(lengthOfBitmap).get(0); Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(), element.getVersionBitmap().toArray()); }
@Test public void testWith64BitVersionBitmap() throws Exception { int lengthOfBitmap = 64; HelloInputBuilder builder = new HelloInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); List<Elements> expectedElement = createElement(lengthOfBitmap); builder.setElements(expectedElement); HelloInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); helloFactory.serialize(message, out); if (LOG.isDebugEnabled()) { LOG.debug("bytebuf: ", ByteBufUtils.byteBufToHexString(out)); } BufferHelper.checkHeaderV13(out, (byte) 0, 24); Elements element = readElement(out).get(0); Assert.assertEquals("Wrong element type", expectedElement.get(0).getType(), element.getType()); Elements comparation = createComparationElement(lengthOfBitmap).get(0); Assert.assertArrayEquals("Wrong element bitmap", comparation.getVersionBitmap().toArray(), element.getVersionBitmap().toArray()); }