@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
- final SubobjectBuilder builder = new SubobjectBuilder();
- builder.setLoose(loose);
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject> list = parseSubobject(buffer);
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.Exrs> exrss = new ArrayList<>();
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject s : list) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder();
- b.setAttribute(s.getAttribute());
- b.setMandatory(s.isMandatory());
- b.setSubobjectType(s.getSubobjectType());
- exrss.add(b.build());
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(),
+ "Array of bytes is mandatory. Can't be null or empty.");
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude
+ .route.object.xro.Subobject> xros = parseSubobject(buffer);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit
+ .route.subobjects.subobject.type.exrs._case.exrs.Exrs> exrss = new ArrayList<>();
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude
+ .route.object.xro.Subobject xro : xros) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820
+ .explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder exrsBuilder =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820
+ .explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder()
+ .setAttribute(xro.getAttribute())
+ .setMandatory(xro.isMandatory())
+ .setSubobjectType(xro.getSubobjectType());
+ exrss.add(exrsBuilder.build());
}
- builder.setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(exrss).build()).build());
+ final SubobjectBuilder builder = new SubobjectBuilder()
+ .setLoose(loose)
+ .setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(exrss).build()).build());
return builder.build();
}
- @Override
- public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof ExrsCase, "Unknown subobject instance. Passed %s. Needed Exrs.", subobject.getSubobjectType().getClass());
- final Exrs e = ((ExrsCase) subobject.getSubobjectType()).getExrs();
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject> list = new ArrayList<>();
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.Exrs ex : e.getExrs()) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder();
- b.setAttribute(ex.getAttribute());
- b.setMandatory(ex.isMandatory());
- b.setSubobjectType(ex.getSubobjectType());
- list.add(b.build());
- }
- final ByteBuf body = Unpooled.buffer();
- serializeSubobject(list, body);
- EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
- }
-
- private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject> parseSubobject(
- final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject> subs = new ArrayList<>();
+ private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude
+ .route.object.xro.Subobject> parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(),
+ "Array of bytes is mandatory. Can't be null or empty.");
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude
+ .route.object.xro.Subobject> xros = new ArrayList<>();
while (buffer.isReadable()) {
- final boolean mandatory = ((buffer.getByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
- final int type = (buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET);
+ final boolean mandatory =
+ ((buffer.getByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
+ final int type =
+ (buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET);
final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
if (length > buffer.readableBytes()) {
throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
+ buffer.readableBytes());
}
- subs.add(this.registry.parseSubobject(type, buffer.readSlice(length), mandatory));
+ xros.add(this.registry.parseSubobject(type, buffer.readSlice(length), mandatory));
}
- return subs;
+ return xros;
+ }
+
+ @Override
+ public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof ExrsCase,
+ "Unknown subobject instance. Passed %s. Needed Exrs.", subobject.getSubobjectType().getClass());
+ final Exrs exrs = ((ExrsCase) subobject.getSubobjectType()).getExrs();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude
+ .route.object.xro.Subobject> xros = new ArrayList<>();
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit
+ .route.subobjects.subobject.type.exrs._case.exrs.Exrs exr : exrs.getExrs()) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
+ .exclude.route.object.xro.SubobjectBuilder xroBuilder =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
+ .exclude.route.object.xro.SubobjectBuilder()
+ .setAttribute(exr.getAttribute())
+ .setMandatory(exr.isMandatory())
+ .setSubobjectType(exr.getSubobjectType());
+ xros.add(xroBuilder.build());
+ }
+ final ByteBuf body = Unpooled.buffer();
+ serializeSubobject(xros, body);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
}
private void serializeSubobject(
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject> subobjects, final ByteBuf body) {
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject subobject : subobjects) {
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude
+ .route.object.xro.Subobject> subobjects, final ByteBuf body) {
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude
+ .route.object.xro.Subobject subobject : subobjects) {
this.registry.serializeSubobject(subobject, body);
}
}