Update OF header lenght
[openflowjava.git] / openflowjava-util / src / main / java / org / opendaylight / openflowjava / util / ByteBufUtils.java
index 66c4272ef9ee4a2d4089eacd34a7f3fb85c83709..5d6869cfb961e072dab713fdd05d7f971f7d12d3 100644 (file)
@@ -15,10 +15,8 @@ import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;
-
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.ObjectOutputStream;
+import java.nio.ByteBuffer;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -138,6 +136,15 @@ public abstract class ByteBufUtils {
         out.setShort(EncodeConstants.OFHEADER_LENGTH_INDEX, out.readableBytes());
     }
 
+    /**
+     * Write length OF header
+     * @param out writing buffer
+     * @param index writing index
+     */
+    public static void updateOFHeaderLength(final ByteBuf out, int index) {
+        out.setShort(index + EncodeConstants.OFHEADER_LENGTH_INDEX, out.writerIndex() - index);
+    }
+
     /**
      * Fills the bitmask from boolean map where key is bit position
      * @param booleanMap bit to boolean mapping
@@ -371,10 +378,11 @@ public abstract class ByteBufUtils {
         return IetfYangUtil.INSTANCE.macAddressFor(tmp);
     }
     
-    public static byte[] serializableList(final List<Short> list) throws IOException{
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
-        objectOutputStream.writeObject(list);
-        return byteArrayOutputStream.toByteArray();
+    public static byte[] serializeList(final List<Short> list) throws IOException{
+        ByteBuffer byteBuffer = ByteBuffer.allocate(list.size() * 2);
+        for (Short aShort : list) {
+            byteBuffer.putShort(aShort);
+        }
+        return byteBuffer.array();
     }
 }