2 * Copyright (c) 2013 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 io.netty.buffer.ByteBuf;
11 import java.util.BitSet;
12 import org.opendaylight.protocol.util.ByteArray;
14 public final class ObjectUtil {
16 private static final int HEADER_SIZE = 4;
18 private static final int OT_SF_LENGTH = 4;
20 * flags offsets inside multi-field
22 private static final int P_FLAG_OFFSET = 6;
23 private static final int I_FLAG_OFFSET = 7;
25 private ObjectUtil() {
26 throw new UnsupportedOperationException();
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);
34 flags.set(I_FLAG_OFFSET, ignore);
36 if (processingRule != null) {
37 flags.set(P_FLAG_OFFSET, processingRule);
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);