PROTON-799: Created a utility module for the Ruby Engine APIs.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/6fd3be83 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/6fd3be83 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/6fd3be83 Branch: refs/heads/ruby-engine-apis Commit: 6fd3be83c90549b6a3c1741257e2a52727b94587 Parents: 9748c32 Author: Darryl L. Pierce <mcpie...@gmail.com> Authored: Tue Feb 24 13:38:50 2015 -0500 Committer: Darryl L. Pierce <mcpie...@gmail.com> Committed: Thu May 14 15:17:31 2015 -0400 ---------------------------------------------------------------------- proton-c/bindings/ruby/lib/qpid_proton.rb | 1 + proton-c/bindings/ruby/lib/util/engine.rb | 82 ++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fd3be83/proton-c/bindings/ruby/lib/qpid_proton.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/qpid_proton.rb b/proton-c/bindings/ruby/lib/qpid_proton.rb index f1b17ea..bcc7edd 100644 --- a/proton-c/bindings/ruby/lib/qpid_proton.rb +++ b/proton-c/bindings/ruby/lib/qpid_proton.rb @@ -32,6 +32,7 @@ require "util/version" require "util/error_handler" require "util/constants" require "util/swig_helper" +require "util/engine" # Types require "types/strings" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6fd3be83/proton-c/bindings/ruby/lib/util/engine.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/util/engine.rb b/proton-c/bindings/ruby/lib/util/engine.rb new file mode 100644 index 0000000..53aa672 --- /dev/null +++ b/proton-c/bindings/ruby/lib/util/engine.rb @@ -0,0 +1,82 @@ +#-- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +#++ + +module Qpid::Proton::Util + + # @private + module Engine + + # Convenience method to receive messages from a delivery. + # + # @param delivery [Qpid::Proton::Delivery] The delivery. + # @param message [Qpid::Proton::Message] The message to use. + # + # @return [Qpid::Proton::Message] the message + # + def self.receive_message(delivery, msg = nil) + msg = Qpid::Proton::Message.new if msg.nil? + msg.decode(delivery.link.receive(delivery.pending)) + delivery.link.advance + return msg + end + + def data_to_object(data_impl) # :nodoc: + object = nil + unless data_impl.nil? + data = Qpid::Proton::Codec::Data.new(data_impl) + data.rewind + data.next + object = data.object + data.rewind + end + return object + end + + def object_to_data(object, data_impl) # :nodoc: + unless object.nil? + data = Data.new(data_impl) + data.object = object + end + end + + def condition_to_object(condition) # :nodoc: + result = nil + if Cproton.pn_condition_is_set(condition) + result = Condition.new(Cproton.pn_condition_get_name(condition), + Cproton.pn_condition_get_description(condition), + data_to_object(Cproton.pn_condition_info(condition))) + end + return result + end + + def object_to_condition(object, condition) # :nodoc: + Cproton.pn_condition_clear(condition) + unless object.nil? + Cproton.pn_condition_set_name(condition, object.name) + Cproton.pn_condition_set_description(condition, object.description) + info = Data.new(Cproton.pn_condition_info(condition)) + if object.info? + info.object = object.info + end + end + end + + end + +end --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org