fee3fdaa3bdbb11fc3ea0558c9776b82613295cf
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / tlv / PredundancyGroupTlvParser.java
1 /*
2  * Copyright (c) 2013 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.impl.tlv;
9
10 import org.opendaylight.protocol.pcep.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.types.rev131005.Tlv;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.predundancy.group.id.tlv.PredundancyGroupId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.predundancy.group.id.tlv.PredundancyGroupIdBuilder;
16
17 /**
18  * Parser for {@link PredundancyGroupId}
19  */
20 public class PredundancyGroupTlvParser implements TlvParser, TlvSerializer {
21
22         public static final int TYPE = 24;
23
24         @Override
25         public PredundancyGroupId parseTlv(final byte[] buffer) throws PCEPDeserializerException {
26                 return new PredundancyGroupIdBuilder().setIdentifier(buffer).build();
27         }
28
29         @Override
30         public byte[] serializeTlv(final Tlv tlv) {
31                 if (tlv == null) {
32                         throw new IllegalArgumentException("PredundancyGroupIdTlv is mandatory.");
33                 }
34                 final PredundancyGroupId pgt = (PredundancyGroupId) tlv;
35                 return pgt.getIdentifier();
36         }
37
38         @Override
39         public int getType() {
40                 return TYPE;
41         }
42 }