BUG-2794 : refactored code to use BitArray
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / LabelUtil.java
1 /*
2  * Copyright (c) 2014 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 LabelUtil {
14
15     private static final int FLAGS_SIZE = 8;
16
17     private static final int UNIDIRECTIONAL = 0;
18     private static final int GLOBAL = 7;
19
20     private LabelUtil() {
21         throw new UnsupportedOperationException();
22     }
23
24     public static void formatLabel(final int type, final Boolean unidirectional, final Boolean global, final ByteBuf body, final ByteBuf buffer) {
25         final BitArray reserved = new BitArray(FLAGS_SIZE);
26         reserved.set(UNIDIRECTIONAL, unidirectional);
27         reserved.set(GLOBAL, global);
28         reserved.toByteBuf(buffer);
29         buffer.writeByte(type);
30         buffer.writeBytes(body);
31     }
32 }