Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyTableFeaturesDeserializer.java
index 32dd0b54bb85470f1c9032c338679398a1f79976..b5b95f21743a603ca36f21968968320f2b535202 100644 (file)
@@ -5,11 +5,13 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart;
 
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint64;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
+
 import io.netty.buffer.ByteBuf;
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
@@ -57,6 +59,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesKey;
+import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -73,30 +76,24 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
     private DeserializerRegistry registry;
 
     @Override
-    public MultipartReplyBody deserialize(ByteBuf message) {
+    public MultipartReplyBody deserialize(final ByteBuf message) {
         final MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder();
         final List<TableFeatures> items = new ArrayList<>();
 
         while (message.readableBytes() > 0) {
             final int itemLength = message.readUnsignedShort();
             final TableFeaturesBuilder itemBuilder = new TableFeaturesBuilder()
-                    .setTableId(message.readUnsignedByte());
+                    .setTableId(readUint8(message));
 
             message.skipBytes(PADDING_IN_MULTIPART_REPLY_TABLE_FEATURES);
 
-            final String name = ByteBufUtils.decodeNullTerminatedString(message, MAX_TABLE_NAME_LENGTH);
-            final byte[] match = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
-            message.readBytes(match);
-            final byte[] write = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
-            message.readBytes(write);
-
             items.add(itemBuilder
-                    .setKey(new TableFeaturesKey(itemBuilder.getTableId()))
-                    .setName(name)
-                    .setMetadataMatch(new BigInteger(1, match))
-                    .setMetadataWrite(new BigInteger(1, write))
+                    .withKey(new TableFeaturesKey(itemBuilder.getTableId()))
+                    .setName(ByteBufUtils.decodeNullTerminatedString(message, MAX_TABLE_NAME_LENGTH))
+                    .setMetadataMatch(readUint64(message))
+                    .setMetadataWrite(readUint64(message))
                     .setConfig(readTableConfig(message))
-                    .setMaxEntries(message.readUnsignedInt())
+                    .setMaxEntries(readUint32(message))
                     .setTableProperties(readTableProperties(message,
                             itemLength - MULTIPART_REPLY_TABLE_FEATURES_STRUCTURE_LENGTH))
                     .build());
@@ -107,14 +104,14 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
                 .build();
     }
 
-    private TableConfig readTableConfig(ByteBuf message) {
+    private static TableConfig readTableConfig(final ByteBuf message) {
         final long input = message.readUnsignedInt();
         final boolean deprecated = (input & 3) != 0;
 
         return new TableConfig(deprecated);
     }
 
-    private TableProperties readTableProperties(ByteBuf message, int length) {
+    private TableProperties readTableProperties(final ByteBuf message, final int length) {
         final List<TableFeatureProperties> items = new ArrayList<>();
         int tableFeaturesLength = length;
         int order = 0;
@@ -127,7 +124,7 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
             final int commonPropertyLength = propertyLength - COMMON_PROPERTY_LENGTH;
             final TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder()
                 .setOrder(order)
-                .setKey(new TableFeaturePropertiesKey(order));
+                .withKey(new TableFeaturePropertiesKey(order));
 
             switch (propType) {
                 case OFPTFPTINSTRUCTIONS:
@@ -278,17 +275,17 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
             .build();
     }
 
-    private List<SetFieldMatch> readMatchFields(ByteBuf message, int length) {
+    private static List<SetFieldMatch> readMatchFields(final ByteBuf message, final int length) {
         final List<SetFieldMatch> matchFields = new ArrayList<>();
 
         final int startIndex = message.readerIndex();
 
-        while ((message.readerIndex() - startIndex) < length) {
+        while (message.readerIndex() - startIndex < length) {
             MATCH_FIELD_DESERIALIZER
                     .deserialize(message)
                     .map(matchFields::add)
                     .orElseGet(() -> {
-                        message.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+                        message.skipBytes(2 * Short.BYTES);
                         return Boolean.FALSE;
                     });
         }
@@ -296,12 +293,12 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
         return matchFields;
     }
 
-    private List<Short> readNextTableIds(ByteBuf message, int length) {
-        final List<Short> tableIds = new ArrayList<>();
+    private static List<Uint8> readNextTableIds(final ByteBuf message, final int length) {
+        final List<Uint8> tableIds = new ArrayList<>();
         int nextTableLength = length;
 
         while (nextTableLength > 0) {
-            tableIds.add(message.readUnsignedByte());
+            tableIds.add(Uint8.valueOf(message.readUnsignedByte()));
             nextTableLength -= 1;
         }
 
@@ -309,17 +306,17 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
     }
 
     private List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list
-            .Instruction> readInstructions(ByteBuf message, int length) {
+            .Instruction> readInstructions(final ByteBuf message, final int length) {
 
         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list
                 .Instruction> instructions = new ArrayList<>();
         final int startIndex = message.readerIndex();
         int offset = 0;
 
-        while ((message.readerIndex() - startIndex) < length) {
+        while (message.readerIndex() - startIndex < length) {
             try {
                 instructions.add(new InstructionBuilder()
-                        .setKey(new InstructionKey(offset))
+                        .withKey(new InstructionKey(offset))
                         .setOrder(offset)
                         .setInstruction(InstructionUtil
                                 .readInstructionHeader(EncodeConstants.OF13_VERSION_ID, message, registry))
@@ -327,7 +324,7 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
 
                 offset++;
             } catch (ClassCastException | IllegalStateException e) {
-                message.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+                message.skipBytes(2 * Short.BYTES);
             }
         }
 
@@ -335,24 +332,23 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
     }
 
     @SuppressWarnings("checkstyle:LineLength")
-    private List<Action> readActions(ByteBuf message, int length) {
+    private List<Action> readActions(final ByteBuf message, final int length) {
         final List<Action> actions = new ArrayList<>();
         final int startIndex = message.readerIndex();
         int offset = 0;
 
-        while ((message.readerIndex() - startIndex) < length) {
+        while (message.readerIndex() - startIndex < length) {
             try {
                 actions.add(new ActionBuilder()
-                        .setKey(new ActionKey(offset))
+                        .withKey(new ActionKey(offset))
                         .setOrder(offset)
                         .setAction(ActionUtil.readActionHeader(EncodeConstants.OF13_VERSION_ID, message, registry,
-                                ActionPath
-                                        .FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION))
+                                ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS))
                         .build());
 
                 offset++;
             } catch (ClassCastException | IllegalStateException e) {
-                message.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+                message.skipBytes(2 * Short.BYTES);
             }
         }
 
@@ -360,7 +356,7 @@ public class MultipartReplyTableFeaturesDeserializer implements OFDeserializer<M
     }
 
     @Override
-    public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
+    public void injectDeserializerRegistry(final DeserializerRegistry deserializerRegistry) {
         registry = deserializerRegistry;
     }