*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
-
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import java.util.BitSet;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
import org.opendaylight.protocol.pcep.spi.TlvUtil;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.Stateful;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
public static final int TYPE = 16;
- protected static final int FLAGS_F_LENGTH = 4;
+ protected static final int FLAGS_F_LENGTH = 32;
protected static final int U_FLAG_OFFSET = 31;
if (buffer == null) {
return null;
}
- if (buffer.readableBytes() < FLAGS_F_LENGTH) {
+ if (buffer.readableBytes() < FLAGS_F_LENGTH / Byte.SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
- + FLAGS_F_LENGTH + ".");
+ + FLAGS_F_LENGTH / Byte.SIZE + ".");
}
- final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
-
+ final BitArray flags = BitArray.valueOf(buffer, FLAGS_F_LENGTH);
final StatefulBuilder sb = new StatefulBuilder();
sb.setLspUpdateCapability(flags.get(U_FLAG_OFFSET));
return sb.build();
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
final Stateful sct = (Stateful) tlv;
- final ByteBuf body = Unpooled.buffer();
- final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
- if (sct.isLspUpdateCapability() != null) {
- flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
- }
- writeBitSet(flags, FLAGS_F_LENGTH, body);
- TlvUtil.formatTlv(TYPE, body, buffer);
+ final BitArray flags = new BitArray(FLAGS_F_LENGTH);
+ flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
+ TlvUtil.formatTlv(TYPE, Unpooled.wrappedBuffer(flags.array()), buffer);
}
}