2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.impl.subobject;
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;
21 * Parser for {@link AsNumberCase}
23 public class XROAsNumberSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
25 public static final int TYPE = 32;
28 public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
29 return new SubobjectBuilder().setMandatory(mandatory).setSubobjectType(AsNumberCaseParser.parseSubobject(buffer)).build();
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);