*/\r
public abstract class ByteBufUtils {\r
\r
+\r
/**\r
* Converts ByteBuf into String\r
* @param bb input ByteBuf\r
* @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
* @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