Author: rhs
Date: Mon Oct 8 13:34:01 2012
New Revision: 1395553
URL: http://svn.apache.org/viewvc?rev=1395553&view=rev
Log:
codec support for uuid and decimal types
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/types.h
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=1395553&r1=1395552&r2=1395553&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/proton.py (original)
+++ qpid/proton/trunk/proton-c/bindings/python/proton.py Mon Oct 8 13:34:01
2012
@@ -31,6 +31,7 @@ The proton APIs consist of the following
"""
from cproton import *
+import uuid
class ProtonException(Exception):
"""
@@ -667,6 +668,10 @@ class Data:
TIMESTAMP = PN_TIMESTAMP; "A timestamp value."
FLOAT = PN_FLOAT; "A float value."
DOUBLE = PN_DOUBLE; "A double value."
+ DECIMAL32 = PN_DECIMAL32; "A DECIMAL32 value."
+ DECIMAL64 = PN_DECIMAL64; "A DECIMAL64 value."
+ DECIMAL128 = PN_DECIMAL128; "A DECIMAL128 value."
+ UUID = PN_UUID; "A UUID value."
BINARY = PN_BINARY; "A binary string."
STRING = PN_STRING; "A unicode string."
SYMBOL = PN_SYMBOL; "A symbolic string."
@@ -944,6 +949,38 @@ class Data:
"""
self._check(pn_data_put_double(self._data, d))
+ def put_decimal32(self, d):
+ """
+ Puts a decimal32 value.
+
+ @param d: a decimal32 value
+ """
+ self._check(pn_data_put_decimal32(self._data, d))
+
+ def put_decimal64(self, d):
+ """
+ Puts a decimal64 value.
+
+ @param d: a decimal64 value
+ """
+ self._check(pn_data_put_decimal64(self._data, d))
+
+ def put_decimal128(self, d):
+ """
+ Puts a decimal128 value.
+
+ @param d: a decimal128 value
+ """
+ self._check(pn_data_put_decimal128(self._data, d))
+
+ def put_uuid(self, u):
+ """
+ Puts a UUID value.
+
+ @param u: a uuid value
+ """
+ self._check(pn_data_put_uuid(self._data, u.bytes))
+
def put_binary(self, b):
"""
Puts a binary value.
@@ -1171,6 +1208,45 @@ class Data:
self._check(err)
return value
+ # XXX: need to convert
+ def get_decimal32(self):
+ """
+ If the current node is a decimal32, returns its value, raises an
+ exception otherwise.
+ """
+ err, value = pn_data_get_decimal32(self._data)
+ self._check(err)
+ return value
+
+ # XXX: need to convert
+ def get_decimal64(self):
+ """
+ If the current node is a decimal64, returns its value, raises an
+ exception otherwise.
+ """
+ err, value = pn_data_get_decimal64(self._data)
+ self._check(err)
+ return value
+
+ # XXX: need to convert
+ def get_decimal128(self):
+ """
+ If the current node is a decimal128, returns its value, raises an
+ exception otherwise.
+ """
+ err, value = pn_data_get_decimal128(self._data)
+ self._check(err)
+ return value
+
+ def get_uuid(self):
+ """
+ If the current node is a UUID, returns its value, raises an
+ exception otherwise.
+ """
+ err, value = pn_data_get_uuid(self._data)
+ self._check(err)
+ return uuid.UUID(bytes=value)
+
def get_binary(self):
"""
If the current node is binary, returns its value, raises an
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=1395553&r1=1395552&r2=1395553&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/python/python.i (original)
+++ qpid/proton/trunk/proton-c/bindings/python/python.i Mon Oct 8 13:34:01 2012
@@ -46,6 +46,38 @@ typedef int int32_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);
+}
+
+%typemap(out) pn_decimal128_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);
+}
+
+%typemap(out) pn_uuid_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=1395553&r1=1395552&r2=1395553&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/include/proton/codec.h (original)
+++ qpid/proton/trunk/proton-c/include/proton/codec.h Mon Oct 8 13:34:01 2012
@@ -47,6 +47,10 @@ typedef enum {
PN_TIMESTAMP,
PN_FLOAT,
PN_DOUBLE,
+ PN_DECIMAL32,
+ PN_DECIMAL64,
+ PN_DECIMAL128,
+ PN_UUID,
PN_BINARY,
PN_STRING,
PN_SYMBOL,
@@ -73,6 +77,10 @@ typedef struct {
pn_timestamp_t as_timestamp;
float as_float;
double as_double;
+ pn_decimal32_t as_decimal32;
+ pn_decimal64_t as_decimal64;
+ pn_decimal128_t as_decimal128;
+ pn_uuid_t as_uuid;
pn_bytes_t as_binary;
pn_bytes_t as_string;
pn_bytes_t as_symbol;
@@ -125,6 +133,10 @@ int pn_data_put_long(pn_data_t *data, in
int pn_data_put_timestamp(pn_data_t *data, pn_timestamp_t t);
int pn_data_put_float(pn_data_t *data, float f);
int pn_data_put_double(pn_data_t *data, double d);
+int pn_data_put_decimal32(pn_data_t *data, pn_decimal32_t d);
+int pn_data_put_decimal64(pn_data_t *data, pn_decimal64_t d);
+int pn_data_put_decimal128(pn_data_t *data, pn_decimal128_t d);
+int pn_data_put_uuid(pn_data_t *data, pn_uuid_t u);
int pn_data_put_binary(pn_data_t *data, pn_bytes_t bytes);
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);
@@ -147,6 +159,10 @@ int pn_data_get_long(pn_data_t *data, in
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);
Modified: qpid/proton/trunk/proton-c/include/proton/types.h
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/include/proton/types.h?rev=1395553&r1=1395552&r2=1395553&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/include/proton/types.h (original)
+++ qpid/proton/trunk/proton-c/include/proton/types.h Mon Oct 8 13:34:01 2012
@@ -33,6 +33,14 @@ typedef int32_t pn_sequence_t;
typedef uint32_t pn_millis_t;
typedef uint64_t pn_timestamp_t;
typedef uint32_t pn_char_t;
+typedef uint32_t pn_decimal32_t;
+typedef uint64_t pn_decimal64_t;
+typedef struct {
+ char bytes[16];
+} pn_decimal128_t;
+typedef struct {
+ char bytes[16];
+} pn_uuid_t;
typedef struct {
size_t size;
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=1395553&r1=1395552&r2=1395553&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/codec/codec.c (original)
+++ qpid/proton/trunk/proton-c/src/codec/codec.c Mon Oct 8 13:34:01 2012
@@ -83,6 +83,10 @@ const char *pn_type_str(pn_type_t type)
case PN_TIMESTAMP: return "PN_TIMESTAMP";
case PN_FLOAT: return "PN_FLOAT";
case PN_DOUBLE: return "PN_DOUBLE";
+ case PN_DECIMAL32: return "PN_DECIMAL32";
+ case PN_DECIMAL64: return "PN_DECIMAL64";
+ case PN_DECIMAL128: return "PN_DECIMAL128";
+ case PN_UUID: return "PN_UUID";
case PN_BINARY: return "PN_BINARY";
case PN_STRING: return "PN_STRING";
case PN_SYMBOL: return "PN_SYMBOL";
@@ -167,6 +171,46 @@ int pn_format_atom(pn_bytes_t *bytes, pn
return pn_bytes_format(bytes, "%g", atom.u.as_float);
case PN_DOUBLE:
return pn_bytes_format(bytes, "%g", atom.u.as_double);
+ case PN_DECIMAL32:
+ return pn_bytes_format(bytes, "D32(%" PRIu32 ")", atom.u.as_decimal32);
+ case PN_DECIMAL64:
+ return pn_bytes_format(bytes, "D64(%" PRIu64 ")", atom.u.as_decimal64);
+ case PN_DECIMAL128:
+ return pn_bytes_format(bytes, "D128(%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x)",
+ atom.u.as_decimal128.bytes[0],
+ atom.u.as_decimal128.bytes[1],
+ atom.u.as_decimal128.bytes[2],
+ atom.u.as_decimal128.bytes[3],
+ atom.u.as_decimal128.bytes[4],
+ atom.u.as_decimal128.bytes[5],
+ atom.u.as_decimal128.bytes[6],
+ atom.u.as_decimal128.bytes[7],
+ atom.u.as_decimal128.bytes[8],
+ atom.u.as_decimal128.bytes[9],
+ atom.u.as_decimal128.bytes[10],
+ atom.u.as_decimal128.bytes[11],
+ atom.u.as_decimal128.bytes[12],
+ atom.u.as_decimal128.bytes[13],
+ atom.u.as_decimal128.bytes[14],
+ atom.u.as_decimal128.bytes[15]);
+ case PN_UUID:
+ return pn_bytes_format(bytes, "UUID(%x%x%x%x-%x%x-%x%x-%x%x-%x%x%x%x%x%x)",
+ atom.u.as_uuid.bytes[0],
+ atom.u.as_uuid.bytes[1],
+ atom.u.as_uuid.bytes[2],
+ atom.u.as_uuid.bytes[3],
+ atom.u.as_uuid.bytes[4],
+ atom.u.as_uuid.bytes[5],
+ atom.u.as_uuid.bytes[6],
+ atom.u.as_uuid.bytes[7],
+ atom.u.as_uuid.bytes[8],
+ atom.u.as_uuid.bytes[9],
+ atom.u.as_uuid.bytes[10],
+ atom.u.as_uuid.bytes[11],
+ atom.u.as_uuid.bytes[12],
+ atom.u.as_uuid.bytes[13],
+ atom.u.as_uuid.bytes[14],
+ atom.u.as_uuid.bytes[15]);
case PN_BINARY:
case PN_STRING:
case PN_SYMBOL:
@@ -412,6 +456,10 @@ uint8_t pn_type2code(pn_type_t type)
case PN_LONG: return PNE_LONG;
case PN_TIMESTAMP: return PNE_MS64;
case PN_DOUBLE: return PNE_DOUBLE;
+ case PN_DECIMAL32: return PNE_DECIMAL32;
+ case PN_DECIMAL64: return PNE_DECIMAL64;
+ case PN_DECIMAL128: return PNE_DECIMAL128;
+ case PN_UUID: return PNE_UUID;
case PN_ULONG: return PNE_ULONG;
case PN_BINARY: return PNE_VBIN32;
case PN_STRING: return PNE_STR32_UTF8;
@@ -482,6 +530,16 @@ int pn_bytes_writef64(pn_bytes_t *bytes,
}
}
+int pn_bytes_writef128(pn_bytes_t *bytes, char *value) {
+ if (bytes->size < 16) {
+ return PN_OVERFLOW;
+ } else {
+ memmove(bytes->start, value, 16);
+ pn_bytes_ltrim(bytes, 16);
+ return 0;
+ }
+}
+
int pn_bytes_writev32(pn_bytes_t *bytes, const pn_bytes_t *value)
{
if (bytes->size < 4 + value->size) {
@@ -542,6 +600,10 @@ int pn_encode_value(pn_bytes_t *bytes, p
case PN_TIMESTAMP: return pn_bytes_writef64(bytes, atom->u.as_timestamp);
case PN_FLOAT: c.f = atom->u.as_float; return pn_bytes_writef32(bytes, c.i);
case PN_DOUBLE: c.d = atom->u.as_double; return pn_bytes_writef64(bytes,
c.l);
+ case PN_DECIMAL32: return pn_bytes_writef32(bytes, atom->u.as_decimal32);
+ case PN_DECIMAL64: return pn_bytes_writef64(bytes, atom->u.as_decimal64);
+ case PN_DECIMAL128: return pn_bytes_writef128(bytes,
atom->u.as_decimal128.bytes);
+ case PN_UUID: return pn_bytes_writef128(bytes, atom->u.as_uuid.bytes);
case PN_BINARY: return pn_bytes_writev32(bytes, &atom->u.as_binary);
case PN_STRING: return pn_bytes_writev32(bytes, &atom->u.as_string);
case PN_SYMBOL: return pn_bytes_writev32(bytes, &atom->u.as_symbol);
@@ -658,6 +720,14 @@ pn_type_t pn_code2type(uint8_t code)
return PN_TIMESTAMP;
case PNE_DOUBLE:
return PN_DOUBLE;
+ case PNE_DECIMAL32:
+ return PN_DECIMAL32;
+ case PNE_DECIMAL64:
+ return PN_DECIMAL64;
+ case PNE_DECIMAL128:
+ return PN_DECIMAL128;
+ case PNE_UUID:
+ return PN_UUID;
case PNE_ULONG0:
case PNE_SMALLULONG:
case PNE_SMALLLONG:
@@ -771,10 +841,16 @@ int pn_decode_value(pn_bytes_t *bytes, p
atom.type=PN_FLOAT, atom.u.as_float=conv.f;
pn_bytes_ltrim(bytes, 4);
break;
+ case PNE_DECIMAL32:
+ if (bytes->size < 4) return PN_UNDERFLOW;
+ atom.type=PN_DECIMAL32, atom.u.as_decimal32=ntohl(*((uint32_t *)
(bytes->start)));
+ pn_bytes_ltrim(bytes, 4);
+ break;
case PNE_ULONG:
case PNE_LONG:
case PNE_MS64:
case PNE_DOUBLE:
+ case PNE_DECIMAL64:
if (bytes->size < 8) return PN_UNDERFLOW;
{
@@ -798,6 +874,9 @@ int pn_decode_value(pn_bytes_t *bytes, p
// XXX: this assumes the platform uses IEEE floats
atom.type=PN_DOUBLE, atom.u.as_double=conv.d;
break;
+ case PNE_DECIMAL64:
+ atom.type=PN_DECIMAL64, atom.u.as_decimal64=conv.l;
+ break;
default:
return PN_ARG_ERR;
}
@@ -817,6 +896,18 @@ int pn_decode_value(pn_bytes_t *bytes, p
atom.type=PN_LONG, atom.u.as_long=*((int8_t *) (bytes->start));
pn_bytes_ltrim(bytes, 1);
break;
+ case PNE_DECIMAL128:
+ if (bytes->size < 16) return PN_UNDERFLOW;
+ atom.type = PN_DECIMAL128;
+ memmove(&atom.u.as_decimal128.bytes, bytes->start, 16);
+ pn_bytes_ltrim(bytes, 16);
+ break;
+ case PNE_UUID:
+ if (bytes->size < 16) return PN_UNDERFLOW;
+ atom.type = PN_UUID;
+ memmove(atom.u.as_uuid.bytes, bytes->start, 16);
+ pn_bytes_ltrim(bytes, 16);
+ break;
case PNE_VBIN8:
case PNE_STR8_UTF8:
case PNE_SYM8:
@@ -2767,6 +2858,22 @@ int pn_data_parse_atoms(pn_data_t *data,
pn_data_put_double(data, atom.u.as_double);
count++;
break;
+ case PN_DECIMAL32:
+ pn_data_put_decimal32(data, atom.u.as_decimal32);
+ count++;
+ break;
+ case PN_DECIMAL64:
+ pn_data_put_decimal64(data, atom.u.as_decimal64);
+ count++;
+ break;
+ case PN_DECIMAL128:
+ pn_data_put_decimal128(data, atom.u.as_decimal128);
+ count++;
+ break;
+ case PN_UUID:
+ pn_data_put_uuid(data, atom.u.as_uuid);
+ count++;
+ break;
case PN_BINARY:
pn_data_put_binary(data, atom.u.as_binary);
count++;
@@ -3027,6 +3134,38 @@ int pn_data_put_double(pn_data_t *data,
return 0;
}
+int pn_data_put_decimal32(pn_data_t *data, pn_decimal32_t d)
+{
+ pn_node_t *node = pn_data_add(data);
+ node->atom.type = PN_DECIMAL32;
+ node->atom.u.as_decimal32 = d;
+ return 0;
+}
+
+int pn_data_put_decimal64(pn_data_t *data, pn_decimal64_t d)
+{
+ pn_node_t *node = pn_data_add(data);
+ node->atom.type = PN_DECIMAL64;
+ node->atom.u.as_decimal64 = d;
+ return 0;
+}
+
+int pn_data_put_decimal128(pn_data_t *data, pn_decimal128_t d)
+{
+ pn_node_t *node = pn_data_add(data);
+ node->atom.type = PN_DECIMAL128;
+ memmove(node->atom.u.as_decimal128.bytes, d.bytes, 16);
+ return 0;
+}
+
+int pn_data_put_uuid(pn_data_t *data, pn_uuid_t u)
+{
+ pn_node_t *node = pn_data_add(data);
+ node->atom.type = PN_UUID;
+ memmove(node->atom.u.as_uuid.bytes, u.bytes, 16);
+ return 0;
+}
+
int pn_data_put_binary(pn_data_t *data, pn_bytes_t bytes)
{
pn_node_t *node = pn_data_add(data);
@@ -3271,6 +3410,54 @@ int pn_data_get_double(pn_data_t *data,
}
}
+int pn_data_get_decimal32(pn_data_t *data, pn_decimal32_t *d)
+{
+ pn_node_t *node = pn_data_current(data);
+ if (node->atom.type == PN_DECIMAL32) {
+ *d = node->atom.u.as_decimal32;
+ return 0;
+ } else {
+ *d = 0;
+ return PN_ERR;
+ }
+}
+
+int pn_data_get_decimal64(pn_data_t *data, pn_decimal64_t *d)
+{
+ pn_node_t *node = pn_data_current(data);
+ if (node->atom.type == PN_DECIMAL64) {
+ *d = node->atom.u.as_decimal64;
+ return 0;
+ } else {
+ *d = 0;
+ return PN_ERR;
+ }
+}
+
+int pn_data_get_decimal128(pn_data_t *data, pn_decimal128_t *d)
+{
+ 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;
+ } else {
+ memset(d->bytes, 0, 16);
+ return PN_ERR;
+ }
+}
+
+int pn_data_get_uuid(pn_data_t *data, pn_uuid_t *u)
+{
+ 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;
+ } else {
+ memset(u->bytes, 0, 16);
+ return PN_ERR;
+ }
+}
+
int pn_data_get_binary(pn_data_t *data, pn_bytes_t *bytes)
{
pn_node_t *node = pn_data_current(data);
Modified: qpid/proton/trunk/tests/proton_tests/codec.py
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/tests/proton_tests/codec.py?rev=1395553&r1=1395552&r2=1395553&view=diff
==============================================================================
--- qpid/proton/trunk/tests/proton_tests/codec.py (original)
+++ qpid/proton/trunk/tests/proton_tests/codec.py Mon Oct 8 13:34:01 2012
@@ -19,6 +19,7 @@
import os, common
from proton import *
+from uuid import uuid3, NAMESPACE_OID
class Test(common.Test):
@@ -177,3 +178,16 @@ class DataTest(Test):
def testChar(self):
self._test("char", 'a', 'b', 'c', u'\u1234')
+
+ def testUUID(self):
+ self._test("uuid", uuid3(NAMESPACE_OID, "test1"), uuid3(NAMESPACE_OID,
"test2"),
+ uuid3(NAMESPACE_OID, "test3"))
+
+ def testDecimal32(self):
+ self._test("decimal32", 0, 1, 2, 3, 4, 2**30)
+
+ def testDecimal64(self):
+ self._test("decimal64", 0, 1, 2, 3, 4, 2**60)
+
+ def testDecimal128(self):
+ self._test("decimal128", "fdsaasdf;lkjjkl;", "x"*16 )
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]