Quickfix - Hello versionBitmap
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / ByteBufUtils.java
index 975f49ad888940beb8c34de6b151ac58bfaa5d81..196e44d39edd23ed083e32d3da6465cc6fc09ad3 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */\r
 public abstract class ByteBufUtils {\r
 \r
+\r
     /**\r
      * Converts ByteBuf into String\r
      * @param bb input ByteBuf\r
@@ -98,10 +99,10 @@ public abstract class ByteBufUtils {
      * @param message POJO\r
      * @param out writing buffer\r
      */\r
-    public static void writeOFHeader(OFSerializer<?> factory, OfHeader message, ByteBuf out) { \r
+    public static <E extends OfHeader> void writeOFHeader(OFSerializer<E> factory, E message, ByteBuf out) { \r
         out.writeByte(message.getVersion());\r
         out.writeByte(factory.getMessageType());\r
-        out.writeShort(factory.computeLength());\r
+        out.writeShort(factory.computeLength(message));\r
         out.writeInt(message.getXid().intValue());\r
 \r
     }\r
@@ -128,17 +129,20 @@ public abstract class ByteBufUtils {
      * @return bit mask\r
      */\r
     public static int[] fillBitMaskFromList(List<Boolean> booleanList) {\r
-        final int intLength = 32;\r
-        int[] bitmask = new int[booleanList.size()];\r
+        int[] bitmask;\r
         int index = 0;\r
         int arrayIndex = 0;\r
-        \r
+        if ((booleanList.size() % Integer.SIZE) != 0) {\r
+            bitmask = new int[booleanList.size() / Integer.SIZE + 1];\r
+        } else {\r
+            bitmask = new int[booleanList.size() / Integer.SIZE];\r
+        }\r
         for (Boolean currElement : booleanList) {\r
             if (currElement != null && currElement.booleanValue()) {\r
                 bitmask[arrayIndex] |= 1 << index;\r
             }\r
             index++;\r
-            arrayIndex = index/intLength;\r
+            arrayIndex = index / Integer.SIZE;\r
         }\r
         return bitmask;\r
     }\r