Move ipv4/ipv6 ByteBuf utilities to Ipv{4,6}Util
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / PCEPExistingBandwidthObjectParser.java
index 2f2b182993f811d006992a4fea32c1831b522938..fe4b726803d4b1cae4b23ae24c6e08e74fe6cb3c 100644 (file)
@@ -12,42 +12,53 @@ import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reoptimization.bandwidth.object.ReoptimizationBandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reoptimization.bandwidth.object.ReoptimizationBandwidthBuilder;
 
 /**
- * Parser for Bandwidth
+ * Parser for Bandwidth.
  */
-public class PCEPExistingBandwidthObjectParser implements ObjectParser, ObjectSerializer {
+public class PCEPExistingBandwidthObjectParser extends CommonObjectParser implements ObjectSerializer {
 
-    public static final int CLASS = 5;
+    private static final int CLASS = 5;
 
-    public static final int TYPE = 2;
+    private static final int TYPE = 2;
+
+    public PCEPExistingBandwidthObjectParser() {
+        super(CLASS, TYPE);
+    }
 
     @Override
-    public ReoptimizationBandwidth parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
-        Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+    public ReoptimizationBandwidth parseObject(final ObjectHeader header, final ByteBuf bytes)
+            throws PCEPDeserializerException {
+        Preconditions.checkArgument(bytes != null && bytes.isReadable(),
+                "Array of bytes is mandatory. Can't be null or empty.");
         if (bytes.readableBytes() != PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH) {
-            throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: "
-                + PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH + ".");
+            throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes()
+                    + "; Expected: " + PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH + ".");
         }
-        final ReoptimizationBandwidthBuilder builder = new ReoptimizationBandwidthBuilder();
-        builder.setIgnore(header.isIgnore());
-        builder.setProcessingRule(header.isProcessingRule());
-        builder.setBandwidth(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(ByteArray.getAllBytes(bytes)));
+        final ReoptimizationBandwidthBuilder builder = new ReoptimizationBandwidthBuilder()
+                .setIgnore(header.isIgnore())
+                .setProcessingRule(header.isProcessingRule())
+                .setBandwidth(
+                    new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125
+                        .Bandwidth(ByteArray.getAllBytes(bytes)));
         return builder.build();
     }
 
     @Override
-    public void serializeObject(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object object, final ByteBuf buffer) {
-        Preconditions.checkArgument(object instanceof ReoptimizationBandwidth, "Wrong instance of PCEPObject. Passed " +
-            "%s. Needed ReoptimizationBandwidthObject.", object.getClass());
+    public void serializeObject(
+            final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object object,
+            final ByteBuf buffer) {
+        Preconditions.checkArgument(object instanceof ReoptimizationBandwidth,
+                "Wrong instance of PCEPObject. Passed " + "%s. Needed ReoptimizationBandwidthObject.",
+                object.getClass());
         final ByteBuf body = Unpooled.buffer();
         writeFloat32(((ReoptimizationBandwidth) object).getBandwidth(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);