Migrate uint/ByteBuf interactions
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / FeaturesReplyMessageFactory.java
index b599c208dfb0c21db5d471d059dfd504ebac6abd..a91b0e449df31b68dcb39e0d06ba258ee0e542ca 100644 (file)
@@ -5,13 +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.openflowjava.protocol.impl.deserialization.factories;
 
-import io.netty.buffer.ByteBuf;
-
-import java.math.BigInteger;
+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 org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
@@ -19,11 +19,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
 
 /**
- * Translates FeaturesReply messages
+ * Translates FeaturesReply messages.
+ *
  * @author michal.polkorab
  * @author timotej.kubas
  */
-public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOutput>{
+public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOutput> {
 
     private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2;
 
@@ -31,27 +32,25 @@ public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOu
     public GetFeaturesOutput deserialize(ByteBuf rawMessage) {
         GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
         builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
-        builder.setXid(rawMessage.readUnsignedInt());
-        byte[] datapathId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
-        rawMessage.readBytes(datapathId);
-        builder.setDatapathId(new BigInteger(1, datapathId));
-        builder.setBuffers(rawMessage.readUnsignedInt());
-        builder.setTables(rawMessage.readUnsignedByte());
-        builder.setAuxiliaryId(rawMessage.readUnsignedByte());
+        builder.setXid(readUint32(rawMessage));
+        builder.setDatapathId(readUint64(rawMessage));
+        builder.setBuffers(readUint32(rawMessage));
+        builder.setTables(readUint8(rawMessage));
+        builder.setAuxiliaryId(readUint8(rawMessage));
         rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);
         builder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt()));
-        builder.setReserved(rawMessage.readUnsignedInt());
+        builder.setReserved(readUint32(rawMessage));
         return builder.build();
     }
 
     private static Capabilities createCapabilities(long input) {
-        final Boolean flowStats = (input & (1 << 0)) != 0;
-        final Boolean tableStats = (input & (1 << 1)) != 0;
-        final Boolean portStats = (input & (1 << 2)) != 0;
-        final Boolean groupStats = (input & (1 << 3)) != 0;
-        final Boolean ipReasm = (input & (1 << 5)) != 0;
-        final Boolean queueStats = (input & (1 << 6)) != 0;
-        final Boolean portBlocked = (input & (1 << 8)) != 0;
+        final Boolean flowStats = (input & 1 << 0) != 0;
+        final Boolean tableStats = (input & 1 << 1) != 0;
+        final Boolean portStats = (input & 1 << 2) != 0;
+        final Boolean groupStats = (input & 1 << 3) != 0;
+        final Boolean ipReasm = (input & 1 << 5) != 0;
+        final Boolean queueStats = (input & 1 << 6) != 0;
+        final Boolean portBlocked = (input & 1 << 8) != 0;
         return new Capabilities(flowStats, groupStats, ipReasm,
                 portBlocked, portStats, queueStats, tableStats);
     }