Fixed netty & checkstyle failures
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / EchoReplyMessageFactory.java
index 3b5fcc6c8a85c38bd1451a58273a414c4aa73a1f..5d3ecde73db018484c644e5c02a61d6786f9f905 100644 (file)
@@ -1,45 +1,39 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class EchoReplyMessageFactory implements OFDeserializer<EchoOutput> {\r
-\r
-    private static EchoReplyMessageFactory instance;\r
-\r
-    private EchoReplyMessageFactory() {\r
-        // do nothing, just singleton\r
-    }\r
-    \r
-    /**\r
-     * @return singleton factory\r
-     */\r
-    public static EchoReplyMessageFactory getInstance() {\r
-        if (instance == null) {\r
-            instance = new EchoReplyMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-    \r
-    /* (non-Javadoc)\r
-     * @see org.openflow.core.deserialization.OfDeserializer#createMessage(io.netty.buffer.ByteBuf, short)\r
-     */\r
-    @Override\r
-    public EchoOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
-        EchoOutputBuilder eob = new EchoOutputBuilder();\r
-        eob.setVersion(version);\r
-        eob.setXid(rawMessage.readUnsignedInt());\r
-        // read the rest of EchoReply message\r
-        eob.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
-        return eob.build();\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.deserialization.factories;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder;
+
+/**
+ * Translates EchoReply messages (both OpenFlow v1.0 and OpenFlow v1.3)
+ * @author michal.polkorab
+ * @author timotej.kubas
+ */
+public class EchoReplyMessageFactory implements OFDeserializer<EchoOutput> {
+
+    @Override
+    public EchoOutput deserialize(ByteBuf rawMessage) {
+        EchoOutputBuilder builder = new EchoOutputBuilder();
+        builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
+        builder.setXid(rawMessage.readUnsignedInt());
+        int remainingBytes = rawMessage.readableBytes();
+        if (remainingBytes > 0) {
+            byte[] data = new byte[remainingBytes];
+            rawMessage.readBytes(data);
+            builder.setData(data);
+        }
+        return builder.build();
+    }
+
+}