Extensibility support (serialization part)
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / EchoInputMessageFactory.java
index 9e1cfa5b95fca06918ad9feef7b6d9e60bedfcf2..06ba06206abd59e10bf67f341cd79dd1e066322b 100644 (file)
@@ -10,8 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 
 import io.netty.buffer.ByteBuf;
 
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+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.EchoInput;
 
 /**
@@ -22,46 +23,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class EchoInputMessageFactory implements OFSerializer<EchoInput> {
 
     /** Code type of EchoRequest message */
-    public static final byte MESSAGE_TYPE = 2;
-    private static EchoInputMessageFactory instance;
-    private static final int MESSAGE_LENGTH = 8;
-    
-    private EchoInputMessageFactory() {
-        // do nothing, just singleton
-    }
-    
-    /**
-     * @return singleton factory
-     */
-    public static synchronized EchoInputMessageFactory getInstance() {
-        if (instance == null) {
-            instance = new EchoInputMessageFactory();
-        }
-        return instance;
-    }
+    private static final byte MESSAGE_TYPE = 2;
 
     @Override
-    public void messageToBuffer(short version, ByteBuf out, EchoInput message) {
-        ByteBufUtils.writeOFHeader(instance, message, out);
+    public void serialize(EchoInput message, ByteBuf outBuffer) {
+        ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
         byte[] data = message.getData();
         if (data != null) {
-            out.writeBytes(data);
+            outBuffer.writeBytes(data);
         }
+        ByteBufUtils.updateOFHeaderLength(outBuffer);
     }
 
-    @Override
-    public int computeLength(EchoInput message) {
-        int length = MESSAGE_LENGTH;
-        byte[] data = message.getData();
-        if (data != null) {
-            length += data.length;
-        }
-        return length;
-    }
-
-    @Override
-    public byte getMessageType() {
-        return MESSAGE_TYPE;
-    }
-    
 }