### Question:
OF10PacketInMessageFactory implements OFDeserializer<PacketInMessage> { @Override public PacketInMessage deserialize(final ByteBuf rawMessage) { PacketInMessageBuilder builder = new PacketInMessageBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setTotalLen(rawMessage.readUnsignedShort()); builder.setInPort(rawMessage.readUnsignedShort()); builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte())); rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER); int remainingBytes = rawMessage.readableBytes(); if (remainingBytes > 0) { final byte[] buf = new byte[remainingBytes]; rawMessage.readBytes(buf); builder.setData(buf); } return builder.build(); }  @Override PacketInMessage deserialize(final ByteBuf rawMessage);  }### Answer:
@Test public void test(){ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04"); PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb); BufferHelper.checkHeaderV10(builtByFactory); Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue()); Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue()); Assert.assertEquals("Wrong inPort", 0x0102, builtByFactory.getInPort().intValue()); Assert.assertEquals("Wrong reason", PacketInReason.OFPRNOMATCH, builtByFactory.getReason()); Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData()); }
@Test public void testWithNoAdditionalData(){ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00"); PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb); Assert.assertNull("Wrong data", builtByFactory.getData()); }