Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / subobject / EROAsNumberSubobjectParser.java
index 7ef9fe05c8f5ad1c2c9b9a5e8f3c2ae29d52c4ba..60d14e968031bf766ca0d376bd8cb9ced4e2fbb2 100644 (file)
@@ -8,53 +8,42 @@
 package org.opendaylight.protocol.pcep.impl.subobject;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.SubobjectParser;
-import org.opendaylight.protocol.pcep.spi.SubobjectSerializer;
+import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject;
+import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.route.subobjects.subobject.type.AsNumberBuilder;
 
 /**
- * Parser for {@link AsNumberSubobject}
+ * Parser for {@link org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject EROAsNumberSubobject}
  */
 
-public class EROAsNumberSubobjectParser implements SubobjectParser, SubobjectSerializer {
-       
-       public static final int TYPE = 32;
-       
-       public static final int AS_NUMBER_LENGTH = 4;
+public class EROAsNumberSubobjectParser {
+       public static final int AS_NUMBER_LENGTH = 2;
 
        public static final int AS_NUMBER_OFFSET = 0;
 
        public static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET;
 
-       public AsNumberSubobject parseSubobject(byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+       public static EROAsNumberSubobject parse(final byte[] soContentsBytes, final boolean loose) throws PCEPDeserializerException {
+               if (soContentsBytes == null || soContentsBytes.length == 0)
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+               if (soContentsBytes.length != CONTENT_LENGTH)
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: "
                                        + CONTENT_LENGTH + ".");
 
-               return new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build();
+               return new EROAsNumberSubobject(new AsNumber((long) (ByteArray.bytesToShort(soContentsBytes) & 0xFFFF)), loose);
        }
 
-       public byte[] serializeSubobject(CSubobject subobject) {
-               if (!(subobject instanceof AsNumberSubobject))
-                       throw new IllegalArgumentException("Unknown subobject instance. Passed " + subobject.getClass()
-                                       + ". Needed AsNumberSubobject.");
+       public static byte[] put(final ExplicitRouteSubobject objToSerialize) {
+               if (!(objToSerialize instanceof EROAsNumberSubobject))
+                       throw new IllegalArgumentException("Unknown ExplicitRouteSubobject instance. Passed " + objToSerialize.getClass()
+                                       + ". Needed EROAsNumberSubobject.");
 
                final byte[] retBytes = new byte[CONTENT_LENGTH];
 
-               System.arraycopy(ByteArray.longToBytes(((AsNumberSubobject) subobject).getAsNumber().getValue()), Long.SIZE / Byte.SIZE
+               System.arraycopy(ByteArray.longToBytes(((EROAsNumberSubobject) objToSerialize).getASNumber().getValue()), Long.SIZE / Byte.SIZE
                                - AS_NUMBER_LENGTH, retBytes, AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
 
                return retBytes;
        }
-
-       @Override
-       public int getType() {
-               return TYPE;
-       }
 }