### Question:
GetAsyncReplyMessageFactory implements OFSerializer<GetAsyncOutput> { @Override public void serialize(GetAsyncOutput message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); serializePacketInMask(message.getPacketInMask(), outBuffer); serializePortStatusMask(message.getPortStatusMask(), outBuffer); serializeFlowRemovedMask(message.getFlowRemovedMask(), outBuffer); ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void serialize(GetAsyncOutput message, ByteBuf outBuffer);  }### Answer:
@Test public void testSerialize() throws Exception { GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setPacketInMask(createPacketInMask()); builder.setPortStatusMask(createPortStatusMask()); builder.setFlowRemovedMask(createFlowRemowedMask()); GetAsyncOutput message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 32); Assert.assertEquals("Wrong packetInMask", 7, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong packetInMask", 0, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong portStatusMask", 7, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong portStatusMask", 0, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong flowRemovedMask", 15, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong flowRemovedMask", 0, serializedBuffer.readUnsignedInt()); }
@Test public void testSetAsyncInputWithNullMasks() throws Exception { GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setPacketInMask(null); builder.setPortStatusMask(null); builder.setFlowRemovedMask(null); GetAsyncOutput message = builder.build(); GetAsyncReplyMessageFactory serializer = new GetAsyncReplyMessageFactory(); SerializerRegistry registry = new SerializerRegistryImpl(); registry.init(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 8); Assert.assertTrue("Unexpected data", serializedBuffer.readableBytes() == 0); }
@Test public void testSerialize() { GetAsyncReplyMessageFactory serializer = new GetAsyncReplyMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 32); Assert.assertEquals("Wrong packetInMask", 7, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong packetInMask", 0, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong portStatusMask", 7, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong portStatusMask", 0, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong flowRemovedMask", 15, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong flowRemovedMask", 0, serializedBuffer.readUnsignedInt()); }
@Test public void testSetAsyncInputWithNullMasks() throws Exception { GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setPacketInMask(null); builder.setPortStatusMask(null); builder.setFlowRemovedMask(null); GetAsyncOutput message = builder.build(); GetAsyncReplyMessageFactory serializer = new GetAsyncReplyMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 8); Assert.assertTrue("Unexpected data", serializedBuffer.readableBytes() == 0); }