Bump odlparent/yangtools/mdsal/controller
[bgpcep.git] / pcep / ietf-stateful / src / main / java / org / opendaylight / protocol / pcep / sync / optimizations / SpeakerEntityIdTlvParser.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.sync.optimizations;
9
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;
21
22 public class SpeakerEntityIdTlvParser implements TlvParser, TlvSerializer {
23
24     public static final int TYPE = 24;
25
26     @Override
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);
32     }
33
34     @Override
35     public Tlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
36         if (buffer == null) {
37             return null;
38         }
39         return new SpeakerEntityIdBuilder().setSpeakerEntityIdValue(ByteArray.readAllBytes(buffer)).build();
40     }
41
42 }