qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [28/41] qpid-proton git commit: PROTON-1857: [cpp] correct decoding for connection offered/desired capabilities
Date Wed, 04 Jul 2018 15:58:00 GMT
PROTON-1857: [cpp] correct decoding for connection offered/desired capabilities

capabilities are encoded as a "multiple" symbol field. "multiple" fields can be
encoded either as an array or a single value. The C++ binding was not accepting
a single value.


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

Branch: refs/heads/go1
Commit: af93c804ca34ca6d9de48c87dae7391f4a602239
Parents: 8a6d7ea
Author: Alan Conway <aconway@redhat.com>
Authored: Wed Jun 13 14:57:25 2018 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Wed Jun 13 14:58:53 2018 -0400

----------------------------------------------------------------------
 cpp/include/proton/value.hpp |  2 +-
 cpp/src/connection.cpp       |  4 ++--
 cpp/src/proton_bits.hpp      | 26 ++++++++++++++++++++++++++
 3 files changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/af93c804/cpp/include/proton/value.hpp
----------------------------------------------------------------------
diff --git a/cpp/include/proton/value.hpp b/cpp/include/proton/value.hpp
index 552a2e4..979881e 100644
--- a/cpp/include/proton/value.hpp
+++ b/cpp/include/proton/value.hpp
@@ -125,7 +125,7 @@ class value : public internal::value_base, private internal::comparable<value>
{
 /// @relatedalso proton::value
 template<class T> T get(const value& v) { T x; get(v, x); return x; }
 
-/// Like get(const value&) but assigns the value to a reference
+/// Like get(const value&) but extracts the value to a reference @p x
 /// instead of returning it.  May be more efficient for complex values
 /// (arrays, maps, etc.)
 ///

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/af93c804/cpp/src/connection.cpp
----------------------------------------------------------------------
diff --git a/cpp/src/connection.cpp b/cpp/src/connection.cpp
index cab1ec6..b2dadae 100644
--- a/cpp/src/connection.cpp
+++ b/cpp/src/connection.cpp
@@ -182,12 +182,12 @@ void connection::wake() const {
 
 std::vector<symbol> connection::offered_capabilities() const {
     value caps(pn_connection_remote_offered_capabilities(pn_object()));
-    return caps.empty() ? std::vector<symbol>() : caps.get<std::vector<symbol>
>();
+    return get_multiple<std::vector<symbol> >(caps);
 }
 
 std::vector<symbol> connection::desired_capabilities() const {
     value caps(pn_connection_remote_desired_capabilities(pn_object()));
-    return caps.empty() ? std::vector<symbol>() : caps.get<std::vector<symbol>
>();
+    return get_multiple<std::vector<symbol> >(caps);
 }
 
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/af93c804/cpp/src/proton_bits.hpp
----------------------------------------------------------------------
diff --git a/cpp/src/proton_bits.hpp b/cpp/src/proton_bits.hpp
index b6636f9..48b9f5f 100644
--- a/cpp/src/proton_bits.hpp
+++ b/cpp/src/proton_bits.hpp
@@ -157,6 +157,32 @@ template <class T> returned<T> make_returned(typename internal::wrapped<T>::type
     return internal::returned_factory::make<T>(pn);
 }
 
+// Get an AMQP "multiple" field from a value. A "multiple" field can be encoded as a single
+// value or as an array. This function always extracts it as a sequence, a sequence of one
+// if it is encoded as a single value.
+//
+// T should be a valid sequence type for proton::get() with a T::value_type typedef.
+//
+template<class T>
+void get_multiple(const value& v, T& x) {
+    if (v.empty()) {
+        x.clear();
+    } else if (v.type() == ARRAY) {
+        proton::get(v,x);
+    } else {
+        x.resize(1);
+        proton::get(v,x[0]);
+    }
+}
+
+// Same as previous but returns the value.
+template<class T>
+T get_multiple(const value& v) {
+    T x;
+    get_multiple(v, x);
+    return x;
 }
 
+} // namespace proton
+
 #endif // PROTON_BITS_HPP


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


Mime
View raw message