org.opendaylight.protocol.pcep.sync.optimizations.SpeakerEntityIdTlvParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pcep-ietf-stateful Show documentation
Show all versions of pcep-ietf-stateful Show documentation
PCE IETF Stateful model plugin
/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.protocol.pcep.sync.optimizations;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
import org.opendaylight.protocol.pcep.spi.TlvUtil;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.speaker.entity.id.tlv.SpeakerEntityId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.speaker.entity.id.tlv.SpeakerEntityIdBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
public class SpeakerEntityIdTlvParser implements TlvParser, TlvSerializer {
public static final int TYPE = 24;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof SpeakerEntityId, "Tlv object is not instance of SpeakerEntityId.");
final ByteBuf body = Unpooled.buffer();
body.writeBytes(((SpeakerEntityId) tlv).getSpeakerEntityIdValue());
TlvUtil.formatTlv(TYPE, body, buffer);
}
@Override
public Tlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
if (buffer == null) {
return null;
}
return new SpeakerEntityIdBuilder().setSpeakerEntityIdValue(ByteArray.readAllBytes(buffer)).build();
}
}