c6097933a5121af9aa0d679400f5ed32944b9fd5
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / 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.impl.subobject;
9
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.spi.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.rev131005.exclude.route.object.xro.Subobject;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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).setSubobjectType(AsNumberCaseParser.parseSubobject(buffer)).build();
30     }
31
32     @Override
33     public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
34         Preconditions.checkArgument(subobject.getSubobjectType() instanceof AsNumberCase, "Unknown subobject instance. Passed %s. Needed AsNumberCase.", subobject.getSubobjectType().getClass());
35         final ByteBuf body = AsNumberCaseParser.serializeSubobject((AsNumberCase) subobject.getSubobjectType());
36         XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
37     }
38 }