Extensibility support (serialization part)
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / EchoReplyInputMessageFactory.java
index 3b3e188ebcbff597a1d233d013159ba325138792..5273a7b9aa643f598dda77a4c1706c5c6f09f753 100644 (file)
@@ -1,42 +1,38 @@
-/* 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.core.OFFrameDecoder;\r
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\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 EchoReplyInputMessageFactory instance;\r
-    \r
-    private EchoReplyInputMessageFactory() {\r
-        // do nothing, just singleton\r
-    }\r
-    \r
-    /**\r
-     * @return singleton factory\r
-     */\r
-    public static EchoReplyInputMessageFactory getInstance() {\r
-        if (instance == null) {\r
-            instance = new EchoReplyInputMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-\r
-    @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
-    }\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.impl.util.ByteBufUtils;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
+
+/**
+ * Translates EchoReply messages (both OpenFlow v1.0 and OpenFlow v1.3)
+ * @author michal.polkorab
+ * @author timotej.kubas
+ */
+public class EchoReplyInputMessageFactory implements OFSerializer<EchoReplyInput>{
+
+    /** Code type of EchoReply message */
+    private static final byte MESSAGE_TYPE = 3;
+
+    @Override
+    public void serialize(EchoReplyInput message, ByteBuf outBuffer) {
+        ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.OFHEADER_SIZE);
+        byte[] data = message.getData();
+        if (data != null) {
+            outBuffer.writeBytes(data);
+            ByteBufUtils.updateOFHeaderLength(outBuffer);
+        }
+    }
+
+}