-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class ExperimenterInputMessageFactory implements OFSerializer<ExperimenterInput>{\r
-\r
- /** Code type of Experimenter message */\r
- public static final byte MESSAGE_TYPE = 4;\r
- private int dataLength;\r
- private static ExperimenterInputMessageFactory instance;\r
- \r
- private ExperimenterInputMessageFactory() {\r
- // do nothing, just singleton\r
- }\r
- \r
- /**\r
- * @return singleton factory\r
- */\r
- public static synchronized ExperimenterInputMessageFactory getInstance() {\r
- if (instance == null) {\r
- instance = new ExperimenterInputMessageFactory();\r
- }\r
- return instance;\r
- }\r
- \r
- @Override\r
- public void messageToBuffer(short version, ByteBuf out,\r
- ExperimenterInput message) {\r
- dataLength = message.getData().length;\r
- ByteBufUtils.writeOFHeader(instance, message, out);\r
- out.writeInt(message.getExperimenter().intValue());\r
- out.writeInt(message.getExpType().intValue());\r
- out.writeBytes(message.getData());\r
- }\r
-\r
- @Override\r
- public int computeLength() {\r
- int ofHeaderLength = 8; //OFHeaderLength\r
- int messageLength = 8; //experimenterHeaderLength\r
- return messageLength + ofHeaderLength + dataLength;\r
- }\r
-\r
- @Override\r
- public byte getMessageType() {\r
- return MESSAGE_TYPE;\r
- }\r
- \r
-}\r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
+
+/**
+ * Translates Experimenter messages
+ * @author michal.polkorab
+ */
+public class ExperimenterInputMessageFactory implements OFSerializer<ExperimenterInput>,
+ SerializerRegistryInjector {
+
+ private SerializerRegistry registry;
+
+ @Override
+ public void serialize(ExperimenterInput message, ByteBuf outBuffer) {
+ long expId = message.getExperimenter().getValue();
+ OFSerializer<ExperimenterInput> serializer = registry.getSerializer(
+ ExperimenterSerializerKeyFactory.createExperimenterMessageSerializerKey(
+ EncodeConstants.OF10_VERSION_ID, expId));
+ serializer.serialize(message, outBuffer);
+ }
+
+ @Override
+ public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+ this.registry = serializerRegistry;
+ }
+}
\ No newline at end of file