GetAsyncReplyMessageFactory, QueueGetConfigReplyMessageFactoryTest
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / ByteBufUtils.java
index 3f5e360005dccb1699ecd43f15a70909a29e7817..a4fe74588199cf43aabef1a0e2210b6f3affe598 100644 (file)
@@ -5,6 +5,12 @@ package org.opendaylight.openflowjava.protocol.impl.util;
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
+import java.util.Map;\r
+import java.util.Map.Entry;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;\r
+\r
 /** Class for common operations on ByteBuf\r
  *\r
  * @author michal.polkorab\r
@@ -69,4 +75,34 @@ public abstract class ByteBufUtils {
             out.writeByte(0);\r
         }\r
     }\r
+    \r
+    /**\r
+     * Create standard OF header\r
+     * @param factory serialization factory \r
+     * @param message POJO\r
+     * @param out writing buffer\r
+     */\r
+    public static void writeOFHeader(OFSerializer<?> factory, OfHeader message, ByteBuf out) { \r
+        out.writeByte(message.getVersion());\r
+        out.writeByte(factory.getMessageType());\r
+        out.writeShort(factory.computeLength());\r
+        out.writeInt(message.getXid().intValue());\r
+\r
+    }\r
+\r
+    /**\r
+     * Fills the bitmask from boolean map where key is bit position\r
+     * @param booleanMap bit to boolean mapping\r
+     * @return bit mask\r
+     */\r
+    public static int fillBitMaskFromMap(Map<Integer, Boolean> booleanMap) {\r
+        int bitmask = 0;\r
+        \r
+        for (Entry<Integer, Boolean> iterator : booleanMap.entrySet()) {\r
+            if (iterator.getValue() != null && iterator.getValue().booleanValue()) {\r
+                bitmask |= 1 << iterator.getKey();\r
+            }\r
+        }\r
+        return bitmask;\r
+    }\r
 }\r