*/
package org.opendaylight.protocol.pcep.impl.object;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
/**
- * Parser for {@link Bandwidth}
+ * Parser for Bandwidth
*/
-public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser<BandwidthBuilder> {
-
- public static final int E_CLASS = 5;
-
- public static final int E_TYPE = 1;
-
- public static final int CLASS = 5;
-
- public static final int TYPE = 2;
-
- private static final int BANDWIDTH_F_LENGTH = 4;
-
- public PCEPBandwidthObjectParser(final TlvHandlerRegistry tlvReg) {
- super(tlvReg);
- }
-
- @Override
- public Bandwidth parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
- if (bytes == null || bytes.length == 0) {
- throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- }
- if (bytes.length != BANDWIDTH_F_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: "
- + BANDWIDTH_F_LENGTH + ".");
- }
- final BandwidthBuilder builder = new BandwidthBuilder();
- builder.setIgnore(header.isIgnore());
- builder.setProcessingRule(header.isProcessingRule());
- builder.setBandwidth(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth(bytes));
- return builder.build();
- }
-
- @Override
- public void addTlv(final BandwidthBuilder builder, final Tlv tlv) {
- // No tlvs defined
- }
-
- @Override
- public byte[] serializeObject(final Object object) {
- if (!(object instanceof Bandwidth)) {
- throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed BandwidthObject.");
- }
- return ((Bandwidth) object).getBandwidth().getValue();
- }
+public class PCEPBandwidthObjectParser extends AbstractBandwidthParser {
- @Override
- public int getObjectType() {
- return TYPE;
- }
+ public static final int CLASS = 5;
- @Override
- public int getObjectClass() {
- return CLASS;
- }
+ public static final int TYPE = 1;
- public int getEObjectType() {
- return E_TYPE;
- }
+ public PCEPBandwidthObjectParser(final TlvRegistry tlvReg) {
+ super(tlvReg);
+ }
- public int getEObjectClass() {
- return E_CLASS;
- }
+ @Override
+ protected void formatBandwidth(boolean processed, boolean ignored, ByteBuf body, ByteBuf buffer) {
+ ObjectUtil.formatSubobject(TYPE, CLASS, processed, ignored, body, buffer);
+ }
}