@Test public void test() throws Exception { PacketOutInput expectedMessage = createMessage(); SerializerRegistry registry = new SerializerRegistryImpl(); registry.init(); NetIdePacketOutInputMessageFactory serializer = new NetIdePacketOutInputMessageFactory(); serializer.injectSerializerRegistry(registry); ByteBuf originalBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(expectedMessage, originalBuffer); originalBuffer.skipBytes(4); PacketOutInput deserializedMessage = BufferHelper.deserialize(factory, originalBuffer); Assert.assertEquals("Wrong version", expectedMessage.getVersion(), deserializedMessage.getVersion()); Assert.assertEquals("Wrong XId", expectedMessage.getXid(), deserializedMessage.getXid()); Assert.assertEquals("Wrong buffer Id", expectedMessage.getBufferId(), deserializedMessage.getBufferId()); Assert.assertEquals("Wrong In Port", expectedMessage.getInPort().getValue(), deserializedMessage.getInPort().getValue()); Assert.assertEquals("Wrong Numbers of actions", expectedMessage.getAction().size(), deserializedMessage.getAction().size()); int i = 0; for (Action a : expectedMessage.getAction()) { Assert.assertEquals("Wrong action", a, deserializedMessage.getAction().get(i)); i++; } Assert.assertArrayEquals("Wrong data", expectedMessage.getData(), deserializedMessage.getData()); }
@Override public PacketOutInput deserialize(ByteBuf rawMessage) { PacketOutInputBuilder builder = new PacketOutInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setInPort(new PortNumber(rawMessage.readUnsignedInt())); int actions_len = rawMessage.readShort(); rawMessage.skipBytes(PADDING); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, actions_len, rawMessage, keyMaker, registry); builder.setAction(actions); byte[] data = rawMessage.readBytes(rawMessage.readableBytes()).array(); if (data != null) { builder.setData(data); } return builder.build(); }
PacketOutInputMessageFactory implements OFDeserializer<PacketOutInput>, DeserializerRegistryInjector { @Override public PacketOutInput deserialize(ByteBuf rawMessage) { PacketOutInputBuilder builder = new PacketOutInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setInPort(new PortNumber(rawMessage.readUnsignedInt())); int actions_len = rawMessage.readShort(); rawMessage.skipBytes(PADDING); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, actions_len, rawMessage, keyMaker, registry); builder.setAction(actions); byte[] data = rawMessage.readBytes(rawMessage.readableBytes()).array(); if (data != null) { builder.setData(data); } return builder.build(); } }
PacketOutInputMessageFactory implements OFDeserializer<PacketOutInput>, DeserializerRegistryInjector { @Override public PacketOutInput deserialize(ByteBuf rawMessage) { PacketOutInputBuilder builder = new PacketOutInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setInPort(new PortNumber(rawMessage.readUnsignedInt())); int actions_len = rawMessage.readShort(); rawMessage.skipBytes(PADDING); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, actions_len, rawMessage, keyMaker, registry); builder.setAction(actions); byte[] data = rawMessage.readBytes(rawMessage.readableBytes()).array(); if (data != null) { builder.setData(data); } return builder.build(); }  }
PacketOutInputMessageFactory implements OFDeserializer<PacketOutInput>, DeserializerRegistryInjector { @Override public PacketOutInput deserialize(ByteBuf rawMessage) { PacketOutInputBuilder builder = new PacketOutInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setInPort(new PortNumber(rawMessage.readUnsignedInt())); int actions_len = rawMessage.readShort(); rawMessage.skipBytes(PADDING); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, actions_len, rawMessage, keyMaker, registry); builder.setAction(actions); byte[] data = rawMessage.readBytes(rawMessage.readableBytes()).array(); if (data != null) { builder.setData(data); } return builder.build(); }  @Override PacketOutInput deserialize(ByteBuf rawMessage); @Override void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry); }
PacketOutInputMessageFactory implements OFDeserializer<PacketOutInput>, DeserializerRegistryInjector { @Override public PacketOutInput deserialize(ByteBuf rawMessage) { PacketOutInputBuilder builder = new PacketOutInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setInPort(new PortNumber(rawMessage.readUnsignedInt())); int actions_len = rawMessage.readShort(); rawMessage.skipBytes(PADDING); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, actions_len, rawMessage, keyMaker, registry); builder.setAction(actions); byte[] data = rawMessage.readBytes(rawMessage.readableBytes()).array(); if (data != null) { builder.setData(data); } return builder.build(); }  @Override PacketOutInput deserialize(ByteBuf rawMessage); @Override void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry);  }