Replaced slice() with readSlice() where appropriate.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / AbstractEROWithSubobjectsParser.java
index 96fd9b369080f1175c236413af2c06e218d259bd..694b025675797709b13913c02cb6e33ae0afbf6c 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Values;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,22 +39,21 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
         Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
         final List<Subobject> subs = new ArrayList<>();
         while (buffer.isReadable()) {
-            boolean loose = ((buffer.getByte(buffer.readerIndex()) & (1 << 7)) != 0) ? true : false;
-            int type = (buffer.readByte() & 0xff) & ~(1 << 7);
-            int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
+            final boolean loose = ((buffer.getByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
+            final int type = (buffer.readByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET);
+            final int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
             if (length > buffer.readableBytes()) {
                 throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
                         + buffer.readableBytes());
             }
             LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer));
-            final Subobject sub = this.subobjReg.parseSubobject(type, buffer.slice(buffer.readerIndex(), length), loose);
+            final Subobject sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length), loose);
             if (sub == null) {
                 LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
             } else {
                 LOG.debug("Subobject was parsed. {}", sub);
                 subs.add(sub);
             }
-            buffer.readerIndex(buffer.readerIndex() + length);
         }
         return subs;
     }