Add new revision for pcep types model
[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         throw new UnsupportedOperationException();
26     }
27
28     public static void formatSubobject(final int objectType, final int objectClass, final Boolean processingRule, final Boolean ignore,
29         final ByteBuf body, final ByteBuf out) {
30         out.writeByte(objectClass);
31         final BitArray flags = new BitArray(FLAGS_SIZE);
32         flags.set(IGNORED, ignore);
33         flags.set(PROCESSED, processingRule);
34         final byte flagB = flags.toByte();
35         final int typeByte = objectType << FLAGS_SIZE | (flagB & 0xff);
36         out.writeByte(typeByte);
37         out.writeShort(body.writerIndex() + HEADER_SIZE);
38         out.writeBytes(body);
39     }
40 }