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