BUG-612 : switched ERO to ByteBuf.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPExplicitRouteObjectParser.java
index bec1f4c5f59d642c6a21765ebba5772d8c41f2dd..4c06b9ca1e34f071fd973a13948a9645fa650d64 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+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;
@@ -15,6 +17,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 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 Ero}
  */
@@ -24,19 +28,17 @@ 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 Ero parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
-               if (bytes == null || bytes.length == 0) {
-                       throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
-               }
+       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.setSubobject(parseSubobjects(bytes));
+               builder.setSubobject(parseSubobjects(buffer));
                return builder.build();
        }
 
@@ -53,14 +55,4 @@ public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsPars
                return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(),
                                serializeSubobject(ero.getSubobject()));
        }
-
-       @Override
-       public int getObjectType() {
-               return TYPE;
-       }
-
-       @Override
-       public int getObjectClass() {
-               return CLASS;
-       }
 }