- protected final void parseTlvs(final T builder, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null, "Array of bytes is mandatory. Can't be null.");
- if (!bytes.isReadable()) {
- return;
- }
- while (bytes.isReadable()) {
- int type = bytes.readUnsignedShort();
- 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);
- LOG.trace("Attempt to parse tlv from bytes: {}", ByteBufUtil.hexDump(tlvBytes));
- final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes);
- LOG.trace("Tlv was parsed. {}", tlv);
- addTlv(builder, tlv);
- bytes.readerIndex(bytes.readerIndex() + length + getPadding(TLV_HEADER_LENGTH + length, PADDED_TO));
- }
- }
+ protected final void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
+ requireNonNull(tlv, "PCEP TLV is mandatory.");
+ LOG.trace("Serializing PCEP TLV {}", tlv);
+ this.tlvReg.serializeTlv(tlv, buffer);
+ LOG.trace("Serialized PCEP TLV : {}.", ByteBufUtil.hexDump(buffer));
+ }