Extensibility support (serialization part)
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / TableModInputMessageFactory.java
index 9c4e3b24f984c259822819fd9e8c34f3632e60f3..c9fb2b67cab64707f09e94fcc36f0e9f79a5c9ab 100644 (file)
@@ -13,8 +13,9 @@ import io.netty.buffer.ByteBuf;
 import java.util.HashMap;
 import java.util.Map;
 
-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.common.types.rev130731.TableConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
 
@@ -26,41 +27,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class TableModInputMessageFactory implements OFSerializer<TableModInput> {
     private static final byte MESSAGE_TYPE = 17;
     private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3;
-    private static final int MESSAGE_LENGTH = 16;
-    private static TableModInputMessageFactory instance;
-    
-    private TableModInputMessageFactory() {
-        // just singleton
-    }
-    
-    /**
-     * @return singleton factory
-     */
-    public static synchronized TableModInputMessageFactory getInstance() {
-        if(instance == null){
-            instance = new TableModInputMessageFactory();
-        }
-        return instance;
-    }
-    
-    @Override
-    public void messageToBuffer(short version, ByteBuf out, TableModInput message) {
-        ByteBufUtils.writeOFHeader(instance, message, out);
-        out.writeByte(message.getTableId().getValue().byteValue());
-        ByteBufUtils.padBuffer(PADDING_IN_TABLE_MOD_MESSAGE, out);
-        out.writeInt(createConfigBitmask(message.getConfig()));
-    }
 
     @Override
-    public int computeLength(TableModInput message) {
-        return MESSAGE_LENGTH;
+    public void serialize(TableModInput message, ByteBuf outBuffer) {
+        ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
+        outBuffer.writeByte(message.getTableId().getValue().byteValue());
+        ByteBufUtils.padBuffer(PADDING_IN_TABLE_MOD_MESSAGE, outBuffer);
+        outBuffer.writeInt(createConfigBitmask(message.getConfig()));
+        ByteBufUtils.updateOFHeaderLength(outBuffer);
     }
 
-    @Override
-    public byte getMessageType() {
-        return MESSAGE_TYPE;
-    }
-    
     /**
      * @param tableConfig
      * @return port config bitmask 
@@ -71,4 +47,5 @@ public class TableModInputMessageFactory implements OFSerializer<TableModInput>
         int configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap);
         return configBitmask;
     }
+
 }