Eliminate use of ByteBufWriteUtil in rsvp-spi 13/86713/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 11:31:20 +0000 (12:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 13:46:54 +0000 (14:46 +0100)
Logic in rsvp-spi can easily use ByteBufUtils or direct ByteBuf
methods, remove unneeded use of ByteBufWriteUtil.

Change-Id: Ic12ac3939d4077b18e6d9e29396e8381dd77335c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/AbstractRSVPObjectParser.java
rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonPathKeyParser.java
rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/CommonUnnumberedInterfaceSubobjectParser.java

index 39ab88fadba04c7b21d5f3cfb357a3c1f3ad7867..b1577ddea1ffa48dfc4c8cc1301a96b37150651a 100644 (file)
@@ -5,17 +5,15 @@
  * 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.spi.subobjects;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectParser;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectSerializer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public abstract class AbstractRSVPObjectParser implements RSVPTeObjectSerializer, RSVPTeObjectParser {
 
@@ -35,7 +33,11 @@ public abstract class AbstractRSVPObjectParser implements RSVPTeObjectSerializer
     }
 
     protected static void writeAttributeFilter(final AttributeFilter attributeFilter, final ByteBuf body) {
-        writeUnsignedInt(attributeFilter != null ? attributeFilter.getValue() : null, body);
+        if (attributeFilter != null) {
+            ByteBufUtils.write(body, attributeFilter.getValue());
+        } else {
+            body.writeInt(0);
+        }
     }
 
     @Override
index 32263c4a82f7eeae00cddae911fa31423d8349a6..0597a9c9a7b59af686f708a8dafc82c1f1fcd113 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.protocol.rsvp.parser.spi.subobjects;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -16,7 +15,6 @@ import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 public class CommonPathKeyParser {
@@ -26,21 +24,22 @@ public class CommonPathKeyParser {
 
     public static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
         .subobjects.subobject.type.path.key._case.PathKey parsePathKey(final int pceIdFLength, final ByteBuf buffer) {
-        final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
-        final byte[] pceId = ByteArray.readBytes(buffer, pceIdFLength);
-        final PathKeyBuilder pBuilder = new PathKeyBuilder();
-        pBuilder.setPceId(new PceId(pceId));
-        pBuilder.setPathKey(new PathKey(pathKey));
-        return pBuilder.build();
+        return new PathKeyBuilder()
+                .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+                .setPceId(new PceId(ByteArray.readBytes(buffer, pceIdFLength)))
+                .build();
     }
 
     public static ByteBuf serializePathKey(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
         .rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey pk) {
         final ByteBuf body = Unpooled.buffer();
-        checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
-        writeUnsignedShort(pk.getPathKey().getValue(), body);
-        checkArgument(pk.getPceId() != null, "PceId is mandatory.");
-        body.writeBytes(pk.getPceId().getValue());
+        final PathKey pathKey = pk.getPathKey();
+        checkArgument(pathKey != null, "PathKey is mandatory.");
+        ByteBufUtils.write(body, pathKey.getValue());
+
+        final PceId pceId = pk.getPceId();
+        checkArgument(pceId != null, "PceId is mandatory.");
+        body.writeBytes(pceId.getValue());
         return body;
     }
 }
index 2f1175251f56f42111e2df86a6b6738deea27b08..3d394848f7d606ca2e8a0c84e95c1a61f3a53442 100644 (file)
@@ -7,10 +7,7 @@
  */
 package org.opendaylight.protocol.rsvp.parser.spi.subobjects;
 
-import static com.google.common.base.Preconditions.checkArgument;
-
 import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.Unnumbered;
@@ -32,9 +29,7 @@ public class CommonUnnumberedInterfaceSubobjectParser {
     }
 
     protected static void serializeUnnumeredInterface(final Unnumbered unnumbered, final ByteBuf body) {
-        checkArgument(unnumbered.getRouterId() != null, "RouterId is mandatory.");
-        ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRouterId(), body);
-        checkArgument(unnumbered.getInterfaceId() != null, "InterfaceId is mandatory.");
-        ByteBufWriteUtil.writeUnsignedInt(unnumbered.getInterfaceId(), body);
+        ByteBufUtils.writeMandatory(body, unnumbered.getRouterId(), "RouterId");
+        ByteBufUtils.writeMandatory(body, unnumbered.getInterfaceId(), "InterfaceId");
     }
 }