Minimize use of ByteBufWriteUtil in bgp-parser-spi 11/86711/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 11:12:11 +0000 (12:12 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 13:46:54 +0000 (14:46 +0100)
Most of the call sites are easily reformulated in terms of either
raw ByteBuf access or ByteBufUtils.

Change-Id: Ie500b13578ed9be0b94f48d335889e2121d8e034
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/extended/community/FourOctAsCommonECUtil.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleExtendedCommunityRegistry.java
bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtilTest.java

index 3afaf6d126e8b7c532c977b1872333cc15db4063..8351604d363a7b1cfc902a5a904994828c464b44 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.bgp.parser.spi;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import java.util.Optional;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
 import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -33,17 +32,16 @@ public final class PathIdUtil {
     }
 
     /**
-     * Writes path-id value into the buffer when
-     * the path-id is not null or does not equal to zero.
+     * Writes path-id value into the buffer when the path-id is not null or does not equal to zero.
      *
      * @param pathId The NLRI Path Identifier.
      * @param buffer The ByteBuf where path-id value can be written.
      */
     public static void writePathId(final PathId pathId, final ByteBuf buffer) {
         if (pathId != null) {
-            final Uint32 value = pathId.getValue();
-            if (value.toJava() != 0) {
-                ByteBufWriteUtil.writeUnsignedInt(value, buffer);
+            final int value = pathId.getValue().intValue();
+            if (value != 0) {
+                buffer.writeInt(value);
             }
         }
     }
index 9e2fefdbc657905bd3b501d90c33034e7f482e14..ba909a2a91e554b4e9671af9de43e20c2f3e71fd 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.bgp.parser.spi.extended.community;
 
 import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommon;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommonBuilder;
@@ -20,12 +19,14 @@ public final class FourOctAsCommonECUtil {
     }
 
     public static As4SpecificCommon parseCommon(final ByteBuf body) {
-        return new As4SpecificCommonBuilder().setAsNumber(new AsNumber(ByteBufUtils.readUint32(body)))
-            .setLocalAdministrator(ByteBufUtils.readUint16(body)).build();
+        return new As4SpecificCommonBuilder()
+                .setAsNumber(new AsNumber(ByteBufUtils.readUint32(body)))
+                .setLocalAdministrator(ByteBufUtils.readUint16(body))
+                .build();
     }
 
     public static void serializeCommon(final As4SpecificCommon extComm, final ByteBuf body) {
-        body.writeInt(extComm.getAsNumber().getValue().intValue());
-        ByteBufWriteUtil.writeUnsignedShort(extComm.getLocalAdministrator(), body);
+        ByteBufUtils.write(body, extComm.getAsNumber().getValue());
+        ByteBufUtils.writeOrZero(body, extComm.getLocalAdministrator());
     }
 }
index eb8a87a918ef09060b5d6ebd1d3575597f6b28a6..6a7deaf8b58cf23ad5fc4dd68b4d1bde31836e3e 100644 (file)
@@ -19,7 +19,6 @@ import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommu
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
 import org.opendaylight.yangtools.concepts.Registration;
@@ -64,9 +63,8 @@ final class SimpleExtendedCommunityRegistry implements ExtendedCommunityRegistry
         if (serializer == null) {
             return;
         }
-        ByteBufWriteUtil.writeUnsignedByte(Shorts.checkedCast(serializer.getType(extendedCommunity.isTransitive())),
-            byteAggregator);
-        ByteBufWriteUtil.writeUnsignedByte(Shorts.checkedCast(serializer.getSubType()), byteAggregator);
+        byteAggregator.writeByte(Shorts.checkedCast(serializer.getType(extendedCommunity.isTransitive())));
+        byteAggregator.writeByte(Shorts.checkedCast(serializer.getSubType()));
         serializer.serializeExtendedCommunity(extendedCommunity.getExtendedCommunity(), byteAggregator);
     }
 
index f0afbd30624b29061f6320fb22ff47f8d2055702..de683aa4f68c1c7fd91ca36dff9ddcbcabd1e696 100644 (file)
@@ -14,7 +14,6 @@ import io.netty.buffer.Unpooled;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Uint32;
@@ -52,10 +51,9 @@ public class PathIdUtilTest {
 
     @Test
     public void testReadPathId() {
-        final long expected = 10L;
-        ByteBufWriteUtil.writeUnsignedInt(expected, this.buffer);
+        this.buffer.writeInt(10);
         final PathId pathId = PathIdUtil.readPathId(this.buffer);
-        Assert.assertEquals(expected, pathId.getValue().longValue());
+        Assert.assertEquals(Uint32.TEN, pathId.getValue());
     }
 
     @Test