Merge "Fixing OF Multipart messages 1) So we have a MultipartRequestDesc message...
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / ExperimenterInputMessageFactory.java
index fde8713323fbfa251803ba1dac43e5b0dc086c0c..de2133f21137242176473f84a61d65d9d7b2d9fb 100644 (file)
@@ -3,18 +3,20 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 \r
 import io.netty.buffer.ByteBuf;\r
 \r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\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
+ * Translates Experimenter messages\r
  * @author michal.polkorab\r
- *\r
+ * @author timotej.kubas\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 static final byte MESSAGE_LENGTH = 8;\r
     private static ExperimenterInputMessageFactory instance;\r
     \r
     private ExperimenterInputMessageFactory() {\r
@@ -24,7 +26,7 @@ public class ExperimenterInputMessageFactory implements OFSerializer<Experimente
     /**\r
      * @return singleton factory\r
      */\r
-    public static ExperimenterInputMessageFactory getInstance() {\r
+    public static synchronized ExperimenterInputMessageFactory getInstance() {\r
         if (instance == null) {\r
             instance = new ExperimenterInputMessageFactory();\r
         }\r
@@ -34,12 +36,28 @@ public class ExperimenterInputMessageFactory implements OFSerializer<Experimente
     @Override\r
     public void messageToBuffer(short version, ByteBuf out,\r
             ExperimenterInput message) {\r
-        out.writeByte(message.getVersion());\r
-        out.writeByte(MESSAGE_TYPE);\r
-        out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER + (Integer.SIZE/Byte.SIZE)*2);\r
-        out.writeInt(message.getXid().intValue());\r
+        ByteBufUtils.writeOFHeader(instance, message, out);\r
         out.writeInt(message.getExperimenter().intValue());\r
         out.writeInt(message.getExpType().intValue());\r
+        byte[] data = message.getData();\r
+        if (data != null) {\r
+            out.writeBytes(data);\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public int computeLength(ExperimenterInput message) {\r
+        int length = MESSAGE_LENGTH + 2 * (Integer.SIZE / Byte.SIZE);\r
+        byte[] data = message.getData();\r
+        if (data != null) {\r
+            length += data.length;\r
+        }\r
+        return length;\r
     }\r
 \r
+    @Override\r
+    public byte getMessageType() {\r
+        return MESSAGE_TYPE;\r
+    }\r
+    \r
 }\r