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
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