You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2015/01/29 01:46:08 UTC

qpid-proton git commit: PROTON-807: Use the small int and small long encodings when possible.

Repository: qpid-proton
Updated Branches:
  refs/heads/master c14244020 -> a515e195c


PROTON-807: Use the small int and small long encodings when possible.

Due to an oversight, proton was using small encodings for unsigned int and long
types but not for signed types. This patch corrects that.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/a515e195
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/a515e195
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/a515e195

Branch: refs/heads/master
Commit: a515e195c4ea28b4bb513ed6e7a905b4fa34e2ad
Parents: c142440
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Jan 28 17:51:06 2015 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Jan 28 18:56:33 2015 -0500

----------------------------------------------------------------------
 proton-c/src/codec/encoder.c       |  12 +++++
 tests/interop/described.amqp       | Bin 39 -> 33 bytes
 tests/interop/lists.amqp           | Bin 29 -> 26 bytes
 tests/interop/maps.amqp            | Bin 91 -> 73 bytes
 tests/python/proton_tests/codec.py |  81 ++++++++++++++++++++++----------
 5 files changed, 67 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a515e195/proton-c/src/codec/encoder.c
----------------------------------------------------------------------
diff --git a/proton-c/src/codec/encoder.c b/proton-c/src/codec/encoder.c
index 2496f09..7e19953 100644
--- a/proton-c/src/codec/encoder.c
+++ b/proton-c/src/codec/encoder.c
@@ -97,6 +97,18 @@ static uint8_t pn_type2code(pn_encoder_t *encoder, pn_type_t type)
 static uint8_t pn_node2code(pn_encoder_t *encoder, pni_node_t *node)
 {
   switch (node->atom.type) {
+  case PN_LONG:
+    if (-128 <= node->atom.u.as_long && node->atom.u.as_long <= 127) {
+      return PNE_SMALLLONG;
+    } else {
+      return PNE_LONG;
+    }
+  case PN_INT:
+    if (-128 <= node->atom.u.as_int && node->atom.u.as_int <= 127) {
+      return PNE_SMALLINT;
+    } else {
+      return PNE_INT;
+    }
   case PN_ULONG:
     if (node->atom.u.as_ulong < 256) {
       return PNE_SMALLULONG;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a515e195/tests/interop/described.amqp
----------------------------------------------------------------------
diff --git a/tests/interop/described.amqp b/tests/interop/described.amqp
index cdedd04..2d1cb63 100644
Binary files a/tests/interop/described.amqp and b/tests/interop/described.amqp differ

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a515e195/tests/interop/lists.amqp
----------------------------------------------------------------------
diff --git a/tests/interop/lists.amqp b/tests/interop/lists.amqp
index d9f5857..db12fcf 100644
Binary files a/tests/interop/lists.amqp and b/tests/interop/lists.amqp differ

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a515e195/tests/interop/maps.amqp
----------------------------------------------------------------------
diff --git a/tests/interop/maps.amqp b/tests/interop/maps.amqp
index 24e7c23..d428545 100644
Binary files a/tests/interop/maps.amqp and b/tests/interop/maps.amqp differ

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a515e195/tests/python/proton_tests/codec.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/codec.py b/tests/python/proton_tests/codec.py
index 661a1a9..81bb4de 100644
--- a/tests/python/proton_tests/codec.py
+++ b/tests/python/proton_tests/codec.py
@@ -121,6 +121,40 @@ class DataTest(Test):
     assert self.data.get_list() == 1
     assert not self.data.exit()
 
+
+  def put(self, putter, v):
+    """More informative exception from putters, include bad value"""
+    try:
+      putter(v)
+    except Exception, e:
+      etype, value, trace = sys.exc_info()
+      raise etype, "%s(%r): %s" % (putter.__name__, v, value), trace
+    return putter
+
+  # (bits, signed) for each integer type
+  INT_TYPES = {
+    "byte": (8, True),
+    "ubyte": (8, False),
+    "int": (32, True),
+    "uint": (32, False),
+    "long": (64, True),
+    "ulong": (64, False)
+  }
+
+  def int_values(self, dtype):
+    """Set of test values for integer type dtype, include extreme and medial values"""
+    bits, signed = self.INT_TYPES[dtype]
+    values = [0, 1, 2, 5, 42]
+    if signed:
+      min, max = -2**(bits-1), 2**(bits-1)-1
+      values.append(max / 2)
+      values += [-i for i in values if i]
+      values += [min, max]
+    else:
+      max = 2**(bits) - 1
+      values += [max / 2, max]
+    return sorted(values)
+
   def _testArray(self, dtype, descriptor, atype, *values):
     if dtype: dTYPE = getattr(self.data, dtype.upper())
     aTYPE = getattr(self.data, atype.upper())
@@ -128,10 +162,10 @@ class DataTest(Test):
     self.data.enter()
     if dtype is not None:
       putter = getattr(self.data, "put_%s" % dtype)
-      putter(descriptor)
+      self.put(putter, descriptor)
     putter = getattr(self.data, "put_%s" % atype)
     for v in values:
-      putter(v)
+      self.put(putter, v)
     self.data.exit()
     self.data.rewind()
     assert self.data.next() == Data.ARRAY
@@ -163,8 +197,15 @@ class DataTest(Test):
   def testDescribedStringArray(self):
     self._testArray("symbol", "url", "string", "one", "two", "three")
 
-  def testIntArray(self):
-    self._testArray(None, None, "int", 1, 2, 3)
+  def _test_int_array(self, atype):
+    self._testArray(None, None, atype, *self.int_values(atype))
+
+  def testByteArray(self): self._test_int_array("byte")
+  def testUbyteArray(self): self._test_int_array("ubyte")
+  def testIntArray(self): self._test_int_array("int")
+  def testUintArray(self): self._test_int_array("uint")
+  def testLongArray(self): self._test_int_array("long")
+  def testUlongArray(self): self._test_int_array("ulong")
 
   def testUUIDArray(self):
     self._testArray(None, None, "uuid", uuid4(), uuid4(), uuid4())
@@ -182,11 +223,7 @@ class DataTest(Test):
     getter = getattr(self.data, "get_%s" % dtype)
 
     for v in values:
-      try:
-        putter(v)
-      except Exception, e:
-        etype, value, trace = sys.exc_info()
-        raise etype, "Testing %s: %s" % (v, value), trace
+      self.put(putter, v)
       gotten = getter()
       assert eq(gotten, v), (gotten, v)
 
@@ -213,23 +250,15 @@ class DataTest(Test):
       gotten = cgetter()
       assert eq(gotten, v), (gotten, v)
 
-  def _test_int(self, dtype, bits, signed=True):
-    """Test a few basic integers and the min/max"""
-    values = [0, 1, 2, 3, 42]
-    if signed:
-      max = 2**(bits-1)-1
-      values += [-i for i in values] + [-2**(bits-1)]
-    else:
-      max = 2**(bits)-1
-    values.append(max)
-    self._test(dtype, *values)
-
-  def testByte(self): self._test_int("byte", 8)
-  def testUbyte(self): self._test_int("ubyte", 8, signed=False)
-  def testInt(self): self._test_int("int", 32)
-  def testUint(self): self._test_int("uint", 32, signed=False)
-  def testLong(self): self._test_int("long", 64)
-  def testUlong(self): self._test_int("ulong", 64, signed=False)
+  def _test_int(self, itype):
+    self._test(itype, *self.int_values(itype))
+
+  def testByte(self): self._test_int("byte")
+  def testUbyte(self): self._test_int("ubyte")
+  def testInt(self): self._test_int("int")
+  def testUint(self): self._test_int("uint")
+  def testLong(self): self._test_int("long")
+  def testUlong(self): self._test_int("ulong")
 
   def testString(self):
     self._test("string", "one", "two", "three", "this is a test", "")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org