Reduce PathKey serialization duplication 59/86759/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 18:45:13 +0000 (19:45 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 18:45:13 +0000 (19:45 +0100)
PathKeyUtils.serializePathKey() can take PathKeySubobject, which
makes it readily reusable in RROPathKey128SubobjectParser, reducing
amount of duplication we have.

Change-Id: I23f5c58842c2a1ef073ef3f90b6224247a7a195f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
rsvp/impl/src/main/java/org/opendaylight/protocol/rsvp/parser/impl/subobject/rro/RROPathKey128SubobjectParser.java
rsvp/spi/src/main/java/org/opendaylight/protocol/rsvp/parser/spi/subobjects/PathKeyUtils.java

index fc33c71545f3cebc0818215544b7e0f8cc5987a2..e6634465b3598bd1e0218a03ae24d4b2231d809b 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro;
 import static com.google.common.base.Preconditions.checkArgument;
 
 import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.rsvp.parser.spi.subobjects.PathKeyUtils;
 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;
@@ -35,18 +35,7 @@ public class RROPathKey128SubobjectParser implements RROSubobjectParser {
 
     public static void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
         final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
-            .subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
-        final ByteBuf body = Unpooled.buffer();
-
-        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());
-        RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
+        RROSubobjectUtil.formatSubobject(TYPE, PathKeyUtils.serializePathKey(pkcase.getPathKey()), buffer);
     }
 
     @Override
index fc613383dbcbd52d9d45195002f312bb4ad2d0fd..8d0b6588f55f74bb6973271d3635232344d1a190 100644 (file)
@@ -13,6 +13,7 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 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.PathKeySubobject;
 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.netty.ByteBufUtils;
@@ -30,8 +31,7 @@ public final class PathKeyUtils {
                 .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) {
+    public static ByteBuf serializePathKey(final PathKeySubobject pk) {
         final ByteBuf body = Unpooled.buffer();
         final PathKey pathKey = pk.getPathKey();
         checkArgument(pathKey != null, "PathKey is mandatory.");