qpid-proton git commit: PROTON-1502: encode empty annotations by ommission, not as empty maps

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

qpid-proton git commit: PROTON-1502: encode empty annotations by ommission, not as empty maps

aconway-2
Repository: qpid-proton
Updated Branches:
  refs/heads/master cb91969f3 -> 662957df6


PROTON-1502: encode empty annotations by ommission, not as empty maps


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

Branch: refs/heads/master
Commit: 662957df680dd51dd46c31a15330f228ec0f1452
Parents: cb91969
Author: Alan Conway <[hidden email]>
Authored: Wed Jun 14 17:14:16 2017 -0400
Committer: Alan Conway <[hidden email]>
Committed: Wed Jun 14 17:46:07 2017 -0400

----------------------------------------------------------------------
 proton-c/bindings/cpp/include/proton/map.hpp |  7 ++---
 proton-c/bindings/cpp/src/map.cpp            | 35 ++++++++++++-----------
 proton-c/bindings/cpp/src/message.cpp        |  8 +++---
 3 files changed, 26 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/662957df/proton-c/bindings/cpp/include/proton/map.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/map.hpp b/proton-c/bindings/cpp/include/proton/map.hpp
index 86e4de7..86948e5 100644
--- a/proton-c/bindings/cpp/include/proton/map.hpp
+++ b/proton-c/bindings/cpp/include/proton/map.hpp
@@ -85,9 +85,9 @@ class PN_CPP_CLASS_EXTERN map {
     /// Copy from a proton::value.
     /// @throw proton::conversion_error if x does not contain a compatible map.
     PN_CPP_EXTERN void value(const value& x);
-    /// Access as a proton::value
+    /// Access as a proton::value containing an AMQP map
     PN_CPP_EXTERN proton::value& value();
-    /// Access as a proton::value
+    /// Access as a proton::value containing an AMQP map
     PN_CPP_EXTERN const proton::value& value() const;
 
     /// Get the map entry for key k, return T() if no such entry
@@ -100,7 +100,7 @@ class PN_CPP_CLASS_EXTERN map {
     PN_CPP_EXTERN bool exists(const K& k) const;
     /// Number of map entries
     PN_CPP_EXTERN size_t size() const;
-    /// Clear the map value
+    /// Clear the map
     PN_CPP_EXTERN void clear();
     /// True if the map is empty
     PN_CPP_EXTERN bool empty() const;
@@ -108,7 +108,6 @@ class PN_CPP_CLASS_EXTERN map {
     ///@cond INTERNAL
     explicit map(pn_data_t*);
     void reset(pn_data_t*);
-    ///@endcond
 
  private:
     typedef map_type_impl<K,T> map_type;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/662957df/proton-c/bindings/cpp/src/map.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/map.cpp b/proton-c/bindings/cpp/src/map.cpp
index 29652d2..86bd8c5 100644
--- a/proton-c/bindings/cpp/src/map.cpp
+++ b/proton-c/bindings/cpp/src/map.cpp
@@ -32,9 +32,9 @@
 #include <string>
 
 // IMPLEMENTATION NOTES:
-// - if (map_.get()) then *map_ is the authority
-// - cache() ensures that *map_ is up to date
-// - flush() ensures value_ is up to date and map_ is reset
+// - if (map_.get()) then *map_ is the authority and value_ is empty()
+// - cache() ensures that *map_ is up to date and value_ is cleared.
+// - flush() ensures value_ is up to date and map_ is cleared.
 
 namespace proton {
 
@@ -49,7 +49,10 @@ template <class K, class T>
 map<K,T>::map(const map& x) { *this = x; }
 
 template <class K, class T>
-map<K,T>::map(pn_data_t *d) : value_(d) {}
+map<K,T>::map(pn_data_t *d) : value_(d) {
+    // NOTE: for internal use. Don't verify that the data is valid here as that
+    // would forcibly decode message maps immediately, we want to decode on-demand.
+}
 
 template <class K, class T>
 PN_CPP_EXTERN void swap(map<K,T>& x, map<K,T>& y) {
@@ -62,9 +65,7 @@ template <class K, class T>
 map<K,T>& map<K,T>::operator=(const map& x) {
     if (&x != this) {
         map_.reset(x.map_.get() ? new map_type(*x.map_) : 0);
-        if (!map_) {
-            value_ = x.value_;
-        }
+        value_ = x.value_;
     }
     return *this;
 }
@@ -93,18 +94,14 @@ typename map<K,T>::map_type& map<K,T>::cache() const {
     if (!map_) {
         map_.reset(new map_type);
         if (!value_.empty()) {
-            try {
-                proton::get(value_, *map_);
-            } catch (...) {     // Invalid value for the map, throw it away.
-                map_.reset();
-                value_.clear();
-                throw;
-            }
+            proton::get(value_, *map_);
+            value_.clear();
         }
     }
     return *map_;
 }
 
+// Make sure value_ is valid
 template <class K, class T>
 value& map<K,T>::flush() const {
     if (map_.get()) {
@@ -119,8 +116,14 @@ value& map<K,T>::flush() const {
 
 template <class K, class T>
 void map<K,T>::value(const proton::value& x) {
-    value_ = x;
-    cache();    // Validate the value by decoding to cache.
+    if (x.empty()) {
+        clear();
+    } else {
+        internal::pn_unique_ptr<map_type> tmp(new map_type);
+        proton::get(x, *tmp);  // Validate by decoding, may throw
+        map_.reset(tmp.release());
+        value_.clear();
+    }
 }
 
 template <class K, class T>

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/662957df/proton-c/bindings/cpp/src/message.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/message.cpp b/proton-c/bindings/cpp/src/message.cpp
index eb0695e..d121cc8 100644
--- a/proton-c/bindings/cpp/src/message.cpp
+++ b/proton-c/bindings/cpp/src/message.cpp
@@ -60,11 +60,11 @@ struct message::impl {
         instructions.clear();
     }
 
-    // Encode cached maps back to the underlying pn_data_t
+    // Encode cached maps to the pn_data_t, always used an empty() value for an empty map
     void flush() {
-        properties.value();
-        annotations.value();
-        instructions.value();
+        if (!properties.empty()) properties.value();
+        if (!annotations.empty()) annotations.value();
+        if (!instructions.empty()) instructions.value();
     }
 };
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]