X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fimpl%2Fsubobject%2FEROPathKey32SubobjectParser.java;h=4780090bc197f9b8d9b71f891576e2b31c09e78c;hb=bb1a5b0139b814666b85de460a89604bea5db0ec;hp=5225aac6e963a488ed1519eb54761ec9ddafc882;hpb=6e760f886348592e4d1088ceeed80fa3ffbf9dc5;p=bgpcep.git diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKey32SubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKey32SubobjectParser.java index 5225aac6e9..4780090bc1 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKey32SubobjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKey32SubobjectParser.java @@ -7,7 +7,7 @@ */ package org.opendaylight.protocol.pcep.impl.subobject; -import java.util.Arrays; +import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.pcep.impl.object.EROSubobjectUtil; import org.opendaylight.protocol.pcep.spi.EROSubobjectParser; @@ -22,6 +22,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.subobject.subobject.type.PathKeyCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKeyBuilder; +import com.google.common.base.Preconditions; + /** * Parser for {@link PathKey} */ @@ -38,21 +40,19 @@ public class EROPathKey32SubobjectParser implements EROSubobjectParser, EROSubob private static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH; @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 != CONTENT_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() != CONTENT_LENGTH) { + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" + CONTENT_LENGTH + "."); } - final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH); - final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)); + final int pathKey = buffer.readUnsignedShort(); + final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH); final SubobjectBuilder builder = new SubobjectBuilder(); - builder.setLoose(loose); final PathKeyBuilder pBuilder = new PathKeyBuilder(); pBuilder.setPceId(new PceId(pceId)); pBuilder.setPathKey(new PathKey(pathKey)); + builder.setLoose(loose); builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build()); return builder.build(); }