Enforce pcep-spi checkstyle
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / ObjectUtil.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.spi;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.util.BitArray;
12
13 public final class ObjectUtil {
14
15     private static final int HEADER_SIZE = 4;
16
17     private static final int FLAGS_SIZE = 4;
18     /*
19      * flags offsets inside multi-field
20      */
21     private static final int PROCESSED = 2;
22     private static final int IGNORED = 3;
23
24     private ObjectUtil() {
25     }
26
27     public static void formatSubobject(final int objectType, final int objectClass, final Boolean processingRule,
28             final Boolean ignore, final ByteBuf body, final ByteBuf out) {
29         out.writeByte(objectClass);
30         final BitArray flags = new BitArray(FLAGS_SIZE);
31         flags.set(IGNORED, ignore);
32         flags.set(PROCESSED, processingRule);
33         final byte flagB = flags.toByte();
34         final int typeByte = objectType << FLAGS_SIZE | flagB & 0xff;
35         out.writeByte(typeByte);
36         out.writeShort(body.writerIndex() + HEADER_SIZE);
37         out.writeBytes(body);
38     }
39 }