- // public PCEPExcludeRouteObjectParser(final HandlerRegistry registry) {
- // super(registry);
- // }
- //
- // @Override
- // public ExcludeRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws
- // PCEPDeserializerException,
- // PCEPDocumentedException {
- // if (bytes == null || bytes.length == 0)
- // throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
- //
- // final ExcludeRouterBuilder builder = new ExcludeRouterBuilder();
- //
- // builder.setIgnore(header.isIgnore());
- // builder.setProcessingRule(header.isProcessingRule());
- // // FIXME: add subobjects
- // return builder.build();
- // }
- //
- // @Override
- // public void addTlv(final ExcludeRouterBuilder builder, final Tlv tlv) {
- // // No tlvs defined
- // }
- //
- // @Override
- // public byte[] serializeObject(final Object object) {
- // if (!(object instanceof ExcludeRouteObject))
- // throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() +
- // ". Needed ExcludeRouteObject.");
- //
- // assert !(((ExcludeRouteObject) object).getSubobjects().isEmpty()) : "Empty Excluded Route Object.";
- //
- // // return PCEPEROSubobjectParser.put(((ExplicitRouteObject) obj).getSubobjects());
- //
- // // FIXME: add subobjects
- // return null;
- // }
- //
- // @Override
- // public int getObjectType() {
- // return TYPE;
- // }
- //
- // @Override
- // public int getObjectClass() {
- // return CLASS;
- // }
+ private static final int FLAGS_OFFSET = 3;
+
+ public PCEPExcludeRouteObjectParser(final XROSubobjectHandlerRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public ExcludeRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
+ PCEPDocumentedException {
+ if (bytes == null || bytes.length == 0) {
+ throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
+ }
+ final XroBuilder builder = new XroBuilder();
+ builder.setIgnore(header.isIgnore());
+ builder.setProcessingRule(header.isProcessingRule());
+ builder.setFlags(new Flags(UnsignedBytes.toInt(bytes[FLAGS_OFFSET]) != 0));
+ builder.setSubobjects(parseSubobjects(ByteArray.cutBytes(bytes, FLAGS_OFFSET + 1)));
+ return builder.build();
+ }
+
+ @Override
+ public byte[] serializeObject(final Object object) {
+ if (!(object instanceof ExcludeRouteObject)) {
+ throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed ExcludeRouteObject.");
+ }
+ final ExcludeRouteObject obj = (ExcludeRouteObject) object;
+ assert !(obj.getSubobjects().isEmpty()) : "Empty Excluded Route Object.";
+ final byte[] bytes = serializeSubobject(obj.getSubobjects());
+ final byte[] result = new byte[FLAGS_OFFSET + 1 + bytes.length];
+ if (obj.getFlags().isFail()) {
+ result[FLAGS_OFFSET] = 1;
+ }
+ ByteArray.copyWhole(bytes, result, FLAGS_OFFSET + 1);
+ return result;
+ }
+
+ @Override
+ public int getObjectType() {
+ return TYPE;
+ }
+
+ @Override
+ public int getObjectClass() {
+ return CLASS;
+ }