*/
package org.opendaylight.protocol.pcep.impl.subobject;
+import io.netty.buffer.ByteBuf;
+
import org.opendaylight.protocol.pcep.impl.object.EROSubobjectUtil;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
+import com.google.common.base.Preconditions;
+
/**
* Parser for {@link AsNumberCase}
*/
public static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET;
@Override
- public Subobjects 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 + ".");
}
-
- return new SubobjectsBuilder().setLoose(loose).setSubobjectType(
+ return new SubobjectBuilder().setLoose(loose).setSubobjectType(
new AsNumberCaseBuilder().setAsNumber(
- new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build()).build()).build();
+ new AsNumberBuilder().setAsNumber(new AsNumber((long) buffer.readUnsignedShort())).build()).build()).build();
}
@Override
- public byte[] serializeSubobject(final Subobjects subobject) {
+ public byte[] serializeSubobject(final Subobject subobject) {
if (!(subobject.getSubobjectType() instanceof AsNumberCase)) {
throw new IllegalArgumentException("Unknown subobject instance. Passed " + subobject.getSubobjectType().getClass()
+ ". Needed AsNumberCase.");
return EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), retBytes);
}
-
- @Override
- public int getType() {
- return TYPE;
- }
}