BUG-612 : switched PCEP Tlvs to ByteBuf
[bgpcep.git] / pcep / ietf-stateful07 / src / main / java / org / opendaylight / protocol / pcep / ietf / initiated00 / CInitiated00StatefulCapabilityTlvParser.java
index a9ccb0d2060f2d4153b2688324b7e0b2f3694ede..abdac029c7ccc439332cf66971ce1d8cfbb4d422 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.ietf.initiated00;
 
+import io.netty.buffer.ByteBuf;
+
 import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
@@ -27,15 +29,15 @@ public final class CInitiated00StatefulCapabilityTlvParser extends Stateful07Sta
        private static final int I_FLAG_OFFSET = 29;
 
        @Override
-       public Stateful parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0) {
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+       public Stateful parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
+               if (buffer == null) {
+                       return null;
                }
-               if (buffer.length < FLAGS_F_LENGTH) {
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >= "
+               if (buffer.readableBytes() < FLAGS_F_LENGTH) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
                                        + FLAGS_F_LENGTH + ".");
                }
-               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(buffer, 0, FLAGS_F_LENGTH));
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
 
                final StatefulBuilder sb = new StatefulBuilder();
                sb.setLspUpdateCapability(flags.get(U_FLAG_OFFSET));