Reduce use of Util.writeShortest() 06/86706/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 09:32:14 +0000 (10:32 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 09:32:14 +0000 (10:32 +0100)
In case we are coming from an Uint8 there really is no point in
going through Util.writeShortest() as the result is always going
to fit in a single byte. Use ByteBufUtils directly to emit that
byte.

Change-Id: I40288d3fa3c149e8effa0fe1c2c8de52f19eeb79
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/NumericOneByteOperandParser.java

index f686a6bcef5c19b9cbd2f9d02b4f498dd894930a..38755526d2fd3b8377e375ac27d02d1b69936efa 100644 (file)
@@ -17,7 +17,6 @@ import java.util.List;
 import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
 import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser;
-import org.opendaylight.protocol.bgp.flowspec.handlers.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.Dscp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
@@ -34,7 +33,7 @@ public final class FSDscpHandler implements FlowspecTypeParser, FlowspecTypeSeri
         for (final Iterator<Dscps> it = dscps.iterator(); it.hasNext(); ) {
             final Dscps dscp = it.next();
             NumericOneByteOperandParser.INSTANCE.serialize(dscp.getOp(), 1, !it.hasNext(), nlriByteBuf);
-            Util.writeShortest(dscp.getValue().getValue().toJava(), nlriByteBuf);
+            ByteBufUtils.write(nlriByteBuf, dscp.getValue().getValue());
         }
     }
 
index dc83e7a07f9249980fbd378d4033cd77f9c9237a..4c9fe5f81de0fbdf9b2e3f98bcca13b1299155c3 100644 (file)
@@ -13,17 +13,13 @@ import java.util.List;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOneByteValue;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
 import org.opendaylight.yangtools.yang.common.Uint8;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
 
 /**
  * Parser class for NumericOneByteValues.
  */
 public final class NumericOneByteOperandParser extends AbstractNumericByteOperandParser<NumericOneByteValue, Uint8> {
-
-    public static final NumericOneByteOperandParser INSTANCE;
-
-    static {
-        INSTANCE = new NumericOneByteOperandParser();
-    }
+    public static final NumericOneByteOperandParser INSTANCE = new NumericOneByteOperandParser();
 
     private NumericOneByteOperandParser() {
 
@@ -39,8 +35,8 @@ public final class NumericOneByteOperandParser extends AbstractNumericByteOperan
     public <T extends NumericOneByteValue> void serialize(final List<T> list, final ByteBuf nlriByteBuf) {
         for (final Iterator<T> it = list.iterator(); it.hasNext(); ) {
             final T operand = it.next();
-            super.serialize(operand.getOp(), 1, !it.hasNext(), nlriByteBuf);
-            Util.writeShortest(operand.getValue().toJava(), nlriByteBuf);
+            serialize(operand.getOp(), 1, !it.hasNext(), nlriByteBuf);
+            ByteBufUtils.write(nlriByteBuf, operand.getValue());
         }
     }