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