Factory tests back to stable
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / MatchDeserializer.java
index 4567a7b31da810ae907ca79b76272d7218abba58..dba41160c0726bc404737574661e8328f987d59d 100644 (file)
@@ -130,8 +130,7 @@ public abstract class MatchDeserializer {
     private static final byte SIZE_OF_SHORT_IN_BYTES = Short.SIZE / Byte.SIZE;\r
     private static final byte SIZE_OF_BYTE_IN_BYTES = Byte.SIZE / Byte.SIZE;\r
     private static final byte SIZE_OF_IPV6_ADDRESS_IN_BYTES = (8 * Short.SIZE) / Byte.SIZE;\r
-    private static List<MatchEntries> matchEntriesList = new ArrayList<>();\r
-    private static MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); \r
+    \r
     \r
     /**\r
      * Creates match\r
@@ -143,7 +142,6 @@ public abstract class MatchDeserializer {
             MatchBuilder builder = new MatchBuilder();\r
             int type = in.readUnsignedShort();\r
             int length = in.readUnsignedShort();\r
-            LOGGER.debug("length: " + length);\r
             switch (type) {\r
             case 0:\r
                 builder.setType(StandardMatchType.class);\r
@@ -164,14 +162,29 @@ public abstract class MatchDeserializer {
         return null;\r
     }\r
     \r
+    /**\r
+     * @param in input ByteBuf\r
+     * @param matchLength to infer size of array\r
+     * @return MatchEntriesList\r
+     */\r
+    public static List<MatchEntries> createMatchEntry(ByteBuf in, int matchLength) {\r
+        return createMatchEntriesInternal(in, matchLength, true);\r
+    }\r
+    \r
     /**\r
      * @param in input ByteBuf\r
      * @param matchLength to infer size of array\r
      * @return MatchEntriesList\r
      */\r
     public static List<MatchEntries> createMatchEntries(ByteBuf in, int matchLength) {\r
+        return createMatchEntriesInternal(in, matchLength, false);\r
+    }\r
+    \r
+    private static List<MatchEntries> createMatchEntriesInternal(ByteBuf in, int matchLength, boolean oneEntry) {\r
+        List<MatchEntries> matchEntriesList = new ArrayList<>();\r
         int currLength = 0;\r
         while(currLength < matchLength) {\r
+            MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); \r
             switch (in.readUnsignedShort()) { \r
             case 0x0000:\r
                         matchEntriesBuilder.setOxmClass(Nxm0Class.class);\r
@@ -476,6 +489,12 @@ public abstract class MatchDeserializer {
                 break;\r
             }\r
           matchEntriesList.add(matchEntriesBuilder.build());\r
+          if (oneEntry) {\r
+              break;\r
+          }\r
+        }\r
+        if ((matchLength - currLength) > 0) {\r
+            in.skipBytes(matchLength - currLength);\r
         }\r
         return matchEntriesList;\r
     }\r