package org.opendaylight.protocol.pcep.parser.object;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.no.path.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
+import org.opendaylight.yangtools.yang.common.Uint8;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
/**
- * Parser for {@link NoPath}
+ * Parser for {@link NoPath}.
*/
public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<TlvsBuilder> {
-
private static final int CLASS = 3;
private static final int TYPE = 1;
@Override
public NoPath parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
- final NoPathBuilder builder = new NoPathBuilder();
- builder.setIgnore(header.isIgnore());
- builder.setProcessingRule(header.isProcessingRule());
- builder.setNatureOfIssue(ByteBufUtils.readUint8(bytes));
+ final Uint8 issue = ByteBufUtils.readUint8(bytes);
final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
- builder.setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET));
bytes.skipBytes(RESERVED_F_LENGTH);
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
- builder.setTlvs(tlvsBuilder.build());
- return builder.build();
+ return new NoPathBuilder()
+ .setIgnore(header.isIgnore())
+ .setProcessingRule(header.isProcessingRule())
+ .setNatureOfIssue(issue)
+ .setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET))
+ .setTlvs(tlvsBuilder.build())
+ .build();
}
@Override
object.getClass());
final NoPath nPObj = (NoPath) object;
final ByteBuf body = Unpooled.buffer();
- checkArgument(nPObj.getNatureOfIssue() != null, "NatureOfIssue is mandatory.");
- writeUnsignedByte(nPObj.getNatureOfIssue(), body);
+ ByteBufUtils.writeMandatory(body, nPObj.getNatureOfIssue(), "NatureOfIssue");
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
flags.toByteBuf(body);
}
public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
- if (tlvs == null) {
- return;
- }
- if (tlvs.getNoPathVector() != null) {
- serializeTlv(tlvs.getNoPathVector(), body);
+ if (tlvs != null) {
+ if (tlvs.getNoPathVector() != null) {
+ serializeTlv(tlvs.getNoPathVector(), body);
+ }
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
@Override