import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
-
import java.util.List;
-
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
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.vendor.information.tlvs.VendorInformationTlv;
private static final Logger LOG = LoggerFactory.getLogger(AbstractObjectWithTlvsParser.class);
- public static final int PADDED_TO = 4;
-
private final TlvRegistry tlvReg;
private final VendorInformationTlvRegistry viTlvReg;
}
final List<VendorInformationTlv> viTlvs = Lists.newArrayList();
while (bytes.isReadable()) {
- int type = bytes.readUnsignedShort();
- int length = bytes.readUnsignedShort();
+ final int type = bytes.readUnsignedShort();
+ final int length = bytes.readUnsignedShort();
if (length > bytes.readableBytes()) {
throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes()
+ ".");
}
- final ByteBuf tlvBytes = bytes.slice(bytes.readerIndex(), length);
+ final ByteBuf tlvBytes = bytes.readSlice(length);
LOG.trace("Parsing PCEP TLV : {}", ByteBufUtil.hexDump(tlvBytes));
if (VendorInformationUtil.isVendorInformationTlv(type)) {
addTlv(builder, tlv);
}
}
- bytes.skipBytes(length + TlvUtil.getPadding(TlvUtil.HEADER_SIZE + length, TlvUtil.PADDED_TO));
+ bytes.skipBytes(TlvUtil.getPadding(TlvUtil.HEADER_SIZE + length, TlvUtil.PADDED_TO));
}
addVendorInformationTlvs(builder, viTlvs);
}
// FIXME: No TLVs by default, fallback to augments
}
- abstract protected void addVendorInformationTlvs(final T builder, final List<VendorInformationTlv> tlvs);
+ protected abstract void addVendorInformationTlvs(final T builder, final List<VendorInformationTlv> tlvs);
protected final void serializeVendorInformationTlvs(final List<VendorInformationTlv> tlvs, final ByteBuf buffer) {
- if (tlvs != null && !tlvs.isEmpty()) {
+ if (tlvs != null) {
for (final VendorInformationTlv tlv : tlvs) {
LOG.trace("Serializing VENDOR-INFORMATION TLV {}", tlv);
this.viTlvReg.serializeVendorInformationTlv(tlv, buffer);