BUG-612 : switched PCEP Tlvs to ByteBuf
[bgpcep.git] / pcep / ietf-stateful02 / src / main / java / org / opendaylight / protocol / pcep / ietf / stateful02 / Stateful02LspSymbolicNameTlvParser.java
1 /*
2  * Copyright (c) 2014 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.ietf.stateful02;
9
10 import io.netty.buffer.ByteBuf;
11
12 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
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.util.ByteArray;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathName;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathNameBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
20
21 /**
22  * Parser for {@link SymbolicPathName}
23  */
24 public final class Stateful02LspSymbolicNameTlvParser implements TlvParser, TlvSerializer {
25
26         public static final int TYPE = 17;
27
28         @Override
29         public SymbolicPathName parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
30                 if (buffer == null) {
31                         return null;
32                 }
33                 return new SymbolicPathNameBuilder().setPathName(
34                                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.SymbolicPathName(ByteArray.readAllBytes(buffer))).build();
35         }
36
37         @Override
38         public byte[] serializeTlv(final Tlv tlv) {
39                 if (tlv == null) {
40                         throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
41                 }
42                 final SymbolicPathName spn = (SymbolicPathName) tlv;
43                 return TlvUtil.formatTlv(TYPE, spn.getPathName().getValue());
44         }
45 }