Clean up version setters
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10FlowModInputMessageFactory.java
index e7eaf6ea2de70b5017e26038dfd40fa2309ae699..68208323d8cd40f1d5abc3e328e26a1970a25a45 100644 (file)
@@ -7,9 +7,14 @@
  */
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint64;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import io.netty.buffer.ByteBuf;
-import java.math.BigInteger;
 import java.util.List;
+import java.util.Objects;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
@@ -41,22 +46,23 @@ public class OF10FlowModInputMessageFactory implements OFDeserializer<FlowModInp
     }
 
     @Override
+    @SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") // FB doesn't recognize Objects.requireNonNull
     public FlowModInput deserialize(ByteBuf rawMessage) {
-        FlowModInputBuilder builder = new FlowModInputBuilder();
-        builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
-        builder.setXid(rawMessage.readUnsignedInt());
+        Objects.requireNonNull(registry);
+
+        FlowModInputBuilder builder = new FlowModInputBuilder()
+                .setVersion(EncodeConstants.OF_VERSION_1_0)
+                .setXid(readUint32(rawMessage));
         OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(
                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
         builder.setMatchV10(matchDeserializer.deserialize(rawMessage));
-        byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
-        rawMessage.readBytes(cookie);
-        builder.setCookie(new BigInteger(1, cookie));
+        builder.setCookie(readUint64(rawMessage));
         builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedShort()));
-        builder.setIdleTimeout(rawMessage.readUnsignedShort());
-        builder.setHardTimeout(rawMessage.readUnsignedShort());
-        builder.setPriority(rawMessage.readUnsignedShort());
-        builder.setBufferId(rawMessage.readUnsignedInt());
-        builder.setOutPort(new PortNumber((long) rawMessage.readUnsignedShort()));
+        builder.setIdleTimeout(readUint16(rawMessage));
+        builder.setHardTimeout(readUint16(rawMessage));
+        builder.setPriority(readUint16(rawMessage));
+        builder.setBufferId(readUint32(rawMessage));
+        builder.setOutPort(new PortNumber(readUint16(rawMessage).toUint32()));
         builder.setFlagsV10(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort()));
         CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
 
@@ -68,10 +74,9 @@ public class OF10FlowModInputMessageFactory implements OFDeserializer<FlowModInp
 
     @SuppressWarnings("checkstyle:AbbreviationAsWordInName")
     private static FlowModFlagsV10 createFlowModFlagsFromBitmap(int input) {
-        final Boolean _oFPFFSENDFLOWREM = (input & 1 << 0) > 0;
-        final Boolean _oFPFFCHECKOVERLAP = (input & 1 << 1) > 0;
-        final Boolean _oFPFFEMERG = (input & 1 << 2) > 0;
+        final Boolean _oFPFFSENDFLOWREM = (input & 1 << 0) != 0;
+        final Boolean _oFPFFCHECKOVERLAP = (input & 1 << 1) != 0;
+        final Boolean _oFPFFEMERG = (input & 1 << 2) != 0;
         return new FlowModFlagsV10(_oFPFFCHECKOVERLAP, _oFPFFEMERG, _oFPFFSENDFLOWREM);
     }
-
 }