import com.google.common.primitives.UnsignedBytes;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.BitSet;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
+import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
private static final int COMMON_OBJECT_HEADER_LENGTH = 4;
private static final int OT_SF_LENGTH = 4;
- private static final int FLAGS_SF_LENGTH = 4;
/*
* offsets of fields inside of multi-field in bits
*/
private static final int OT_SF_OFFSET = 0;
- private static final int FLAGS_SF_OFFSET = OT_SF_OFFSET + OT_SF_LENGTH;
/*
* flags offsets inside multi-filed
*/
- private static final int P_FLAG_OFFSET = 6;
- private static final int I_FLAG_OFFSET = 7;
+ private static final int PROCESSED = 6;
+ private static final int IGNORED = 7;
private final ObjectRegistry registry;
- private final VendorInformationObjectRegistry viRegistry;
protected AbstractMessageParser(final ObjectRegistry registry) {
this.registry = Preconditions.checkNotNull(registry);
- this.viRegistry = null;
- }
-
- protected AbstractMessageParser(final ObjectRegistry registry, final VendorInformationObjectRegistry viRegistry) {
- this.registry = Preconditions.checkNotNull(registry);
- this.viRegistry = Preconditions.checkNotNull(viRegistry);
}
/**
final int objClass = bytes.readUnsignedByte();
final byte flagsByte = bytes.readByte();
+ final BitArray flags = BitArray.valueOf(flagsByte);
final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(flagsByte, OT_SF_OFFSET, OT_SF_LENGTH));
- final byte[] flagsBytes = { ByteArray.copyBitsRange(flagsByte, FLAGS_SF_OFFSET, FLAGS_SF_LENGTH) };
- final BitSet flags = ByteArray.bytesToBitSet(flagsBytes);
-
final int objLength = bytes.readUnsignedShort();
if (bytes.readableBytes() < objLength - COMMON_OBJECT_HEADER_LENGTH) {
// copy bytes for deeper parsing
final ByteBuf bytesToPass = bytes.readSlice(objLength - COMMON_OBJECT_HEADER_LENGTH);
- final ObjectHeader header = new ObjectHeaderImpl(flags.get(P_FLAG_OFFSET), flags.get(I_FLAG_OFFSET));
+ final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED));
if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) {
- Preconditions.checkState(this.viRegistry != null);
final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(bytesToPass.readUnsignedInt());
- final Optional<? extends Object> obj = this.viRegistry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass);
+ final Optional<? extends Object> obj = this.registry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass);
if (obj.isPresent()) {
objs.add(obj.get());
}
rp.get()).build())).build()).build();
}
return new PcerrBuilder().setPcerrMessage(
- msgBuilder.setErrors(Arrays.asList(new ErrorsBuilder().setErrorObject(
- new ErrorObjectBuilder().setType(e.getErrorType()).setValue(
- e.getErrorValue()).build()).build())).build()).build();
+ msgBuilder.setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject(
+ new ErrorObjectBuilder().setType(e.getErrorType()).setValue(
+ e.getErrorValue()).build()).build())).build()).build();
}
protected abstract Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException;
protected final void serializeVendorInformationObjects(final List<VendorInformationObject> viObjects, final ByteBuf buffer) {
if (viObjects != null) {
for (final VendorInformationObject viObject : viObjects) {
- this.viRegistry.serializeVendorInformationObject(viObject, buffer);
+ this.registry.serializeVendorInformationObject(viObject, buffer);
}
}
}