*/
package org.opendaylight.protocol.pcep.ietf.initiated00;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07SrpObjectParser;
-import org.opendaylight.protocol.pcep.spi.ObjectUtil;
-import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
-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;
/**
* Parser for {@link Srp}
}
@Override
- public Srp parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
- if (bytes.readableBytes() < MIN_SIZE) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: >="
- + MIN_SIZE + ".");
- }
- final SrpBuilder builder = new SrpBuilder();
- builder.setIgnore(header.isIgnore());
- builder.setProcessingRule(header.isProcessingRule());
+ protected void parseFlags(final SrpBuilder builder, final ByteBuf bytes) {
final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
builder.addAugmentation(Srp1.class, new Srp1Builder().setRemove(flags.get(REMOVE_FLAG)).build());
- builder.setOperationId(new SrpIdNumber(bytes.readUnsignedInt()));
- final TlvsBuilder tlvsBuilder = new TlvsBuilder();
- parseTlvs(tlvsBuilder, bytes.slice());
- builder.setTlvs(tlvsBuilder.build());
- return builder.build();
}
@Override
- public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Srp, "Wrong instance of PCEPObject. Passed %s. Needed SrpObject.", object.getClass());
- final Srp srp = (Srp) object;
- final ByteBuf body = Unpooled.buffer();
+ protected void serializeFlags(final Srp srp, final ByteBuf body) {
final BitArray flags = new BitArray(FLAGS_SIZE);
if (srp.getAugmentation(Srp1.class) != null) {
flags.set(REMOVE_FLAG, srp.getAugmentation(Srp1.class).isRemove());
}
flags.toByteBuf(body);
- Preconditions.checkArgument(srp.getOperationId() != null, "OperationId is mandatory.");
- writeUnsignedInt(srp.getOperationId().getValue(), body);
- serializeTlvs(srp.getTlvs(), body);
- ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
}