Bump versions to 0.21.7-SNAPSHOT
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / subobject / XROAsNumberSubobjectParser.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.subobject;
9
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
14 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
15 import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
19
20 /**
21  * Parser for {@link AsNumberCase}.
22  */
23 public class XROAsNumberSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
24
25     public static final int TYPE = 32;
26
27     @Override
28     public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
29         return new SubobjectBuilder().setMandatory(mandatory)
30                 .setSubobjectType(AsNumberCaseParser.parseSubobject(buffer))
31                 .build();
32     }
33
34     @Override
35     public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
36         Preconditions.checkArgument(subobject.getSubobjectType() instanceof AsNumberCase,
37                 "Unknown subobject instance. Passed %s. Needed AsNumberCase.", subobject.getSubobjectType().getClass());
38         final ByteBuf body = AsNumberCaseParser.serializeSubobject((AsNumberCase) subobject.getSubobjectType());
39         XROSubobjectUtil.formatSubobject(TYPE, subobject.getMandatory(), body, buffer);
40     }
41 }