BUG-612 : switched ERO to ByteBuf.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / subobject / EROLabelSubobjectParser.java
index 8261b951fcd7a77df63a5fa7c65b55603a99f515..a817874bf220fa7c0dbb0dba48b2af6a5e2ad37a 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import java.util.Arrays;
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.impl.object.EROSubobjectUtil;
@@ -50,20 +51,17 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
        }
 
        @Override
-       public Subobject parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0) {
-                       throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               }
-               if (buffer.length < HEADER_LENGTH) {
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
+       public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
+               Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+               if (buffer.readableBytes() < HEADER_LENGTH) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
                                        + HEADER_LENGTH + ".");
                }
-               final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
-
-               final short cType = (short) UnsignedBytes.toInt(buffer[C_TYPE_F_OFFSET]);
-
-               final LabelType labelType = this.registry.parseLabel(cType, ByteArray.cutBytes(buffer, HEADER_LENGTH));
+               final BitSet reserved = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, RES_F_LENGTH));
+               final short cType = (short) UnsignedBytes.toInt(buffer.readByte());
 
+               //FIXME: switch to ByteBuf
+               final LabelType labelType = this.registry.parseLabel(cType, ByteArray.readAllBytes(buffer));
                if (labelType == null) {
                        throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
                }