3e7097fa923ac5585bd815fdac1d5cbf93a754ec
[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 org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.spi.TlvParser;
12 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathName;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathNameBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
16
17 /**
18  * Parser for {@link SymbolicPathName}
19  */
20 public class Stateful02LspSymbolicNameTlvParser implements TlvParser, TlvSerializer {
21
22         public static final int TYPE = 17;
23
24         @Override
25         public SymbolicPathName parseTlv(final byte[] buffer) throws PCEPDeserializerException {
26                 return new SymbolicPathNameBuilder().setPathName(
27                                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.SymbolicPathName(buffer)).build();
28         }
29
30         @Override
31         public byte[] serializeTlv(final Tlv tlv) {
32                 if (tlv == null) {
33                         throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
34                 }
35                 final SymbolicPathName spn = (SymbolicPathName) tlv;
36                 return spn.getPathName().getValue();
37         }
38
39         @Override
40         public int getType() {
41                 return TYPE;
42         }
43 }