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.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-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.close.object.CClose;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.c.close.TlvsBuilder;
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
* }.
*/
public final class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<TlvsBuilder> {
-
private static final int CLASS = 15;
private static final int TYPE = 1;
super(tlvReg, viTlvReg, CLASS, TYPE);
}
-
@Override
public CClose 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 CClose obj = (CClose) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(RESERVED + FLAGS_F_LENGTH);
- checkArgument(obj.getReason() != null, "Reason is mandatory.");
- writeUnsignedByte(obj.getReason(), body);
+ ByteBufUtils.writeMandatory(body, obj.getReason(), "Reason");
serializeTlvs(obj.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
- if (tlvs == null) {
- return;
+ if (tlvs != null) {
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
- serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
}
-
@Override
protected void addVendorInformationTlvs(final TlvsBuilder builder, final List<VendorInformationTlv> tlvs) {
if (!tlvs.isEmpty()) {