Reduce use oif ByteBufWriteUtil in pcep-segment-routing 20/86720/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 14:20:25 +0000 (15:20 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 14:22:01 +0000 (15:22 +0100)
ByteBufUtils or ByteBuf methods provide most of what we need, use
upstreams to reduce use of our home-grown utilities.

Change-Id: If166a719f0ad67009c434d97e1347d75369257ad
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/AbstractSrSubobjectParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrPceCapabilityTlvParser.java

index ff886f06fb1a0aaf2fd0d0fd0bdd94e573fae68c..b4ecebf9e042db91dab28c9688b297ecb401bd0c 100644 (file)
@@ -10,14 +10,11 @@ package org.opendaylight.protocol.pcep.segment.routing;
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
@@ -31,7 +28,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.seg
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.subobject.nai.UnnumberedAdjacency;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.subobject.nai.UnnumberedAdjacencyBuilder;
 import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint8;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public abstract class AbstractSrSubobjectParser {
@@ -95,7 +91,7 @@ public abstract class AbstractSrSubobjectParser {
     public ByteBuf serializeSubobject(final SrSubobject srSubobject) {
         final ByteBuf buffer = Unpooled.buffer(MINIMAL_LENGTH);
         // sid type
-        writeUnsignedByte(Uint8.valueOf(srSubobject.getSidType().getIntValue() << SID_TYPE_BITS_OFFSET), buffer);
+        buffer.writeByte(srSubobject.getSidType().getIntValue() << SID_TYPE_BITS_OFFSET);
 
         final BitArray bits = new BitArray(BITSET_LENGTH);
         bits.set(M_FLAG_POSITION, srSubobject.isMFlag());
@@ -113,9 +109,9 @@ public abstract class AbstractSrSubobjectParser {
                 "Both SID and NAI are absent in SR subobject.");
         if (srSubobject.getSid() != null) {
             if (srSubobject.isMFlag()) {
-                writeUnsignedInt(Uint32.valueOf(srSubobject.getSid().intValue() << MPLS_LABEL_OFFSET), buffer);
+                buffer.writeInt(srSubobject.getSid().intValue() << MPLS_LABEL_OFFSET);
             } else {
-                writeUnsignedInt(srSubobject.getSid(), buffer);
+                ByteBufUtils.writeOrZero(buffer, srSubobject.getSid());
             }
         }
         // nai
@@ -144,10 +140,10 @@ public abstract class AbstractSrSubobjectParser {
                 break;
             case Unnumbered:
                 final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency) nai;
-                ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalNodeId(), buffer);
-                ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalInterfaceId(), buffer);
-                ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteNodeId(), buffer);
-                ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteInterfaceId(), buffer);
+                ByteBufUtils.writeOrZero(buffer, unnumbered.getLocalNodeId());
+                ByteBufUtils.writeOrZero(buffer, unnumbered.getLocalInterfaceId());
+                ByteBufUtils.writeOrZero(buffer, unnumbered.getRemoteNodeId());
+                ByteBufUtils.writeOrZero(buffer, unnumbered.getRemoteInterfaceId());
                 break;
             default:
                 break;
index b4e7ae1b517836b4aea679d9a2526accb91a419c..f30b5f7d9eda01ea6875045d7fa515693fad0dd0 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.pcep.segment.routing;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -33,7 +32,7 @@ public class SrPceCapabilityTlvParser implements TlvParser, TlvSerializer {
         checkArgument(tlv instanceof SrPceCapability, "SrPceCapability is mandatory.");
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writerIndex(OFFSET);
-        writeUnsignedByte(((SrPceCapability) tlv).getMsd(), body);
+        ByteBufUtils.writeOrZero(body, ((SrPceCapability) tlv).getMsd());
         TlvUtil.formatTlv(TYPE, body, buffer);
     }