Promote MessageRegistry to pcep-api
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / 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.parser.tlv;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
15 import org.opendaylight.protocol.pcep.spi.TlvParser;
16 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
17 import org.opendaylight.protocol.pcep.spi.TlvUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.RequestId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.req.missing.tlv.ReqMissing;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.req.missing.tlv.ReqMissingBuilder;
22 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
23
24 /**
25  * Parser {@link ReqMissing}.
26  */
27 public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
28     public static final int TYPE = 3;
29
30     @Override
31     public ReqMissing parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
32         if (buffer == null) {
33             return null;
34         }
35         return new ReqMissingBuilder().setRequestId(new RequestId(ByteBufUtils.readUint32(buffer))).build();
36     }
37
38     @Override
39     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
40         checkArgument(tlv instanceof ReqMissing, "ReqMissingTlv is mandatory.");
41         final ReqMissing req = (ReqMissing) tlv;
42         final ByteBuf body = Unpooled.buffer();
43
44         final RequestId reqId = req.getRequestId();
45         checkArgument(reqId != null, "RequestId is mandatory.");
46         ByteBufUtils.write(body, reqId.getValue());
47         TlvUtil.formatTlv(TYPE, body, buffer);
48     }
49 }