2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.sync.optimizations;
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
14 import org.opendaylight.protocol.pcep.spi.TlvParser;
15 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
16 import org.opendaylight.protocol.pcep.spi.TlvUtil;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.speaker.entity.id.tlv.SpeakerEntityId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.speaker.entity.id.tlv.SpeakerEntityIdBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
22 public class SpeakerEntityIdTlvParser implements TlvParser, TlvSerializer {
24 public static final int TYPE = 24;
27 public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
28 Preconditions.checkArgument(tlv instanceof SpeakerEntityId, "Tlv object is not instance of SpeakerEntityId.");
29 final ByteBuf body = Unpooled.buffer();
30 body.writeBytes(((SpeakerEntityId) tlv).getSpeakerEntityIdValue());
31 TlvUtil.formatTlv(TYPE, body, buffer);
35 public Tlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
39 return new SpeakerEntityIdBuilder().setSpeakerEntityIdValue(ByteArray.readAllBytes(buffer)).build();