Eliimnate use to Uint8.toJava() in rsvp-impl 68/96968/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Jul 2021 08:10:40 +0000 (10:10 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 21 Jul 2021 10:27:45 +0000 (10:27 +0000)
We have ByteBufUtils.writeUint8(), which is a tad simpler, use that
instead of dual conversion.

Change-Id: Ibd58934382e9244a0428c68722ef59611801f94b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/AbstractAssociationParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/FastRerouteObjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/InformationalFastRerouteObjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/MetricObjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspObjectParser.java
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/te/SessionAttributeLspRaObjectParser.java

index 0abf314924cec29b0813527f5c32fe8d41c3286d..bf74ea312b3df8eb00793be769da9adfac0558ec 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.protocol.rsvp.parser.impl.te;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.writeUint16;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
@@ -19,7 +21,6 @@ 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.RsvpTeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.association.object.AssociationObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.association.object.AssociationObjectBuilder;
-import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public abstract class AbstractAssociationParser extends AbstractRSVPObjectParser {
     public static final short CLASS_NUM = 199;
@@ -35,17 +36,17 @@ public abstract class AbstractAssociationParser extends AbstractRSVPObjectParser
     protected final void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
         checkArgument(teLspObject instanceof AssociationObject, "AssociationObject is mandatory.");
         final AssociationObject assObject = (AssociationObject) teLspObject;
-
-        if (assObject.getIpAddress().getIpv4AddressNoZone() != null) {
+        final IpAddressNoZone ipAddress = assObject.getIpAddress();
+        if (ipAddress.getIpv4AddressNoZone() != null) {
             serializeAttributeHeader(BODY_SIZE_IPV4, CLASS_NUM, CTYPE_IPV4, output);
             output.writeShort(assObject.getAssociationType().getIntValue());
-            output.writeShort(assObject.getAssociationId().toJava());
-            output.writeBytes(Ipv4Util.byteBufForAddress(assObject.getIpAddress().getIpv4AddressNoZone()));
+            writeUint16(output, assObject.getAssociationId());
+            output.writeBytes(Ipv4Util.byteBufForAddress(ipAddress.getIpv4AddressNoZone()));
         } else {
             serializeAttributeHeader(BODY_SIZE_IPV6, CLASS_NUM, CTYPE_IPV6, output);
             output.writeShort(assObject.getAssociationType().getIntValue());
-            output.writeShort(assObject.getAssociationId().toJava());
-            output.writeBytes(Ipv6Util.byteBufForAddress(assObject.getIpAddress().getIpv6AddressNoZone()));
+            writeUint16(output, assObject.getAssociationId());
+            output.writeBytes(Ipv6Util.byteBufForAddress(ipAddress.getIpv6AddressNoZone()));
         }
     }
 
@@ -53,7 +54,7 @@ public abstract class AbstractAssociationParser extends AbstractRSVPObjectParser
     protected final RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
         return new AssociationObjectBuilder()
                 .setAssociationType(AssociationType.forValue(byteBuf.readUnsignedShort()))
-                .setAssociationId(ByteBufUtils.readUint16(byteBuf))
+                .setAssociationId(readUint16(byteBuf))
                 .setIpAddress(parseAssociationIpAddress(byteBuf))
                 .build();
     }
index 788c59454ffa773f8ce05bab9f0440e2599ca6e5..4a2a4f915e163b32d2bf74d962c9e14137e4d274 100644 (file)
@@ -7,6 +7,10 @@
  */
 package org.opendaylight.protocol.rsvp.parser.impl.te;
 
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.writeUint8;
+
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -18,7 +22,6 @@ 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.RsvpTeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.fast.reroute.object.fast.reroute.object.basic.fast.reroute.object._case.BasicFastRerouteObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.fast.reroute.object.fast.reroute.object.basic.fast.reroute.object._case.BasicFastRerouteObjectBuilder;
-import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public final class FastRerouteObjectParser extends AbstractRSVPObjectParser {
     public static final short CLASS_NUM = 205;
@@ -28,17 +31,17 @@ public final class FastRerouteObjectParser extends AbstractRSVPObjectParser {
     @Override
     protected RsvpTeObject localParseObject(final ByteBuf byteBuf) {
         final BasicFastRerouteObjectBuilder builder = new BasicFastRerouteObjectBuilder()
-                .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
-                .setHoldPriority(ByteBufUtils.readUint8(byteBuf))
-                .setHopLimit(ByteBufUtils.readUint8(byteBuf))
+                .setSetupPriority(readUint8(byteBuf))
+                .setHoldPriority(readUint8(byteBuf))
+                .setHopLimit(readUint8(byteBuf))
                 .setFlags(FastRerouteFlags.forValue(byteBuf.readUnsignedByte()));
         final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
 
         return builder
                 .setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)))
-                .setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
-                .setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
-                .setIncludeAll(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
+                .setIncludeAny(new AttributeFilter(readUint32(byteBuf)))
+                .setExcludeAny(new AttributeFilter(readUint32(byteBuf)))
+                .setIncludeAll(new AttributeFilter(readUint32(byteBuf)))
                 .build();
     }
 
@@ -48,9 +51,9 @@ public final class FastRerouteObjectParser extends AbstractRSVPObjectParser {
         final BasicFastRerouteObject fastRerouteObject = (BasicFastRerouteObject) teLspObject;
 
         serializeAttributeHeader(BODY_SIZE_C1, CLASS_NUM, CTYPE, byteAggregator);
-        byteAggregator.writeByte(fastRerouteObject.getSetupPriority().toJava());
-        byteAggregator.writeByte(fastRerouteObject.getHoldPriority().toJava());
-        byteAggregator.writeByte(fastRerouteObject.getHopLimit().toJava());
+        writeUint8(byteAggregator, fastRerouteObject.getSetupPriority());
+        writeUint8(byteAggregator, fastRerouteObject.getHoldPriority());
+        writeUint8(byteAggregator, fastRerouteObject.getHopLimit());
         byteAggregator.writeByte(fastRerouteObject.getFlags().getIntValue());
         byteAggregator.writeBytes(Unpooled.wrappedBuffer(fastRerouteObject.getBandwidth().getValue()));
         writeAttributeFilter(fastRerouteObject.getIncludeAny(), byteAggregator);
index a8583a5796eb4a3cd86483ce9142b4c30983617c..3520069149271368d1681f87cad9376f9c9f1b5f 100644 (file)
@@ -8,6 +8,9 @@
 package org.opendaylight.protocol.rsvp.parser.impl.te;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.writeUint8;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -19,7 +22,6 @@ 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.RsvpTeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.fast.reroute.object.fast.reroute.object.legacy.fast.reroute.object._case.LegacyFastRerouteObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.fast.reroute.object.fast.reroute.object.legacy.fast.reroute.object._case.LegacyFastRerouteObjectBuilder;
-import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public final class InformationalFastRerouteObjectParser extends AbstractRSVPObjectParser {
     public static final short CLASS_NUM = 205;
@@ -30,16 +32,16 @@ public final class InformationalFastRerouteObjectParser extends AbstractRSVPObje
     @Override
     protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
         final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder()
-                .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
-                .setHoldPriority(ByteBufUtils.readUint8(byteBuf))
-                .setHopLimit(ByteBufUtils.readUint8(byteBuf));
+                .setSetupPriority(readUint8(byteBuf))
+                .setHoldPriority(readUint8(byteBuf))
+                .setHopLimit(readUint8(byteBuf));
 
         //skip reserved
         byteBuf.skipBytes(Byte.BYTES);
         final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
         builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
-        builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
-        builder.setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
+        builder.setIncludeAny(new AttributeFilter(readUint32(byteBuf)));
+        builder.setExcludeAny(new AttributeFilter(readUint32(byteBuf)));
         return builder.build();
     }
 
@@ -49,9 +51,9 @@ public final class InformationalFastRerouteObjectParser extends AbstractRSVPObje
         final LegacyFastRerouteObject fastRerouteObject = (LegacyFastRerouteObject) teLspObject;
         serializeAttributeHeader(BODY_SIZE_C7, CLASS_NUM, CTYPE, byteAggregator);
 
-        byteAggregator.writeByte(fastRerouteObject.getSetupPriority().toJava());
-        byteAggregator.writeByte(fastRerouteObject.getHoldPriority().toJava());
-        byteAggregator.writeByte(fastRerouteObject.getHopLimit().toJava());
+        writeUint8(byteAggregator, fastRerouteObject.getSetupPriority());
+        writeUint8(byteAggregator, fastRerouteObject.getHoldPriority());
+        writeUint8(byteAggregator, fastRerouteObject.getHopLimit());
         byteAggregator.writeByte(0);
         byteAggregator.writeBytes(Unpooled.wrappedBuffer(fastRerouteObject.getBandwidth().getValue()));
         writeAttributeFilter(fastRerouteObject.getIncludeAny(), byteAggregator);
index cd5bd9c400a4690f5ddb98409fd67caca04b581b..751b5fcfc11050d912c22eb6849f49ca77080174 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.protocol.rsvp.parser.impl.te;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.writeUint8;
 
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
@@ -19,7 +21,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.metric.object.MetricObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.metric.object.MetricObjectBuilder;
-import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public final class MetricObjectParser extends AbstractRSVPObjectParser {
     public static final short CLASS_NUM = 6;
@@ -37,7 +38,7 @@ public final class MetricObjectParser extends AbstractRSVPObjectParser {
         return new MetricObjectBuilder()
                 .setBound(flags.get(BOUND))
                 .setComputed(flags.get(COMPUTED))
-                .setMetricType(ByteBufUtils.readUint8(byteBuf))
+                .setMetricType(readUint8(byteBuf))
                 .setValue(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
                 .build();
     }
@@ -52,7 +53,7 @@ public final class MetricObjectParser extends AbstractRSVPObjectParser {
         reflect.set(BOUND, metric.getBound());
         reflect.set(COMPUTED, metric.getComputed());
         reflect.toByteBuf(output);
-        output.writeByte(metric.getMetricType().toJava());
+        writeUint8(output, metric.getMetricType());
         writeFloat32(metric.getValue(), output);
     }
 }
index 5de8252d4bf9912496dedd67bcf89798343f5c4d..44dcd6b27a4da5ef50ae2b93c178131801cb047d 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.protocol.rsvp.parser.impl.te;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.writeUint8;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -19,7 +21,6 @@ import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.basic.session.attribute.object._case.BasicSessionAttributeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.basic.session.attribute.object._case.BasicSessionAttributeObjectBuilder;
-import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public final class SessionAttributeLspObjectParser extends AbstractRSVPObjectParser {
     public static final short CLASS_NUM = 207;
@@ -39,8 +40,8 @@ public final class SessionAttributeLspObjectParser extends AbstractRSVPObjectPar
     @Override
     protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
         final BasicSessionAttributeObjectBuilder builder = new BasicSessionAttributeObjectBuilder()
-                .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
-                .setHoldPriority(ByteBufUtils.readUint8(byteBuf));
+                .setSetupPriority(readUint8(byteBuf))
+                .setHoldPriority(readUint8(byteBuf));
         final BitArray bs = BitArray.valueOf(byteBuf.readByte());
         builder.setLocalProtectionDesired(bs.get(LOCAL_PROTECTION));
         builder.setLabelRecordingDesired(bs.get(LABEL_RECORDING));
@@ -61,8 +62,8 @@ public final class SessionAttributeLspObjectParser extends AbstractRSVPObjectPar
             .getSessionName()));
         final int pad = getPadding(sessionName.readableBytes());
         serializeAttributeHeader(BODY_SIZE_C7 + pad + sessionName.readableBytes(), CLASS_NUM, CTYPE, output);
-        output.writeByte(sessionObject.getSetupPriority().toJava());
-        output.writeByte(sessionObject.getHoldPriority().toJava());
+        writeUint8(output, sessionObject.getSetupPriority());
+        writeUint8(output, sessionObject.getHoldPriority());
         final BitArray bs = new BitArray(FLAGS_SIZE);
         bs.set(LOCAL_PROTECTION, sessionObject.getLocalProtectionDesired());
         bs.set(LABEL_RECORDING, sessionObject.getLabelRecordingDesired());
index 5dae1e245de0309115523c4b958efa2ab08912af..68ea919630362edf24417e8b541ca47f805cdc32 100644 (file)
@@ -8,6 +8,9 @@
 package org.opendaylight.protocol.rsvp.parser.impl.te;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
+import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.writeUint8;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -20,7 +23,6 @@ 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.RsvpTeObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.session.attribute.object.with.resources.affinities._case.SessionAttributeObjectWithResourcesAffinities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.session.attribute.object.with.resources.affinities._case.SessionAttributeObjectWithResourcesAffinitiesBuilder;
-import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public final class SessionAttributeLspRaObjectParser extends AbstractRSVPObjectParser {
     public static final short CLASS_NUM = 207;
@@ -31,11 +33,11 @@ public final class SessionAttributeLspRaObjectParser extends AbstractRSVPObjectP
     protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
         final SessionAttributeObjectWithResourcesAffinitiesBuilder builder =
                 new SessionAttributeObjectWithResourcesAffinitiesBuilder()
-                    .setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
-                    .setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
-                    .setIncludeAll(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
-                    .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
-                    .setHoldPriority(ByteBufUtils.readUint8(byteBuf));
+                    .setIncludeAny(new AttributeFilter(readUint32(byteBuf)))
+                    .setExcludeAny(new AttributeFilter(readUint32(byteBuf)))
+                    .setIncludeAll(new AttributeFilter(readUint32(byteBuf)))
+                    .setSetupPriority(readUint8(byteBuf))
+                    .setHoldPriority(readUint8(byteBuf));
 
         final BitArray bs = BitArray.valueOf(byteBuf.readByte());
         builder.setLocalProtectionDesired(bs.get(SessionAttributeLspObjectParser.LOCAL_PROTECTION));
@@ -63,8 +65,8 @@ public final class SessionAttributeLspRaObjectParser extends AbstractRSVPObjectP
         writeAttributeFilter(sessionObject.getIncludeAny(), output);
         writeAttributeFilter(sessionObject.getExcludeAny(), output);
         writeAttributeFilter(sessionObject.getIncludeAll(), output);
-        output.writeByte(sessionObject.getSetupPriority().toJava());
-        output.writeByte(sessionObject.getHoldPriority().toJava());
+        writeUint8(output, sessionObject.getSetupPriority());
+        writeUint8(output, sessionObject.getHoldPriority());
         final BitArray bs = new BitArray(FLAGS_SIZE);
         bs.set(SessionAttributeLspObjectParser.LOCAL_PROTECTION, sessionObject.getLocalProtectionDesired());
         bs.set(SessionAttributeLspObjectParser.LABEL_RECORDING, sessionObject.getLabelRecordingDesired());