You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2021/10/29 19:41:17 UTC

[qpid-proton] 03/04: PROTON-2445: Allow encoder to produce the short forms for 0

This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 7e0edf421a738fef6e17894f5ab6363ae4a38c5c
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Mon Sep 20 17:58:04 2021 -0400

    PROTON-2445: Allow encoder to produce the short forms for 0
    
    Previously (for reasons unknown) the AMQP type encoder never generated
    the short typecodes for ulong and uint 0. Using these instead of
    SMALLUINT and SMALLULONG saves a byte for each encoding.
    
    [Had to fix a few python tests which have the exact bytes of expected
    frames hardcoded in them]
---
 c/src/core/encoder.c                |  9 +++++++--
 python/tests/proton_tests/engine.py | 12 ++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/c/src/core/encoder.c b/c/src/core/encoder.c
index 472ea3b..44722ef 100644
--- a/c/src/core/encoder.c
+++ b/c/src/core/encoder.c
@@ -99,13 +99,17 @@ static uint8_t pn_node2code(pn_encoder_t *encoder, pni_node_t *node)
       return PNE_INT;
     }
   case PN_ULONG:
-    if (node->atom.u.as_ulong < 256) {
+    if (node->atom.u.as_ulong == 0) {
+      return PNE_ULONG0;
+    } else if (node->atom.u.as_ulong < 256) {
       return PNE_SMALLULONG;
     } else {
       return PNE_ULONG;
     }
   case PN_UINT:
-    if (node->atom.u.as_uint < 256) {
+    if (node->atom.u.as_uint == 0) {
+      return PNE_UINT0;
+    } else if (node->atom.u.as_uint < 256) {
       return PNE_SMALLUINT;
     } else {
       return PNE_UINT;
@@ -290,6 +294,7 @@ static int pni_encoder_enter(void *ctx, pn_data_t *data, pni_node_t *node)
   case PNE_SMALLINT: pn_encoder_writef8(encoder, atom->u.as_int); return 0;
   case PNE_INT: pn_encoder_writef32(encoder, atom->u.as_int); return 0;
   case PNE_UTF32: pn_encoder_writef32(encoder, atom->u.as_char); return 0;
+  case PNE_ULONG0: return 0;
   case PNE_ULONG: pn_encoder_writef64(encoder, atom->u.as_ulong); return 0;
   case PNE_SMALLULONG: pn_encoder_writef8(encoder, atom->u.as_ulong); return 0;
   case PNE_LONG: pn_encoder_writef64(encoder, atom->u.as_long); return 0;
diff --git a/python/tests/proton_tests/engine.py b/python/tests/proton_tests/engine.py
index 586f974..6838d67 100644
--- a/python/tests/proton_tests/engine.py
+++ b/python/tests/proton_tests/engine.py
@@ -922,10 +922,10 @@ class TransferTest(Test):
         # Confirm abort discards the sender's buffered content, i.e. no data in generated transfer frame.
         # We want:
         # @transfer(20) [handle=0, delivery-id=0, delivery-tag=b"tag", message-format=0, settled=true, aborted=true]
-        wanted = b"\x00\x00\x00%\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x15\x00\x00\x00\nR\x00R\x00\xa0\x03tagR\x00A@@@@A"
+        wanted = b'\x00\x00\x00"\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x12\x00\x00\x00\nCC\xa0\x03tagCA@@@@A'
         t = self.snd.transport
         wire_bytes = t.peek(1024)
-        assert wanted == wire_bytes
+        assert wanted == wire_bytes, wire_bytes
 
         self.pump()
         assert self.rcv.current.aborted
@@ -1318,10 +1318,10 @@ class MaxFrameTransferTest(Test):
         assert sd.aborted
         # Expect a single abort transfer frame with no content.  One credit is consumed.
         # @transfer(20) [handle=0, delivery-id=0, delivery-tag=b"tag_1", message-format=0, settled=true, aborted=true]
-        wanted = b"\x00\x00\x00\x27\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x17\x00\x00\x00\nR\x00R\x00\xa0\x05tag_1R\x00A@@@@A"
+        wanted = b'\x00\x00\x00\x24\x02\x00\x00\x00\x00S\x14\xd0\x00\x00\x00\x14\x00\x00\x00\nCC\xa0\x05tag_1CA@@@@A'
         t = self.snd.transport
         wire_bytes = t.peek(2048)
-        assert wanted == wire_bytes
+        assert wanted == wire_bytes, wire_bytes
         assert self.snd.credit == 0
         self.pump()
         assert self.rcv.current.aborted
@@ -1329,9 +1329,9 @@ class MaxFrameTransferTest(Test):
         self.snd.close()
         # Expect just the detach frame.
         # @detach(22) [handle=0, closed=true]
-        wanted = b"\x00\x00\x00\x17\x02\x00\x00\x00\x00S\x16\xd0\x00\x00\x00\x07\x00\x00\x00\x02R\x00A"
+        wanted = b"\x00\x00\x00\x16\x02\x00\x00\x00\x00S\x16\xd0\x00\x00\x00\x06\x00\x00\x00\x02CA"
         wire_bytes = t.peek(2048)
-        assert wanted == wire_bytes
+        assert wanted == wire_bytes, wire_bytes
 
 
 class IdleTimeoutTest(Test):

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