Fixup ProtectionCommonParser.serializeBody() 64/84464/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 14 Sep 2019 23:21:27 +0000 (01:21 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 14 Sep 2019 23:22:53 +0000 (01:22 +0200)
This method cannot really tolerate a nullable Short, make it
operate on a primitive short, adjusting callers and improving
efficiency.

Change-Id: Ic1cbfa9fe8f5854fd72cae1c12c864d4bcdb4460
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/SEROBasicProtectionSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/ero/SERODynamicProtectionSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/SRROBasicProtectionSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/SRRODynamicProtectionSubobjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/ProtectionCommonParser.java

index d7c7a13232da112cc103074109c88ed89cc13786..06314ea4cd1fec8fd00fca3a4d47dae2f666a906 100644 (file)
@@ -5,7 +5,6 @@
  * 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.protocol.rsvp.parser.impl.subobject.ero;
 
 import com.google.common.base.Preconditions;
@@ -25,10 +24,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.subobjects.subobject.type.basic.protection._case.BasicProtectionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.subobjects.subobject.type.dynamic.control.protection._case.DynamicControlProtectionBuilder;
 
-public class SEROBasicProtectionSubobjectParser extends ProtectionCommonParser implements EROSubobjectParser,
-    EROSubobjectSerializer {
+public class SEROBasicProtectionSubobjectParser extends ProtectionCommonParser
+        implements EROSubobjectParser, EROSubobjectSerializer {
     public static final int TYPE = 37;
-    public static final Short CTYPE = 1;
+    public static final short CTYPE = 1;
 
     @Override
     public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
index 4bbbcdbe302d7939f0382281774daf8115e3567b..2a25bf88d10ec9281800affc66cb99d5a41b547f 100644 (file)
@@ -5,7 +5,6 @@
  * 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.protocol.rsvp.parser.impl.subobject.ero;
 
 import com.google.common.base.Preconditions;
@@ -22,9 +21,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
  * Parser for {@link DynamicControlProtectionCase}.
  */
 public class SERODynamicProtectionSubobjectParser extends ProtectionCommonParser implements EROSubobjectSerializer {
-
     public static final int TYPE = 37;
-    public static final Short CTYPE = 2;
+    public static final short CTYPE = 2;
 
     @Override
     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
@@ -37,5 +35,4 @@ public class SERODynamicProtectionSubobjectParser extends ProtectionCommonParser
         serializeBody(CTYPE, protObj, body);
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
     }
-
 }
\ No newline at end of file
index cfce282be21df3594566f949c505117907126fb0..043b17f90fff2af3ebe0ed577d388540048f71f8 100644 (file)
@@ -5,7 +5,6 @@
  * 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.protocol.rsvp.parser.impl.subobject.rro;
 
 import com.google.common.base.Preconditions;
@@ -27,11 +26,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 /**
  * Parser for {@link BasicProtectionCase}.
  */
-public class SRROBasicProtectionSubobjectParser extends ProtectionCommonParser implements RROSubobjectParser,
-    RROSubobjectSerializer {
-
+public class SRROBasicProtectionSubobjectParser extends ProtectionCommonParser
+        implements RROSubobjectParser, RROSubobjectSerializer {
     public static final int TYPE = 37;
-    public static final Short CTYPE = 1;
+    public static final short CTYPE = 1;
 
     @Override
     public SubobjectContainer parseSubobject(final ByteBuf buffer) throws RSVPParsingException {
index 9e538c44d6212d366417db3f2ab6ee37ce5b0f83..6824f4ed4df745c80b31ccf5e8e3de1b56b84e8e 100644 (file)
@@ -5,7 +5,6 @@
  * 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.protocol.rsvp.parser.impl.subobject.rro;
 
 import com.google.common.base.Preconditions;
@@ -19,7 +18,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 
 public class SRRODynamicProtectionSubobjectParser extends ProtectionCommonParser implements RROSubobjectSerializer {
     public static final int TYPE = 37;
-    public static final Short CTYPE = 2;
+    public static final short CTYPE = 2;
 
     @Override
     public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
index eda540598057b44a56340b103b9dba694b3ed954..1b115fc0fe52588860cbbd44d220747242af2ada 100644 (file)
@@ -5,11 +5,8 @@
  * 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.protocol.rsvp.parser.impl.te;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
 import org.opendaylight.protocol.util.BitArray;
@@ -107,10 +104,10 @@ public class ProtectionCommonParser {
         return sub.build();
     }
 
-    protected static void serializeBody(final Short ctype, final ProtectionSubobject protObj,
+    protected static void serializeBody(final short ctype, final ProtectionSubobject protObj,
         final ByteBuf output) {
         output.writeZero(BYTE_SIZE);
-        writeUnsignedByte(ctype, output);
+        output.writeByte(ctype);
         switch (ctype) {
             case PROTECTION_SUBOBJECT_TYPE_1:
                 serializeBodyType1(protObj, output);
@@ -125,19 +122,15 @@ public class ProtectionCommonParser {
     }
 
     protected static ProtectionSubobject parseCommonProtectionBody(final short ctype, final ByteBuf byteBuf)
-        throws RSVPParsingException {
-        ProtectionSubobject protectionSubobject = null;
+            throws RSVPParsingException {
         switch (ctype) {
             case PROTECTION_SUBOBJECT_TYPE_1:
-                protectionSubobject = parseCommonProtectionBodyType1(byteBuf);
-                break;
+                return parseCommonProtectionBodyType1(byteBuf);
             case PROTECTION_SUBOBJECT_TYPE_2:
-                protectionSubobject = parseCommonProtectionBodyType2(byteBuf);
-                break;
+                return parseCommonProtectionBodyType2(byteBuf);
             default:
                 LOG.warn("Secondary Record Route Protection Subobject cType {} not supported", ctype);
-                break;
+                return null;
         }
-        return protectionSubobject;
     }
 }