You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2018/06/13 23:24:01 UTC

[1/2] qpid-proton git commit: PROTON-1857: [cpp] correct decoding for connection offered/desired capabilities

Repository: qpid-proton
Updated Branches:
  refs/heads/master 8a6d7ea76 -> 27f9aec21


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/master
Commit: af93c804ca34ca6d9de48c87dae7391f4a602239
Parents: 8a6d7ea
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Jun 13 14:57:25 2018 -0400
Committer: Alan Conway <ac...@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


[2/2] qpid-proton git commit: PROTON-1861: [ruby] offered/desired capabilities should be decoded as "multiple" fields

Posted by ac...@apache.org.
PROTON-1861: [ruby] offered/desired capabilities should be decoded as "multiple" fields

capabilities are encoded as a "multiple" symbol field. "multiple" fields can be
encoded either as an array or a single value. The connection accessors return an
Array in all cases.


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

Branch: refs/heads/master
Commit: 27f9aec21d737279f117282f136ba9b1b0fd1c06
Parents: af93c80
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Jun 13 18:24:06 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Jun 13 18:24:06 2018 -0400

----------------------------------------------------------------------
 ruby/examples/server.rb     |  2 +-
 ruby/lib/codec/data.rb      | 10 +++++++++-
 ruby/lib/core/connection.rb |  6 ++++--
 3 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/27f9aec2/ruby/examples/server.rb
----------------------------------------------------------------------
diff --git a/ruby/examples/server.rb b/ruby/examples/server.rb
index 7538d61..7ebd807 100644
--- a/ruby/examples/server.rb
+++ b/ruby/examples/server.rb
@@ -37,7 +37,7 @@ class Server < Qpid::Proton::MessagingHandler
 
   def on_connection_open(connection)
     if connection.offered_capabilities &&
-        connection.offered_capabilities.contain?("ANONYMOUS-RELAY")
+        connection.offered_capabilities.include?(:"ANONYMOUS-RELAY")
       @relay = connection.open_sender({:target => nil})
     end
   end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/27f9aec2/ruby/lib/codec/data.rb
----------------------------------------------------------------------
diff --git a/ruby/lib/codec/data.rb b/ruby/lib/codec/data.rb
index ec74756..b6ce869 100644
--- a/ruby/lib/codec/data.rb
+++ b/ruby/lib/codec/data.rb
@@ -42,6 +42,15 @@ module Qpid::Proton
       end
 
       # @private
+      # Convert a pn_data_t* containing an AMQP "multiple" field to an Array or nil.
+      # A "multiple" field can be encoded as an array or a single value - always return Array.
+      # @return [Array, nil] The ruby Array extracted from +impl+ or nil if impl is empty
+      def self.to_multiple(impl)
+        o = self.to_object(impl)
+        Array(o) if o
+      end
+
+      # @private
       # Clear a pn_data_t* and convert a ruby object into it. If x==nil leave it empty.
       def self.from_object(impl, x)
         d = Data.new(impl)
@@ -676,7 +685,6 @@ module Qpid::Proton
           return err
         end
       end
-
     end
   end
 end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/27f9aec2/ruby/lib/core/connection.rb
----------------------------------------------------------------------
diff --git a/ruby/lib/core/connection.rb b/ruby/lib/core/connection.rb
index e54ce16..3586790 100644
--- a/ruby/lib/core/connection.rb
+++ b/ruby/lib/core/connection.rb
@@ -77,13 +77,15 @@ module Qpid::Proton
 
     # @return [Array<Symbol>] offered capabilities provided by the remote peer
     def offered_capabilities
-      Codec::Data.to_object(Cproton.pn_connection_remote_offered_capabilities(@impl))
+      # Provide capabilities consistently as an array, even if encoded as a single symbol
+      Codec::Data.to_multiple(Cproton.pn_connection_remote_offered_capabilities(@impl))
     end
     deprecated_alias :remote_offered_capabilities, :offered_capabilities
 
     # @return [Array<Symbol>] desired capabilities provided by the remote peer
     def desired_capabilities
-      Codec::Data.to_object(Cproton.pn_connection_remote_desired_capabilities(@impl))
+      # Provide capabilities consistently as an array, even if encoded as a single symbol
+      Codec::Data.to_multiple(Cproton.pn_connection_remote_desired_capabilities(@impl))
     end
     deprecated_alias :remote_desired_capabilities, :desired_capabilities
 


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