Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / ErrorMessageFactory.java
index 3069ea369e73cdefab3098080bf4dd2f7faf88dc..1196e416a386981d69871ea73922485e164e9eb2 100644 (file)
@@ -5,9 +5,10 @@
  * 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 static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
+
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import io.netty.buffer.ByteBuf;
 import java.util.Objects;
@@ -53,16 +54,16 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
         Objects.requireNonNull(registry);
 
         int startIndex = rawMessage.readerIndex();
-        ErrorMessageBuilder builder = new ErrorMessageBuilder();
-        builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
-        builder.setXid(rawMessage.readUnsignedInt());
+        ErrorMessageBuilder builder = new ErrorMessageBuilder()
+                .setVersion(EncodeConstants.OF_VERSION_1_3)
+                .setXid(readUint32(rawMessage));
         int type = rawMessage.readUnsignedShort();
         ErrorType errorType = ErrorType.forValue(type);
         if (ErrorType.EXPERIMENTER.equals(errorType)) {
             OFDeserializer<ErrorMessage> deserializer = registry.getDeserializer(
                     ExperimenterDeserializerKeyFactory.createExperimenterErrorDeserializerKey(
                             EncodeConstants.OF13_VERSION_ID, rawMessage.getUnsignedInt(
-                                    rawMessage.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES)));
+                                    rawMessage.readerIndex() + Short.BYTES)));
             rawMessage.readerIndex(startIndex);
             return deserializer.deserialize(rawMessage);
         }
@@ -92,8 +93,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
         int code = rawMessage.readUnsignedShort();
         if (type != null) {
             switch (type) {
-                case HELLOFAILED:
-                {
+                case HELLOFAILED: {
                     HelloFailedCode errorCode = HelloFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -102,8 +102,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case BADREQUEST:
-                {
+                case BADREQUEST: {
                     BadRequestCode errorCode = BadRequestCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -112,8 +111,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case BADACTION:
-                {
+                case BADACTION: {
                     BadActionCode errorCode = BadActionCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -122,8 +120,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case BADINSTRUCTION:
-                {
+                case BADINSTRUCTION: {
                     BadInstructionCode errorCode = BadInstructionCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -132,8 +129,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case BADMATCH:
-                {
+                case BADMATCH: {
                     BadMatchCode errorCode = BadMatchCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -142,8 +138,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case FLOWMODFAILED:
-                {
+                case FLOWMODFAILED: {
                     FlowModFailedCode errorCode = FlowModFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -152,8 +147,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case GROUPMODFAILED:
-                {
+                case GROUPMODFAILED: {
                     GroupModFailedCode errorCode = GroupModFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -162,8 +156,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case PORTMODFAILED:
-                {
+                case PORTMODFAILED: {
                     PortModFailedCode errorCode = PortModFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -172,8 +165,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case TABLEMODFAILED:
-                {
+                case TABLEMODFAILED: {
                     TableModFailedCode errorCode = TableModFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -182,8 +174,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case QUEUEOPFAILED:
-                {
+                case QUEUEOPFAILED: {
                     QueueOpFailedCode errorCode = QueueOpFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -192,8 +183,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case SWITCHCONFIGFAILED:
-                {
+                case SWITCHCONFIGFAILED: {
                     SwitchConfigFailedCode errorCode = SwitchConfigFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -202,8 +192,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case ROLEREQUESTFAILED:
-                {
+                case ROLEREQUESTFAILED: {
                     RoleRequestFailedCode errorCode = RoleRequestFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -212,8 +201,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case METERMODFAILED:
-                {
+                case METERMODFAILED: {
                     MeterModFailedCode errorCode = MeterModFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());
@@ -222,8 +210,7 @@ public class ErrorMessageFactory implements OFDeserializer<ErrorMessage>,
                     }
                     break;
                 }
-                case TABLEFEATURESFAILED:
-                {
+                case TABLEFEATURESFAILED: {
                     TableFeaturesFailedCode errorCode = TableFeaturesFailedCode.forValue(code);
                     if (errorCode != null) {
                         setCode(builder, errorCode.getIntValue(), errorCode.name());