BUG-612 : switched ERO to ByteBuf.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPExplicitRouteObjectParser.java
index 2eb4fd3d05592c3e8f2d7c78da746f4687d64263..4c06b9ca1e34f071fd973a13948a9645fa650d64 100644 (file)
@@ -7,16 +7,20 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 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.path.definition.ExplicitRouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
+
+import com.google.common.base.Preconditions;
 
 /**
- * Parser for {@link ExplicitRouteObject}
+ * Parser for {@link Ero}
  */
 public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsParser {
 
@@ -24,44 +28,31 @@ public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsPars
 
        public static final int TYPE = 1;
 
-       public PCEPExplicitRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
+       public PCEPExplicitRouteObjectParser(final EROSubobjectRegistry subobjReg) {
                super(subobjReg);
        }
 
        @Override
-       public ExplicitRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-                       PCEPDocumentedException {
-               if (bytes == null || bytes.length == 0) {
-                       throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
-               }
-               final ExplicitRouteBuilder builder = new ExplicitRouteBuilder();
+       public Ero parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+               Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+               final EroBuilder builder = new EroBuilder();
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-               builder.setSubobjects(parseSubobjects(bytes));
+               builder.setSubobject(parseSubobjects(buffer));
                return builder.build();
        }
 
        @Override
        public byte[] serializeObject(final Object object) {
-               if (!(object instanceof ExplicitRouteObject)) {
+               if (!(object instanceof Ero)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
                                        + ". Needed ExplicitRouteObject.");
                }
+               final Ero ero = ((Ero) object);
 
-               final ExplicitRouteObject ero = ((ExplicitRouteObject) object);
-
-               assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
-
-               return serializeSubobject(ero.getSubobjects());
-       }
+               assert !(ero.getSubobject().isEmpty()) : "Empty Explicit Route Object.";
 
-       @Override
-       public int getObjectType() {
-               return TYPE;
-       }
-
-       @Override
-       public int getObjectClass() {
-               return CLASS;
+               return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(),
+                               serializeSubobject(ero.getSubobject()));
        }
 }