Bug-1771: Private constuctors in utility static classes throws UnsupportedOperationEx...
[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 java.util.BitSet;
12 import org.opendaylight.protocol.util.ByteArray;
13
14 public final class ObjectUtil {
15
16     private static final int HEADER_SIZE = 4;
17
18     private static final int OT_SF_LENGTH = 4;
19     /*
20      * flags offsets inside multi-field
21      */
22     private static final int P_FLAG_OFFSET = 6;
23     private static final int I_FLAG_OFFSET = 7;
24
25     private ObjectUtil() {
26         throw new UnsupportedOperationException();
27     }
28
29     public static void formatSubobject(final int objectType, final int objectClass, final Boolean processingRule, final Boolean ignore,
30         final ByteBuf body, final ByteBuf out) {
31         out.writeByte(objectClass);
32         BitSet flags = new BitSet(Byte.SIZE);
33         if (ignore != null) {
34             flags.set(I_FLAG_OFFSET, ignore);
35         }
36         if (processingRule != null) {
37             flags.set(P_FLAG_OFFSET, processingRule);
38         }
39         byte[] flagB = ByteArray.bitSetToBytes(flags, 1);
40         int typeByte = objectType << OT_SF_LENGTH | flagB[0];
41         out.writeByte(typeByte);
42         out.writeShort(body.writerIndex() + HEADER_SIZE);
43         out.writeBytes(body);
44     }
45 }