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