Javadoc update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / EchoReplyInputMessageFactory.java
index 3b3e188ebcbff597a1d233d013159ba325138792..18a0243fa0b9d0e13a9d7e16ce09b284c1ed4db5 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.EchoReplyInput;\r
 \r
 /**\r
+ * Translates EchoReply messages\r
  * @author michal.polkorab\r
- *\r
+ * @author timotej.kubas\r
  */\r
 public class EchoReplyInputMessageFactory implements OFSerializer<EchoReplyInput>{\r
 \r
     /** Code type of EchoReply message */\r
     public static final byte MESSAGE_TYPE = 3;\r
+    private static final int MESSAGE_LENGTH = 8;\r
     private static EchoReplyInputMessageFactory instance;\r
     \r
     private EchoReplyInputMessageFactory() {\r
@@ -24,7 +26,7 @@ public class EchoReplyInputMessageFactory implements OFSerializer<EchoReplyInput
     /**\r
      * @return singleton factory\r
      */\r
-    public static EchoReplyInputMessageFactory getInstance() {\r
+    public static synchronized EchoReplyInputMessageFactory getInstance() {\r
         if (instance == null) {\r
             instance = new EchoReplyInputMessageFactory();\r
         }\r
@@ -34,9 +36,25 @@ public class EchoReplyInputMessageFactory implements OFSerializer<EchoReplyInput
     @Override\r
     public void messageToBuffer(short version, ByteBuf out,\r
             EchoReplyInput message) {\r
-        out.writeByte(message.getVersion());\r
-        out.writeByte(MESSAGE_TYPE);\r
-        out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER);\r
-        out.writeInt(message.getXid().intValue());\r
+        ByteBufUtils.writeOFHeader(instance, message, out);\r
+        byte[] data = message.getData();\r
+        if (data != null) {\r
+            out.writeBytes(data);\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public int computeLength(EchoReplyInput message) {\r
+        int length = MESSAGE_LENGTH;\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