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.parser.subobject;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
14 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
15 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
16 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
22 * Parser for {@link AsNumberCase}.
24 public class EROAsNumberSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
26 public static final int TYPE = 32;
29 public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
30 return new SubobjectBuilder().setLoose(loose).setSubobjectType(AsNumberCaseParser.parseSubobject(buffer))
35 public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
36 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 EROSubobjectUtil.formatSubobject(TYPE, subobject.getLoose(), body, buffer);