Author: rhs
Date: Mon Oct  8 18:29:39 2012
New Revision: 1395706

URL: http://svn.apache.org/viewvc?rev=1395706&view=rev
Log:
tweaked data interface for easier swigging

Modified:
    qpid/proton/trunk/proton-c/bindings/python/proton.py
    qpid/proton/trunk/proton-c/bindings/python/python.i
    qpid/proton/trunk/proton-c/include/proton/codec.h
    qpid/proton/trunk/proton-c/include/proton/cproton.i
    qpid/proton/trunk/proton-c/src/codec/codec.c
    qpid/proton/trunk/tests/proton_tests/codec.py

Modified: qpid/proton/trunk/proton-c/bindings/python/proton.py
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/python/proton.py?rev=1395706&r1=1395705&r2=1395706&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/proton.py (original)
+++ qpid/proton/trunk/proton-c/bindings/python/proton.py Mon Oct  8 18:29:39 
2012
@@ -707,9 +707,9 @@ class Data:
     type. If there is no next sibling the current node remains
     unchanged and None is returned.
     """
-    found, dtype = pn_data_next(self._data)
+    found = pn_data_next(self._data)
     if found:
-      return dtype
+      return self.type()
     else:
       return None
 
@@ -719,9 +719,9 @@ class Data:
     type. If there is no previous sibling the current node remains
     unchanged and None is returned.
     """
-    found, dtype = pn_data_prev(self._data)
+    found = pn_data_prev(self._data)
     if found:
-      return dtype
+      return self.type()
     else:
       return None
 
@@ -738,6 +738,16 @@ class Data:
     """
     return pn_data_exit(self._data)
 
+  def type(self):
+    """
+    Returns the type of the current node.
+    """
+    dtype = pn_data_type(self._data)
+    if dtype == -1:
+      return None
+    else:
+      return dtype
+
   def encode(self):
     """
     Returns a representation of the data encoded in AMQP format.
@@ -1011,8 +1021,8 @@ class Data:
   def get_list(self):
     """
     If the current node is a list, return the number of elements,
-    otherwise raise an error. List elements can be accessed by
-    entering the list.
+    otherwise return zero. List elements can be accessed by entering
+    the list.
 
       >>> count = data.get_list()
       >>> data.enter()
@@ -1024,15 +1034,13 @@ class Data:
       ...     ...
       >>> data.exit()
     """
-    err, count = pn_data_get_list(self._data)
-    self._check(err)
-    return count
+    return pn_data_get_list(self._data)
 
   def get_map(self):
     """
     If the current node is a map, return the number of child elements,
-    otherwise raise an error. Key value pairs can be accessed by
-    entering the map.
+    otherwise return zero. Key value pairs can be accessed by entering
+    the map.
 
       >>> count = data.get_map()
       >>> data.enter()
@@ -1044,16 +1052,14 @@ class Data:
       ...     ...
       >>> data.exit()
     """
-    err, count = pn_data_get_map(self._data)
-    self._check(err)
-    return count
+    return pn_data_get_map(self._data)
 
   def get_array(self):
     """
     If the current node is an array, return a tuple of the element
     count, a boolean indicating whether the array is described, and
-    the type of each element. Array data can be accessed by entering
-    the array.
+    the type of each element, otherwise return (0, False, None). Array
+    data can be accessed by entering the array.
 
       >>> # read an array of strings with a symbolic descriptor
       >>> count, described, type = data.get_array()
@@ -1065,214 +1071,178 @@ class Data:
       ...    print "Element:", data.get_string()
       >>> data.exit()
     """
-    err, count, described, type = pn_data_get_array(self._data)
-    self._check(err)
+    count = pn_data_get_array(self._data)
+    described = pn_data_is_array_described(self._data)
+    type = pn_data_get_array_type(self._data)
+    if type == -1:
+      type = None
     return count, described, type
 
-  def get_described(self):
+  def is_described(self):
     """
-    Checks if the current node is a described value, raises an
-    exception otherwise. The descriptor and value may be accessed by
-    entering the described value.
+    Checks if the current node is a described value. The descriptor
+    and value may be accessed by entering the described value.
 
       >>> # read a symbolically described string
-      >>> data.get_described() # will error if the current node is not 
described
+      >>> assert data.is_described() # will error if the current node is not 
described
       >>> data.enter()
       >>> print data.get_symbol()
       >>> print data.get_string()
       >>> data.exit()
     """
-    self._check(pn_data_get_described(self._data))
+    return pn_data_is_described(self._data)
 
-  def get_null(self):
+  def is_null(self):
     """
-    Checks if the current node is a null, raises an exception
-    otherwise.
+    Checks if the current node is a null.
     """
     self._check(pn_data_get_null(self._data))
 
   def get_bool(self):
     """
-    If the current node is a boolean, returns its value, raises an
-    exception otherwise.
+    If the current node is a boolean, returns its value, returns False
+    otherwise.
     """
-    err, b = pn_data_get_bool(self._data)
-    self._check(err)
-    return b
+    return pn_data_get_bool(self._data)
 
   def get_ubyte(self):
     """
-    If the current node is an unsigned byte, returns its value, raises
-    an exception otherwise.
+    If the current node is an unsigned byte, returns its value,
+    returns 0 otherwise.
     """
-    err, value = pn_data_get_ubyte(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_ubyte(self._data)
 
   def get_byte(self):
     """
-    If the current node is a signed byte, returns its value, raises an
-    exception otherwise.
+    If the current node is a signed byte, returns its value, returns 0
+    otherwise.
     """
-    err, value = pn_data_get_byte(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_byte(self._data)
 
   def get_ushort(self):
     """
     If the current node is an unsigned short, returns its value,
-    raises an exception otherwise.
+    returns 0 otherwise.
     """
-    err, value = pn_data_get_ushort(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_ushort(self._data)
 
   def get_short(self):
     """
-    If the current node is a signed short, returns its value, raises
-    an exception otherwise.
+    If the current node is a signed short, returns its value, returns
+    0 otherwise.
     """
-    err, value = pn_data_get_short(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_short(self._data)
 
   def get_uint(self):
     """
-    If the current node is an unsigned int, returns its value, raises
-    an exception otherwise.
+    If the current node is an unsigned int, returns its value, returns
+    0 otherwise.
     """
-    err, value = pn_data_get_uint(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_uint(self._data)
 
   def get_int(self):
     """
-    If the current node is a signed int, returns its value, raises an
-    exception otherwise.
+    If the current node is a signed int, returns its value, returns 0
+    otherwise.
     """
-    err, value = pn_data_get_int(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_int(self._data)
 
   def get_char(self):
     """
-    If the current node is a char, returns its value, raises an
-    exception otherwise.
+    If the current node is a char, returns its value, returns 0
+    otherwise.
     """
-    err, value = pn_data_get_char(self._data)
-    self._check(err)
-    return unichr(value)
+    return unichr(pn_data_get_char(self._data))
 
   def get_ulong(self):
     """
-    If the current node is an unsigned long, returns its value, raises
-    an exception otherwise.
+    If the current node is an unsigned long, returns its value,
+    returns 0 otherwise.
     """
-    err, value = pn_data_get_ulong(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_ulong(self._data)
 
   def get_long(self):
     """
-    If the current node is an signed long, returns its value, raises
-    an exception otherwise.
+    If the current node is an signed long, returns its value, returns
+    0 otherwise.
     """
-    err, value = pn_data_get_long(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_long(self._data)
 
   def get_timestamp(self):
     """
-    If the current node is a timestamp, returns its value, raises
-    an exception otherwise.
+    If the current node is a timestamp, returns its value, returns 0
+    otherwise.
     """
-    err, value = pn_data_get_timestamp(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_timestamp(self._data)
 
   def get_float(self):
     """
-    If the current node is a float, returns its value, raises an
-    exception otherwise.
+    If the current node is a float, returns its value, raises 0
+    otherwise.
     """
-    err, value = pn_data_get_float(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_float(self._data)
 
   def get_double(self):
     """
-    If the current node is a double, returns its value, raises an
-    exception otherwise.
+    If the current node is a double, returns its value, returns 0
+    otherwise.
     """
-    err, value = pn_data_get_double(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_double(self._data)
 
   # XXX: need to convert
   def get_decimal32(self):
     """
-    If the current node is a decimal32, returns its value, raises an
-    exception otherwise.
+    If the current node is a decimal32, returns its value, returns 0
+    otherwise.
     """
-    err, value = pn_data_get_decimal32(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_decimal32(self._data)
 
   # XXX: need to convert
   def get_decimal64(self):
     """
-    If the current node is a decimal64, returns its value, raises an
-    exception otherwise.
+    If the current node is a decimal64, returns its value, returns 0
+    otherwise.
     """
-    err, value = pn_data_get_decimal64(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_decimal64(self._data)
 
   # XXX: need to convert
   def get_decimal128(self):
     """
-    If the current node is a decimal128, returns its value, raises an
-    exception otherwise.
+    If the current node is a decimal128, returns its value, returns 0
+    otherwise.
     """
-    err, value = pn_data_get_decimal128(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_decimal128(self._data)
 
   def get_uuid(self):
     """
-    If the current node is a UUID, returns its value, raises an
-    exception otherwise.
+    If the current node is a UUID, returns its value, returns None
+    otherwise.
     """
-    err, value = pn_data_get_uuid(self._data)
-    self._check(err)
-    return uuid.UUID(bytes=value)
+    if pn_data_type(self._data) == Data.UUID:
+      return uuid.UUID(bytes=pn_data_get_uuid(self._data))
+    else:
+      return None
 
   def get_binary(self):
     """
-    If the current node is binary, returns its value, raises an
-    exception otherwise.
+    If the current node is binary, returns its value, returns ""
+    otherwise.
     """
-    err, value = pn_data_get_binary(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_binary(self._data)
 
   def get_string(self):
     """
-    If the current node is a string, returns its value, raises an
-    exception otherwise.
+    If the current node is a string, returns its value, returns ""
+    otherwise.
     """
-    err, value = pn_data_get_string(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_string(self._data)
 
   def get_symbol(self):
     """
-    If the current node is a symbol, returns its value, raises an
-    exception otherwise.
+    If the current node is a symbol, returns its value, returns ""
+    otherwise.
     """
-    err, value = pn_data_get_symbol(self._data)
-    self._check(err)
-    return value
+    return pn_data_get_symbol(self._data)
 
   def dump(self):
     pn_data_dump(self._data)

Modified: qpid/proton/trunk/proton-c/bindings/python/python.i
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/python/python.i?rev=1395706&r1=1395705&r2=1395706&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/python.i (original)
+++ qpid/proton/trunk/proton-c/bindings/python/python.i Mon Oct  8 18:29:39 2012
@@ -9,13 +9,6 @@
 #include <proton/ssl.h>
 %}
 
-typedef unsigned int size_t;
-typedef signed int ssize_t;
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
-typedef unsigned long int uint64_t;
-typedef int int32_t;
-
 %include <cstring.i>
 
 %cstring_output_withsize(char *OUTPUT, size_t *OUTPUT_SIZE)
@@ -38,14 +31,6 @@ typedef int int32_t;
   $result = PyString_FromStringAndSize($1.start, $1.size);
 }
 
-%typemap(in, numinputs=0) pn_bytes_t * (pn_bytes_t temp) {
-  $1 = &temp;
-}
-
-%typemap(argout) pn_bytes_t * {
-  $result = Py_BuildValue("NN", $result, 
PyString_FromStringAndSize(temp$argnum.start, temp$argnum.size));
-}
-
 %typemap(in) pn_decimal128_t {
   memmove($1.bytes, PyString_AsString($input), 16);
 }
@@ -54,14 +39,6 @@ typedef int int32_t;
   $result = PyString_FromStringAndSize($1.bytes, 16);
 }
 
-%typemap(in, numinputs=0) pn_decimal128_t * (pn_decimal128_t temp) {
-  $1 = &temp;
-}
-
-%typemap(argout) pn_decimal128_t * {
-  $result = Py_BuildValue("NN", $result, 
PyString_FromStringAndSize(temp$argnum.bytes, 16));
-}
-
 %typemap(in) pn_uuid_t {
   memmove($1.bytes, PyString_AsString($input), 16);
 }
@@ -70,14 +47,6 @@ typedef int int32_t;
   $result = PyString_FromStringAndSize($1.bytes, 16);
 }
 
-%typemap(in, numinputs=0) pn_uuid_t * (pn_uuid_t temp) {
-  $1 = &temp;
-}
-
-%typemap(argout) pn_uuid_t * {
-  $result = Py_BuildValue("NN", $result, 
PyString_FromStringAndSize(temp$argnum.bytes, 16));
-}
-
 int pn_message_load(pn_message_t *msg, char *STRING, size_t LENGTH);
 %ignore pn_message_load;
 

Modified: qpid/proton/trunk/proton-c/include/proton/codec.h
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/include/proton/codec.h?rev=1395706&r1=1395705&r2=1395706&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/include/proton/codec.h (original)
+++ qpid/proton/trunk/proton-c/include/proton/codec.h Mon Oct  8 18:29:39 2012
@@ -105,11 +105,13 @@ int pn_data_scan(pn_data_t *data, const 
 void pn_data_clear(pn_data_t *data);
 size_t pn_data_size(pn_data_t *data);
 void pn_data_rewind(pn_data_t *data);
-bool pn_data_next(pn_data_t *data, pn_type_t *type);
-bool pn_data_prev(pn_data_t *data, pn_type_t *type);
+bool pn_data_next(pn_data_t *data);
+bool pn_data_prev(pn_data_t *data);
 bool pn_data_enter(pn_data_t *data);
 bool pn_data_exit(pn_data_t *data);
 
+pn_type_t pn_data_type(pn_data_t *data);
+
 int pn_data_print(pn_data_t *data);
 int pn_data_format(pn_data_t *data, char *bytes, size_t *size);
 ssize_t pn_data_encode(pn_data_t *data, char *bytes, size_t size);
@@ -141,31 +143,33 @@ int pn_data_put_binary(pn_data_t *data, 
 int pn_data_put_string(pn_data_t *data, pn_bytes_t string);
 int pn_data_put_symbol(pn_data_t *data, pn_bytes_t symbol);
 
-int pn_data_get_list(pn_data_t *data, size_t *count);
-int pn_data_get_map(pn_data_t *data, size_t *count);
-int pn_data_get_array(pn_data_t *data, size_t *count, bool *described, 
pn_type_t *type);
-int pn_data_get_described(pn_data_t *data);
-int pn_data_get_null(pn_data_t *data);
-int pn_data_get_bool(pn_data_t *data, bool *b);
-int pn_data_get_ubyte(pn_data_t *data, uint8_t *ub);
-int pn_data_get_byte(pn_data_t *data, int8_t *b);
-int pn_data_get_ushort(pn_data_t *data, uint16_t *us);
-int pn_data_get_short(pn_data_t *data, int16_t *s);
-int pn_data_get_uint(pn_data_t *data, uint32_t *ui);
-int pn_data_get_int(pn_data_t *data, int32_t *i);
-int pn_data_get_char(pn_data_t *data, pn_char_t *c);
-int pn_data_get_ulong(pn_data_t *data, uint64_t *ul);
-int pn_data_get_long(pn_data_t *data, int64_t *l);
-int pn_data_get_timestamp(pn_data_t *data, pn_timestamp_t *l);
-int pn_data_get_float(pn_data_t *data, float *f);
-int pn_data_get_double(pn_data_t *data, double *d);
-int pn_data_get_decimal32(pn_data_t *data, pn_decimal32_t *d);
-int pn_data_get_decimal64(pn_data_t *data, pn_decimal64_t *d);
-int pn_data_get_decimal128(pn_data_t *data, pn_decimal128_t *d);
-int pn_data_get_uuid(pn_data_t *data, pn_uuid_t *u);
-int pn_data_get_binary(pn_data_t *data, pn_bytes_t *bytes);
-int pn_data_get_string(pn_data_t *data, pn_bytes_t *string);
-int pn_data_get_symbol(pn_data_t *data, pn_bytes_t *symbol);
+size_t pn_data_get_list(pn_data_t *data);
+size_t pn_data_get_map(pn_data_t *data);
+size_t pn_data_get_array(pn_data_t *data);
+bool pn_data_is_array_described(pn_data_t *data);
+pn_type_t pn_data_get_array_type(pn_data_t *data);
+bool pn_data_is_described(pn_data_t *data);
+bool pn_data_is_null(pn_data_t *data);
+bool pn_data_get_bool(pn_data_t *data);
+uint8_t pn_data_get_ubyte(pn_data_t *data);
+int8_t pn_data_get_byte(pn_data_t *data);
+uint16_t pn_data_get_ushort(pn_data_t *data);
+int16_t pn_data_get_short(pn_data_t *data);
+uint32_t pn_data_get_uint(pn_data_t *data);
+int32_t pn_data_get_int(pn_data_t *data);
+pn_char_t pn_data_get_char(pn_data_t *data);
+uint64_t pn_data_get_ulong(pn_data_t *data);
+int64_t pn_data_get_long(pn_data_t *data);
+pn_timestamp_t pn_data_get_timestamp(pn_data_t *data);
+float pn_data_get_float(pn_data_t *data);
+double pn_data_get_double(pn_data_t *data);
+pn_decimal32_t pn_data_get_decimal32(pn_data_t *data);
+pn_decimal64_t pn_data_get_decimal64(pn_data_t *data);
+pn_decimal128_t pn_data_get_decimal128(pn_data_t *data);
+pn_uuid_t pn_data_get_uuid(pn_data_t *data);
+pn_bytes_t pn_data_get_binary(pn_data_t *data);
+pn_bytes_t pn_data_get_string(pn_data_t *data);
+pn_bytes_t pn_data_get_symbol(pn_data_t *data);
 
 void pn_data_dump(pn_data_t *data);
 

Modified: qpid/proton/trunk/proton-c/include/proton/cproton.i
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/include/proton/cproton.i?rev=1395706&r1=1395705&r2=1395706&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/include/proton/cproton.i (original)
+++ qpid/proton/trunk/proton-c/include/proton/cproton.i Mon Oct  8 18:29:39 2012
@@ -1,3 +1,11 @@
+typedef unsigned int size_t;
+typedef signed int ssize_t;
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+typedef unsigned long int uint64_t;
+typedef int int32_t;
+typedef long int int64_t;
+
 /* Parse these interface header files to generate APIs for script languages */
 %include "proton/types.h"
 %ignore pn_error_format;
@@ -1303,19 +1311,4 @@
 %ignore pn_data_vfill;
 %ignore pn_data_vscan;
 
-%include <typemaps.i>
-%apply int *OUTPUT {pn_type_t *type};
-%apply bool *OUTPUT {bool *};
-%apply unsigned char *OUTPUT {uint8_t *};
-%apply signed char *OUTPUT {int8_t *};
-%apply unsigned short *OUTPUT {uint16_t *};
-%apply short *OUTPUT {int16_t *};
-%apply unsigned int *OUTPUT {uint32_t *};
-%apply int *OUTPUT {int32_t *};
-%apply uint64_t *OUTPUT {uint64_t *};
-%apply long *OUTPUT {int64_t *};
-%apply float *OUTPUT {float *};
-%apply double *OUTPUT {double *};
-%apply size_t *OUTPUT {size_t *count};
-
 %include "proton/codec.h"

Modified: qpid/proton/trunk/proton-c/src/codec/codec.c
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/codec/codec.c?rev=1395706&r1=1395705&r2=1395706&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/codec/codec.c (original)
+++ qpid/proton/trunk/proton-c/src/codec/codec.c Mon Oct  8 18:29:39 2012
@@ -2138,8 +2138,9 @@ int pn_data_fill(pn_data_t *data, const 
 static bool pn_scan_next(pn_data_t *data, pn_type_t *type, bool suspend)
 {
   if (suspend) return false;
-  bool found = pn_data_next(data, type);
+  bool found = pn_data_next(data);
   if (found) {
+    *type = pn_data_type(data);
     return true;
   } else {
     pn_node_t *parent = pn_data_node(data, data->parent);
@@ -2147,6 +2148,7 @@ static bool pn_scan_next(pn_data_t *data
       pn_data_exit(data);
       return pn_scan_next(data, type, suspend);
     } else {
+      *type = -1;
       return false;
     }
   }
@@ -2185,7 +2187,7 @@ int pn_data_vscan(pn_data_t *data, const
         bool *value = va_arg(ap, bool *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_BOOL) {
-          pn_data_get_bool(data, value);
+          *value = pn_data_get_bool(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2199,7 +2201,7 @@ int pn_data_vscan(pn_data_t *data, const
         uint8_t *value = va_arg(ap, uint8_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_UBYTE) {
-          pn_data_get_ubyte(data, value);
+          *value = pn_data_get_ubyte(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2213,7 +2215,7 @@ int pn_data_vscan(pn_data_t *data, const
         int8_t *value = va_arg(ap, int8_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_BYTE) {
-          pn_data_get_byte(data, value);
+          *value = pn_data_get_byte(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2227,7 +2229,7 @@ int pn_data_vscan(pn_data_t *data, const
         uint16_t *value = va_arg(ap, uint16_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_USHORT) {
-          pn_data_get_ushort(data, value);
+          *value = pn_data_get_ushort(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2241,7 +2243,7 @@ int pn_data_vscan(pn_data_t *data, const
         int16_t *value = va_arg(ap, int16_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_SHORT) {
-          pn_data_get_short(data, value);
+          *value = pn_data_get_short(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2255,7 +2257,7 @@ int pn_data_vscan(pn_data_t *data, const
         uint32_t *value = va_arg(ap, uint32_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_UINT) {
-          pn_data_get_uint(data, value);
+          *value = pn_data_get_uint(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2269,7 +2271,7 @@ int pn_data_vscan(pn_data_t *data, const
         int32_t *value = va_arg(ap, int32_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_INT) {
-          pn_data_get_int(data, value);
+          *value = pn_data_get_int(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2283,7 +2285,7 @@ int pn_data_vscan(pn_data_t *data, const
         pn_char_t *value = va_arg(ap, pn_char_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_CHAR) {
-          pn_data_get_char(data, value);
+          *value = pn_data_get_char(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2297,7 +2299,7 @@ int pn_data_vscan(pn_data_t *data, const
         uint64_t *value = va_arg(ap, uint64_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_ULONG) {
-          pn_data_get_ulong(data, value);
+          *value = pn_data_get_ulong(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2311,7 +2313,7 @@ int pn_data_vscan(pn_data_t *data, const
         int64_t *value = va_arg(ap, int64_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_LONG) {
-          pn_data_get_long(data, value);
+          *value = pn_data_get_long(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2325,7 +2327,7 @@ int pn_data_vscan(pn_data_t *data, const
         pn_timestamp_t *value = va_arg(ap, pn_timestamp_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_TIMESTAMP) {
-          pn_data_get_timestamp(data, value);
+          *value = pn_data_get_timestamp(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2339,7 +2341,7 @@ int pn_data_vscan(pn_data_t *data, const
         float *value = va_arg(ap, float *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_FLOAT) {
-          pn_data_get_float(data, value);
+          *value = pn_data_get_float(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2353,7 +2355,7 @@ int pn_data_vscan(pn_data_t *data, const
         double *value = va_arg(ap, double *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_DOUBLE) {
-          pn_data_get_double(data, value);
+          *value = pn_data_get_double(data);
           scanned = true;
         } else {
           *value = 0;
@@ -2367,7 +2369,7 @@ int pn_data_vscan(pn_data_t *data, const
         pn_bytes_t *bytes = va_arg(ap, pn_bytes_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_BINARY) {
-          pn_data_get_binary(data, bytes);
+          *bytes = pn_data_get_binary(data);
           scanned = true;
         } else {
           *bytes = (pn_bytes_t) {0, 0};
@@ -2381,7 +2383,7 @@ int pn_data_vscan(pn_data_t *data, const
         pn_bytes_t *bytes = va_arg(ap, pn_bytes_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_STRING) {
-          pn_data_get_string(data, bytes);
+          *bytes = pn_data_get_string(data);
           scanned = true;
         } else {
           *bytes = (pn_bytes_t) {0, 0};
@@ -2395,7 +2397,7 @@ int pn_data_vscan(pn_data_t *data, const
         pn_bytes_t *bytes = va_arg(ap, pn_bytes_t *);
         found = pn_scan_next(data, &type, suspend);
         if (found && type == PN_SYMBOL) {
-          pn_data_get_symbol(data, bytes);
+          *bytes = pn_data_get_symbol(data);
           scanned = true;
         } else {
           *bytes = (pn_bytes_t) {0, 0};
@@ -2585,7 +2587,7 @@ pn_node_t *pn_data_current(pn_data_t *da
   return pn_data_node(data, data->current);
 }
 
-bool pn_data_next(pn_data_t *data, pn_type_t *type)
+bool pn_data_next(pn_data_t *data)
 {
   pn_node_t *current = pn_data_current(data);
   pn_node_t *parent = pn_data_node(data, data->parent);
@@ -2598,35 +2600,38 @@ bool pn_data_next(pn_data_t *data, pn_ty
   } else if (!parent && data->size) {
     next = 1;
   } else {
-    *type = -1;
     return false;
   }
 
   if (next) {
     data->current = next;
-    current = pn_data_current(data);
-    *type = current->atom.type;
     return true;
   } else {
-    *type = -1;
     return false;
   }
 }
 
-bool pn_data_prev(pn_data_t *data, pn_type_t *type)
+bool pn_data_prev(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->prev) {
     data->current = node->prev;
-    pn_node_t *prev = pn_data_current(data);
-    *type = prev->atom.type;
     return true;
   } else {
-    *type = -1;
     return false;
   }
 }
 
+pn_type_t pn_data_type(pn_data_t *data)
+{
+  pn_node_t *node = pn_data_current(data);
+  if (node) {
+    return node->atom.type;
+  } else {
+    return -1;
+  }
+}
+
 bool pn_data_enter(pn_data_t *data)
 {
   if (data->current) {
@@ -3190,306 +3195,268 @@ int pn_data_put_symbol(pn_data_t *data, 
   return pn_data_intern_node(data, node);
 }
 
-int pn_data_get_list(pn_data_t *data, size_t *count)
+size_t pn_data_get_list(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_LIST) {
-    *count = node->children;
-    return 0;
+    return node->children;
   } else {
-    *count = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_map(pn_data_t *data, size_t *count)
+size_t pn_data_get_map(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_MAP) {
-    *count = node->children;
-    return 0;
+    return node->children;
   } else {
-    *count = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_array(pn_data_t *data, size_t *count, bool *described, 
pn_type_t *type)
+size_t pn_data_get_array(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_ARRAY) {
     if (node->described) {
-      *count = node->children - 1;
-      *described = true;
+      return node->children - 1;
     } else {
-      *count = node->children;
-      *described = false;
+      return node->children;
     }
-    *type = node->type;
-    return 0;
   } else {
-    *count = 0;
-    return PN_ERR;
+    return 0;
   }
-  return PN_ERR;
 }
 
-int pn_data_get_described(pn_data_t *data)
+bool pn_data_is_array_described(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node && node->atom.type == PN_DESCRIPTOR) {
-    return 0;
+  if (node && node->atom.type == PN_ARRAY) {
+    return node->described;
   } else {
-    return PN_ERR;
+    return false;
   }
 }
 
-int pn_data_get_null(pn_data_t *data)
+pn_type_t pn_data_get_array_type(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node && node->atom.type == PN_NULL) {
-    return 0;
+  if (node && node->atom.type == PN_ARRAY) {
+    return node->type;
   } else {
-    return PN_ERR;
+    return -1;
   }
 }
 
-int pn_data_get_bool(pn_data_t *data, bool *b)
+bool pn_data_is_described(pn_data_t *data)
+{
+  pn_node_t *node = pn_data_current(data);
+  return node && node->atom.type == PN_DESCRIPTOR;
+}
+
+bool pn_data_is_null(pn_data_t *data)
+{
+  pn_node_t *node = pn_data_current(data);
+  return node && node->atom.type == PN_NULL;
+}
+
+bool pn_data_get_bool(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_BOOL) {
-    *b = node->atom.u.as_bool;
-    return 0;
+    return node->atom.u.as_bool;
   } else {
-    *b = false;
-    return PN_ERR;
+    return false;
   }
 }
 
-int pn_data_get_ubyte(pn_data_t *data, uint8_t *ub)
+uint8_t pn_data_get_ubyte(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_UBYTE) {
-    *ub = node->atom.u.as_ubyte;
-    return 0;
+    return node->atom.u.as_ubyte;
   } else {
-    *ub = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_byte(pn_data_t *data, int8_t *b)
+int8_t pn_data_get_byte(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_BYTE) {
-    *b = node->atom.u.as_byte;
-    return 0;
+    return node->atom.u.as_byte;
   } else {
-    *b = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_ushort(pn_data_t *data, uint16_t *us)
+uint16_t pn_data_get_ushort(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_USHORT) {
-    *us = node->atom.u.as_ushort;
-    return 0;
+    return node->atom.u.as_ushort;
   } else {
-    *us = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_short(pn_data_t *data, int16_t *s)
+int16_t pn_data_get_short(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_SHORT) {
-    *s = node->atom.u.as_short;
-    return 0;
+    return node->atom.u.as_short;
   } else {
-    *s = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_uint(pn_data_t *data, uint32_t *ui)
+uint32_t pn_data_get_uint(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
   if (node && node->atom.type == PN_UINT) {
-    *ui = node->atom.u.as_uint;
-    return 0;
+    return node->atom.u.as_uint;
   } else {
-    *ui = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_int(pn_data_t *data, int32_t *i)
+int32_t pn_data_get_int(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_INT) {
-    *i = node->atom.u.as_int;
-    return 0;
+  if (node && node->atom.type == PN_INT) {
+    return node->atom.u.as_int;
   } else {
-    *i = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_char(pn_data_t *data, pn_char_t *c)
+pn_char_t pn_data_get_char(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_CHAR) {
-    *c = node->atom.u.as_char;
-    return 0;
+  if (node && node->atom.type == PN_CHAR) {
+    return node->atom.u.as_char;
   } else {
-    *c = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_ulong(pn_data_t *data, uint64_t *ul)
+uint64_t pn_data_get_ulong(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_ULONG) {
-    *ul = node->atom.u.as_ulong;
-    return 0;
+  if (node && node->atom.type == PN_ULONG) {
+    return node->atom.u.as_ulong;
   } else {
-    *ul = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_long(pn_data_t *data, int64_t *l)
+int64_t pn_data_get_long(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_LONG) {
-    *l = node->atom.u.as_long;
-    return 0;
+  if (node && node->atom.type == PN_LONG) {
+    return node->atom.u.as_long;
   } else {
-    *l = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_timestamp(pn_data_t *data, pn_timestamp_t *t)
+pn_timestamp_t pn_data_get_timestamp(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_TIMESTAMP) {
-    *t = node->atom.u.as_timestamp;
-    return 0;
+  if (node && node->atom.type == PN_TIMESTAMP) {
+    return node->atom.u.as_timestamp;
   } else {
-    *t = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_float(pn_data_t *data, float *f)
+float pn_data_get_float(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_FLOAT) {
-    *f = node->atom.u.as_float;
-    return 0;
+  if (node && node->atom.type == PN_FLOAT) {
+    return node->atom.u.as_float;
   } else {
-    *f = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_double(pn_data_t *data, double *d)
+double pn_data_get_double(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_DOUBLE) {
-    *d = node->atom.u.as_double;
-    return 0;
+  if (node && node->atom.type == PN_DOUBLE) {
+    return node->atom.u.as_double;
   } else {
-    *d = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_decimal32(pn_data_t *data, pn_decimal32_t *d)
+pn_decimal32_t pn_data_get_decimal32(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_DECIMAL32) {
-    *d = node->atom.u.as_decimal32;
-    return 0;
+  if (node && node->atom.type == PN_DECIMAL32) {
+    return node->atom.u.as_decimal32;
   } else {
-    *d = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_decimal64(pn_data_t *data, pn_decimal64_t *d)
+pn_decimal64_t pn_data_get_decimal64(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_DECIMAL64) {
-    *d = node->atom.u.as_decimal64;
-    return 0;
+  if (node && node->atom.type == PN_DECIMAL64) {
+    return node->atom.u.as_decimal64;
   } else {
-    *d = 0;
-    return PN_ERR;
+    return 0;
   }
 }
 
-int pn_data_get_decimal128(pn_data_t *data, pn_decimal128_t *d)
+pn_decimal128_t pn_data_get_decimal128(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_DECIMAL128) {
-    memmove(d->bytes, node->atom.u.as_decimal128.bytes, 16);
-    return 0;
+  if (node && node->atom.type == PN_DECIMAL128) {
+    return node->atom.u.as_decimal128;
   } else {
-    memset(d->bytes, 0, 16);
-    return PN_ERR;
+    return (pn_decimal128_t) {{0}};
   }
 }
 
-int pn_data_get_uuid(pn_data_t *data, pn_uuid_t *u)
+pn_uuid_t pn_data_get_uuid(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_UUID) {
-    memmove(u->bytes, node->atom.u.as_uuid.bytes, 16);
-    return 0;
+  if (node && node->atom.type == PN_UUID) {
+    return node->atom.u.as_uuid;
   } else {
-    memset(u->bytes, 0, 16);
-    return PN_ERR;
+    return (pn_uuid_t) {{0}};
   }
 }
 
-int pn_data_get_binary(pn_data_t *data, pn_bytes_t *bytes)
+pn_bytes_t pn_data_get_binary(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_BINARY) {
-    *bytes = node->atom.u.as_binary;
-    return 0;
+  if (node && node->atom.type == PN_BINARY) {
+    return node->atom.u.as_binary;
   } else {
-    *bytes = (pn_bytes_t) {0};
-    return PN_ERR;
+    return (pn_bytes_t) {0};
   }
 }
 
-int pn_data_get_string(pn_data_t *data, pn_bytes_t *string)
+pn_bytes_t pn_data_get_string(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_STRING) {
-    *string = node->atom.u.as_string;
-    return 0;
+  if (node && node->atom.type == PN_STRING) {
+    return node->atom.u.as_string;
   } else {
-    *string = (pn_bytes_t) {0};
-    return PN_ERR;
+    return (pn_bytes_t) {0};
   }
 }
 
-int pn_data_get_symbol(pn_data_t *data, pn_bytes_t *symbol)
+pn_bytes_t pn_data_get_symbol(pn_data_t *data)
 {
   pn_node_t *node = pn_data_current(data);
-  if (node->atom.type == PN_SYMBOL) {
-    *symbol = node->atom.u.as_symbol;
-    return 0;
+  if (node && node->atom.type == PN_SYMBOL) {
+    return node->atom.u.as_symbol;
   } else {
-    *symbol = (pn_bytes_t) {0};
-    return PN_ERR;
+    return (pn_bytes_t) {0};
   }
 }

Modified: qpid/proton/trunk/tests/proton_tests/codec.py
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/tests/proton_tests/codec.py?rev=1395706&r1=1395705&r2=1395706&view=diff
==============================================================================
--- qpid/proton/trunk/tests/proton_tests/codec.py (original)
+++ qpid/proton/trunk/tests/proton_tests/codec.py Mon Oct  8 18:29:39 2012
@@ -117,6 +117,62 @@ class DataTest(Test):
     assert self.data.get_list() == 1
     assert not self.data.exit()
 
+  def _testArray(self, dtype, descriptor, atype, *values):
+    if dtype: dTYPE = getattr(self.data, dtype.upper())
+    aTYPE = getattr(self.data, atype.upper())
+    self.data.put_array(dtype is not None, aTYPE)
+    self.data.enter()
+    if dtype is not None:
+      putter = getattr(self.data, "put_%s" % dtype)
+      putter(descriptor)
+    putter = getattr(self.data, "put_%s" % atype)
+    for v in values:
+      putter(v)
+    self.data.exit()
+    self.data.rewind()
+    assert self.data.next() == Data.ARRAY
+    count, described, type = self.data.get_array()
+    assert count == len(values), count
+    if dtype is None:
+      assert described == False
+    else:
+      assert described == True
+    assert type == aTYPE, type
+    assert self.data.enter()
+    if described:
+      assert self.data.next() == dTYPE
+      getter = getattr(self.data, "get_%s" % dtype)
+      gotten = getter()
+      assert gotten == descriptor, gotten
+    if values:
+      getter = getattr(self.data, "get_%s" % atype)
+      for v in values:
+        assert self.data.next() == aTYPE
+        gotten = getter()
+        assert gotten == v, gotten
+    assert self.data.next() is None
+    assert self.data.exit()
+
+  def testStringArray(self):
+    self._testArray(None, None, "string", "one", "two", "three")
+
+  def testDescribedStringArray(self):
+    self._testArray("symbol", "url", "string", "one", "two", "three")
+
+  def testIntArray(self):
+    self._testArray(None, None, "int", 1, 2, 3)
+
+  def testUUIDArray(self):
+    self._testArray(None, None, "uuid", uuid3(NAMESPACE_OID, "one"),
+                    uuid3(NAMESPACE_OID, "one"),
+                    uuid3(NAMESPACE_OID, "three"))
+
+  def testEmptyArray(self):
+    self._testArray(None, None, "null")
+
+  def testDescribedEmptyArray(self):
+    self._testArray("long", 0, "null")
+
   def _test(self, dtype, *values, **kwargs):
     eq=kwargs.get("eq", lambda x, y: x == y)
     ntype = getattr(Data, dtype.upper())



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to