qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject [1/3] qpid-proton git commit: PROTON-1505: Fix encoding and decoding of message priority - Added missing default message header fields to xml - Fixed decoder to set priority to default of not set rather than 0 - Fixed encoder to not set priority if it is
Date Thu, 01 Feb 2018 22:58:50 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 61073481b -> c6bfeff2a


PROTON-1505: Fix encoding and decoding of message priority
- Added missing default message header fields to xml
- Fixed decoder to set priority to default of not set rather than 0
- Fixed encoder to not set priority if it is default
- Added tests for encoding/decoding


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

Branch: refs/heads/master
Commit: c6bfeff2a22f3e9495140df3cef046d6708cf5c1
Parents: 21d5024
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Thu Jan 25 01:59:18 2018 -0500
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Thu Feb 1 17:39:35 2018 -0500

----------------------------------------------------------------------
 proton-c/src/core/message.c          | 27 ++++++++++++++++--------
 proton-c/src/messaging.xml           |  8 ++++----
 tests/python/proton_tests/message.py | 34 +++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c6bfeff2/proton-c/src/core/message.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/message.c b/proton-c/src/core/message.c
index 548636b..15b6dea 100644
--- a/proton-c/src/core/message.c
+++ b/proton-c/src/core/message.c
@@ -114,7 +114,7 @@ int pn_message_inspect(void *obj, pn_string_t *dst)
     comma = true;
   }
 
-  if (msg->priority != PN_DEFAULT_PRIORITY) {
+  if (msg->priority != HEADER_PRIORITY_DEFAULT) {
     err = pn_string_addf(dst, "priority=%i, ", msg->priority);
     if (err) return err;
     comma = true;
@@ -309,7 +309,7 @@ static pn_message_t *pni_message_new(size_t size)
   static const pn_class_t clazz = PN_CLASS(pn_message);
   pn_message_t *msg = (pn_message_t *) pn_class_new(&clazz, size);
   msg->durable = false;
-  msg->priority = PN_DEFAULT_PRIORITY;
+  msg->priority = HEADER_PRIORITY_DEFAULT;
   msg->ttl = 0;
   msg->first_acquirer = false;
   msg->delivery_count = 0;
@@ -364,7 +364,7 @@ void pn_message_free(pn_message_t *msg)
 void pn_message_clear(pn_message_t *msg)
 {
   msg->durable = false;
-  msg->priority = PN_DEFAULT_PRIORITY;
+  msg->priority = HEADER_PRIORITY_DEFAULT;
   msg->ttl = 0;
   msg->first_acquirer = false;
   msg->delivery_count = 0;
@@ -672,12 +672,20 @@ int pn_message_decode(pn_message_t *msg, const char *bytes, size_t size)
     pn_data_next(msg->data);
 
     switch (desc) {
-    case HEADER:
-      err = pn_data_scan(msg->data, "D.[oBIoI]", &msg->durable, &msg->priority,
-                   &msg->ttl, &msg->first_acquirer, &msg->delivery_count);
+    case HEADER: {
+      bool priority_q;
+      uint8_t priority;
+      err = pn_data_scan(msg->data, "D.[o?BIoI]",
+                         &msg->durable,
+                         &priority_q, &priority,
+                         &msg->ttl,
+                         &msg->first_acquirer,
+                         &msg->delivery_count);
       if (err) return pn_error_format(msg->error, err, "data error: %s",
                                       pn_error_text(pn_data_error(msg->data)));
+      msg->priority = priority_q ? priority : HEADER_PRIORITY_DEFAULT;
       break;
+    }
     case PROPERTIES:
       {
         pn_bytes_t user_id, address, subject, reply_to, ctype, cencoding,
@@ -771,8 +779,11 @@ int pn_message_encode(pn_message_t *msg, char *bytes, size_t *size)
 int pn_message_data(pn_message_t *msg, pn_data_t *data)
 {
   pn_data_clear(data);
-  int err = pn_data_fill(data, "DL[oB?IoI]", HEADER, msg->durable,
-                         msg->priority, msg->ttl, msg->ttl, msg->first_acquirer,
+  int err = pn_data_fill(data, "DL[o?B?IoI]", HEADER,
+                         msg->durable,
+                         msg->priority!=HEADER_PRIORITY_DEFAULT, msg->priority,
+                         msg->ttl, msg->ttl,
+                         msg->first_acquirer,
                          msg->delivery_count);
   if (err)
     return pn_error_format(msg->error, err, "data error: %s",

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c6bfeff2/proton-c/src/messaging.xml
----------------------------------------------------------------------
diff --git a/proton-c/src/messaging.xml b/proton-c/src/messaging.xml
index 01c34e7..1feb03b 100644
--- a/proton-c/src/messaging.xml
+++ b/proton-c/src/messaging.xml
@@ -36,11 +36,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   <section name="message-format">
     <type name="header" class="composite" source="list" provides="section">
       <descriptor name="amqp:header:list" code="0x00000000:0x00000070"/>
-      <field name="durable" type="boolean"/>
-      <field name="priority" type="ubyte"/>
+      <field name="durable" type="boolean" default="false"/>
+      <field name="priority" type="ubyte" default="4"/>
       <field name="ttl" type="milliseconds"/>
-      <field name="first-acquirer" type="boolean"/>
-      <field name="delivery-count" type="uint"/>
+      <field name="first-acquirer" type="boolean" default="false"/>
+      <field name="delivery-count" type="uint" default="0"/>
     </type>
     <type name="delivery-annotations" class="restricted" source="annotations" provides="section">
       <descriptor name="amqp:delivery-annotations:map" code="0x00000000:0x00000071"/>

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c6bfeff2/tests/python/proton_tests/message.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/message.py b/tests/python/proton_tests/message.py
index 550520e..a7f1dad 100644
--- a/tests/python/proton_tests/message.py
+++ b/tests/python/proton_tests/message.py
@@ -132,3 +132,37 @@ class CodecTest(Test):
     assert self.msg.address == msg2.address, (self.msg.address, msg2.address)
     assert self.msg.subject == msg2.subject, (self.msg.subject, msg2.subject)
     assert self.msg.body == msg2.body, (self.msg.body, msg2.body)
+
+  def testDefaultPriorityEncodeAndDecode(self):
+    assert self.msg.priority == 4, (self.msg.priority)
+    self.msg.ttl = 0.003 # field after priority, so forces priority to be present
+    data = self.msg.encode()
+
+    decoder = Data()
+    decoder.decode(data)
+
+    dheaders = decoder.get_py_described()
+    # Check we've got the correct described list
+    assert dheaders.descriptor == 0x70, (dheaders.descriptor)
+
+    # Check that the priority field (second field) is encoded as null
+    headers = dheaders.value
+    assert headers[1] == None, (headers[1])
+
+    # This is a message with everything filled explicitly as null or zero in LIST32 HEADER
and PROPERTIES lists
+    data = str2bin('\x00\x53\x70\xd0\x00\x00\x00\x0a\x00\x00\x00\x05\x42\x40\x40\x42\x52\x00\x00\x53\x73\xd0\x00\x00\x00\x22\x00\x00\x00\x0d\x40\x40\x40\x40\x40\x40\x40\x40\x83\x00\x00\x00\x00\x00\x00\x00\x00\x83\x00\x00\x00\x00\x00\x00\x00\x00\x40\x52\x00\x40')
+    msg2 = Message()
+    msg2.decode(data)
+    assert msg2.priority == 4, (msg2.priority)
+
+    # The same message with LIST8s instead
+    data = str2bin('\x00\x53\x70\xc0\x07\x05\x42\x40\x40\x42\x52\x00\x00\x53\x73\xc0\x1f\x0d\x40\x40\x40\x40\x40\x40\x40\x40\x83\x00\x00\x00\x00\x00\x00\x00\x00\x83\x00\x00\x00\x00\x00\x00\x00\x00\x40\x52\x00\x40')
+    msg3 = Message()
+    msg3.decode(data)
+    assert msg3.priority == 4, (msg3.priority)
+
+    # Minified message with zero length HEADER and PROPERTIES lists
+    data = str2bin('\x00\x53\x70\x45' '\x00\x53\x73\x45')
+    msg4 = Message()
+    msg4.decode(data)
+    assert msg4.priority == 4, (msg4.priority)


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


Mime
View raw message