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