Fix checkstyle
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / PCEPExplicitRouteObjectParser.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 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
14 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
15 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.EroBuilder;
20
21 /**
22  * Parser for {@link Ero}.
23  */
24 public final class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsParser {
25     private static final int CLASS = 7;
26     private static final int TYPE = 1;
27
28     public PCEPExplicitRouteObjectParser(final EROSubobjectRegistry subobjReg) {
29         super(subobjReg, CLASS, TYPE);
30     }
31
32     @Override
33     public Ero parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
34         // Explicit approval of empty ERO
35         Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
36         final EroBuilder builder = new EroBuilder()
37                 .setIgnore(header.isIgnore())
38                 .setProcessingRule(header.isProcessingRule())
39                 .setSubobject(parseSubobjects(buffer));
40         return builder.build();
41     }
42
43     @Override
44     public void serializeObject(final Object object, final ByteBuf buffer) {
45         Preconditions.checkArgument(object instanceof Ero,
46             "Wrong instance of PCEPObject. Passed %s. Needed EroObject.", object.getClass());
47         final Ero ero = ((Ero) object);
48         final ByteBuf body = Unpooled.buffer();
49         serializeSubobject(ero.getSubobject(), body);
50         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
51     }
52 }