BUG-47 : unfinished PCEP migration to generated DTOs.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / tlv / LspDbVersionTlvParser.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 java.math.BigInteger;
11
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.spi.TlvParser;
14 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
15 import org.opendaylight.protocol.util.ByteArray;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.LspDbVersionBuilder;
19
20 /**
21  * Parser for {@link LspDbVersionTlv}
22  */
23 public class LspDbVersionTlvParser implements TlvParser, TlvSerializer {
24
25         public static final int TYPE = 23;
26
27         private static final int DBV_F_LENGTH = 8;
28
29         @Override
30         public LspDbVersionTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
31                 return new LspDbVersionBuilder().setVersion(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, DBV_F_LENGTH)))).build();
32         }
33
34         @Override
35         public byte[] serializeTlv(final Tlv tlv) {
36                 if (tlv == null)
37                         throw new IllegalArgumentException("LspDbVersionTlv is mandatory.");
38                 final LspDbVersionTlv lsp = (LspDbVersionTlv) tlv;
39                 return ByteArray.subByte(lsp.getVersion().toByteArray(), 0, DBV_F_LENGTH);
40         }
41
42         @Override
43         public int getType() {
44                 return TYPE;
45         }
46 }