2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.spi;
10 import java.util.BitSet;
12 import org.opendaylight.protocol.util.ByteArray;
14 import com.google.common.primitives.UnsignedBytes;
16 public final class LabelUtil {
18 private static final int RES_F_LENGTH = 1;
20 private static final int C_TYPE_F_LENGTH = 1;
22 private static final int RES_F_OFFSET = 0;
24 private static final int C_TYPE_F_OFFSET = RES_F_OFFSET + RES_F_LENGTH;
26 private static final int HEADER_LENGTH = C_TYPE_F_OFFSET + C_TYPE_F_LENGTH;
28 private static final int U_FLAG_OFFSET = 0;
30 private static final int G_FLAG_OFFSET = 7;
33 throw new UnsupportedOperationException("Utility class should not be instantiated");
36 public static byte[] formatLabel(final int type, final boolean unidirectional, final boolean global, final byte[] labelbytes) {
38 final byte[] retBytes = new byte[labelbytes.length + HEADER_LENGTH];
40 System.arraycopy(labelbytes, 0, retBytes, HEADER_LENGTH, labelbytes.length);
42 final BitSet reserved = new BitSet();
43 reserved.set(U_FLAG_OFFSET, unidirectional);
44 reserved.set(G_FLAG_OFFSET, global);
45 System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
46 retBytes[C_TYPE_F_OFFSET] = UnsignedBytes.checkedCast(type);