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.object;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
15 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
16 import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.Rro;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.RroBuilder;
23 * Parser for {@link Rro}.
25 public final class PCEPReportedRouteObjectParser extends AbstractRROWithSubobjectsParser {
26 public static final int CLASS = 8;
27 public static final int TYPE = 1;
29 public PCEPReportedRouteObjectParser(final RROSubobjectRegistry subobjReg) {
30 super(subobjReg, CLASS, TYPE);
34 public Rro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
35 checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
36 return new RroBuilder()
37 .setIgnore(header.getIgnore())
38 .setProcessingRule(header.getProcessingRule())
39 .setSubobject(parseSubobjects(bytes.slice()))
44 public void serializeObject(final Object object, final ByteBuf buffer) {
45 checkArgument(object instanceof Rro, "Wrong instance of PCEPObject. Passed %s. Needed RroObject.",
47 final Rro obj = (Rro) object;
48 final ByteBuf body = Unpooled.buffer();
49 serializeSubobject(obj.getSubobject(), body);
50 ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);