qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [1/5] qpid-proton git commit: NO-JIRA: Separated pn_message_data from pn_message_encode to extract message as a pn_data_t
Date Fri, 10 Apr 2015 19:52:24 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 450b8ba5d -> d6f1b8371


NO-JIRA: Separated pn_message_data from pn_message_encode to extract message as a pn_data_t

This allows you to check the size needed before encoding.


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

Branch: refs/heads/master
Commit: 6d90c02ef15119bbf99d07c60214b3753096fa30
Parents: 3fd17db
Author: Alan Conway <aconway@redhat.com>
Authored: Tue Mar 24 14:52:34 2015 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Tue Apr 7 15:47:42 2015 -0400

----------------------------------------------------------------------
 proton-c/include/proton/message.h |   5 ++
 proton-c/src/message/message.c    | 112 +++++++++++++++------------------
 2 files changed, 54 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6d90c02e/proton-c/include/proton/message.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/message.h b/proton-c/include/proton/message.h
index 86a4872..d11a502 100644
--- a/proton-c/include/proton/message.h
+++ b/proton-c/include/proton/message.h
@@ -738,6 +738,11 @@ PN_EXTERN int pn_message_decode(pn_message_t *msg, const char *bytes,
size_t siz
  */
 PN_EXTERN int pn_message_encode(pn_message_t *msg, char *bytes, size_t *size);
 
+/**
+ * Save message content into a pn_data_t object data. The data object will first be cleared.
+ */
+PN_EXTERN int pn_message_data(pn_message_t *msg, pn_data_t *data);
+
 /** @}
  */
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6d90c02e/proton-c/src/message/message.c
----------------------------------------------------------------------
diff --git a/proton-c/src/message/message.c b/proton-c/src/message/message.c
index a5b8029..6b0765f 100644
--- a/proton-c/src/message/message.c
+++ b/proton-c/src/message/message.c
@@ -32,20 +32,6 @@
 #include "util.h"
 #include "platform_fmt.h"
 
-ssize_t pn_message_data(char *dst, size_t available, const char *src, size_t size)
-{
-  pn_data_t *data = pn_data(16);
-  pn_data_put_described(data);
-  pn_data_enter(data);
-  pn_data_put_long(data, 0x75);
-  pn_data_put_binary(data, pn_bytes(size, (char *)src));
-  pn_data_exit(data);
-  pn_data_rewind(data);
-  int err = pn_data_encode(data, dst, available);
-  pn_data_free(data);
-  return err;
-}
-
 // message
 
 struct pn_message_t {
@@ -752,41 +738,60 @@ int pn_message_decode(pn_message_t *msg, const char *bytes, size_t size)
 int pn_message_encode(pn_message_t *msg, char *bytes, size_t *size)
 {
   if (!msg || !bytes || !size || !*size) return PN_ARG_ERR;
-
   pn_data_clear(msg->data);
+  pn_message_data(msg, msg->data);
+  size_t remaining = *size;
+  ssize_t encoded = pn_data_encode(msg->data, bytes, remaining);
+  if (encoded < 0) {
+    if (encoded == PN_OVERFLOW) {
+      return encoded;
+    } else {
+      return pn_error_format(msg->error, encoded, "data error: %s",
+                             pn_data_error(msg->data));
+    }
+  }
+  bytes += encoded;
+  remaining -= encoded;
+  *size -= remaining;
+  pn_data_clear(msg->data);
+  return 0;
+}
 
-  int err = pn_data_fill(msg->data, "DL[oB?IoI]", HEADER, msg->durable,
+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,
                          msg->delivery_count);
   if (err)
     return pn_error_format(msg->error, err, "data error: %s",
-                           pn_data_error(msg->data));
+                           pn_data_error(data));
 
   if (pn_data_size(msg->instructions)) {
-    pn_data_put_described(msg->data);
-    pn_data_enter(msg->data);
-    pn_data_put_ulong(msg->data, DELIVERY_ANNOTATIONS);
+    pn_data_put_described(data);
+    pn_data_enter(data);
+    pn_data_put_ulong(data, DELIVERY_ANNOTATIONS);
     pn_data_rewind(msg->instructions);
-    err = pn_data_append(msg->data, msg->instructions);
+    err = pn_data_append(data, msg->instructions);
     if (err)
       return pn_error_format(msg->error, err, "data error: %s",
-                             pn_data_error(msg->data));
-    pn_data_exit(msg->data);
+                             pn_data_error(data));
+    pn_data_exit(data);
   }
 
   if (pn_data_size(msg->annotations)) {
-    pn_data_put_described(msg->data);
-    pn_data_enter(msg->data);
-    pn_data_put_ulong(msg->data, MESSAGE_ANNOTATIONS);
+    pn_data_put_described(data);
+    pn_data_enter(data);
+    pn_data_put_ulong(data, MESSAGE_ANNOTATIONS);
     pn_data_rewind(msg->annotations);
-    err = pn_data_append(msg->data, msg->annotations);
+    err = pn_data_append(data, msg->annotations);
     if (err)
       return pn_error_format(msg->error, err, "data error: %s",
-                             pn_data_error(msg->data));
-    pn_data_exit(msg->data);
+                             pn_data_error(data));
+    pn_data_exit(data);
   }
 
-  err = pn_data_fill(msg->data, "DL[CzSSSCssttSIS]", PROPERTIES,
+  err = pn_data_fill(data, "DL[CzSSSCssttSIS]", PROPERTIES,
                      msg->id,
                      pn_string_size(msg->user_id), pn_string_get(msg->user_id),
                      pn_string_get(msg->address),
@@ -802,18 +807,18 @@ int pn_message_encode(pn_message_t *msg, char *bytes, size_t *size)
                      pn_string_get(msg->reply_to_group_id));
   if (err)
     return pn_error_format(msg->error, err, "data error: %s",
-                           pn_data_error(msg->data));
+                           pn_data_error(data));
 
   if (pn_data_size(msg->properties)) {
-    pn_data_put_described(msg->data);
-    pn_data_enter(msg->data);
-    pn_data_put_ulong(msg->data, APPLICATION_PROPERTIES);
+    pn_data_put_described(data);
+    pn_data_enter(data);
+    pn_data_put_ulong(data, APPLICATION_PROPERTIES);
     pn_data_rewind(msg->properties);
-    err = pn_data_append(msg->data, msg->properties);
+    err = pn_data_append(data, msg->properties);
     if (err)
       return pn_error_format(msg->error, err, "data error: %s",
-                             pn_data_error(msg->data));
-    pn_data_exit(msg->data);
+                             pn_data_error(data));
+    pn_data_exit(data);
   }
 
   if (pn_data_size(msg->body)) {
@@ -822,44 +827,25 @@ int pn_message_encode(pn_message_t *msg, char *bytes, size_t *size)
     pn_type_t body_type = pn_data_type(msg->body);
     pn_data_rewind(msg->body);
 
-    pn_data_put_described(msg->data);
-    pn_data_enter(msg->data);
+    pn_data_put_described(data);
+    pn_data_enter(data);
     if (msg->inferred) {
       switch (body_type) {
       case PN_BINARY:
-        pn_data_put_ulong(msg->data, DATA);
+        pn_data_put_ulong(data, DATA);
         break;
       case PN_LIST:
-        pn_data_put_ulong(msg->data, AMQP_SEQUENCE);
+        pn_data_put_ulong(data, AMQP_SEQUENCE);
         break;
       default:
-        pn_data_put_ulong(msg->data, AMQP_VALUE);
+        pn_data_put_ulong(data, AMQP_VALUE);
         break;
       }
     } else {
-      pn_data_put_ulong(msg->data, AMQP_VALUE);
+      pn_data_put_ulong(data, AMQP_VALUE);
     }
-    pn_data_append(msg->data, msg->body);
+    pn_data_append(data, msg->body);
   }
-
-  size_t remaining = *size;
-  ssize_t encoded = pn_data_encode(msg->data, bytes, remaining);
-  if (encoded < 0) {
-    if (encoded == PN_OVERFLOW) {
-      return encoded;
-    } else {
-      return pn_error_format(msg->error, encoded, "data error: %s",
-                             pn_data_error(msg->data));
-    }
-  }
-
-  bytes += encoded;
-  remaining -= encoded;
-
-  *size -= remaining;
-
-  pn_data_clear(msg->data);
-
   return 0;
 }
 


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


Mime
View raw message