/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.protocol.pcep.parser.subobject; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.XROSubobjectParser; import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer; import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase; /** * Parser for {@link AsNumberCase} */ public class XROAsNumberSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer { public static final int TYPE = 32; @Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { return new SubobjectBuilder().setMandatory(mandatory).setSubobjectType(AsNumberCaseParser.parseSubobject(buffer)).build(); } @Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { Preconditions.checkArgument(subobject.getSubobjectType() instanceof AsNumberCase, "Unknown subobject instance. Passed %s. Needed AsNumberCase.", subobject.getSubobjectType().getClass()); final ByteBuf body = AsNumberCaseParser.serializeSubobject((AsNumberCase) subobject.getSubobjectType()); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); } }