Enable restart of CSS modules on blueprint container restart
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / PCEPReportedRouteObjectParser.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.parser.object;
9
10 import com.google.common.base.Preconditions;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14
15 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
16 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
17 import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
22
23 /**
24  * Parser for {@link Rro}
25  */
26 public class PCEPReportedRouteObjectParser extends AbstractRROWithSubobjectsParser {
27
28     public static final int CLASS = 8;
29
30     public static final int TYPE = 1;
31
32     public PCEPReportedRouteObjectParser(final RROSubobjectRegistry subobjReg) {
33         super(subobjReg);
34     }
35
36     @Override
37     public Rro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
38         Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
39         final RroBuilder builder = new RroBuilder();
40         builder.setIgnore(header.isIgnore());
41         builder.setProcessingRule(header.isProcessingRule());
42         builder.setSubobject(parseSubobjects(bytes.slice()));
43         return builder.build();
44     }
45
46     @Override
47     public void serializeObject(final Object object, final ByteBuf buffer) {
48         Preconditions.checkArgument(object instanceof Rro, "Wrong instance of PCEPObject. Passed %s. Needed RroObject.", object.getClass());
49         final Rro obj = (Rro) object;
50         final ByteBuf body = Unpooled.buffer();
51         serializeSubobject(obj.getSubobject(), body);
52         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
53     }
54 }