PROTON-799: Added the object/object= methods to Ruby Data class

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

Branch: refs/heads/ruby-engine-apis
Commit: 670aa99438c19e8cf643bef967cd58fe80d06499
Parents: 88f124f
Author: Darryl L. Pierce <mcpie...@gmail.com>
Authored: Mon Feb 16 15:33:08 2015 -0500
Committer: Darryl L. Pierce <mcpie...@gmail.com>
Committed: Mon May 18 08:10:19 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/codec/data.rb | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/670aa994/proton-c/bindings/ruby/lib/codec/data.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/codec/data.rb 
b/proton-c/bindings/ruby/lib/codec/data.rb
index 69e9ed1..efefa99 100644
--- a/proton-c/bindings/ruby/lib/codec/data.rb
+++ b/proton-c/bindings/ruby/lib/codec/data.rb
@@ -96,13 +96,13 @@ module Qpid::Proton::Codec
       end
 
       # destructor
-      ObjectSpace.define_finalizer(self, self.class.finalize!(@data))
+      ObjectSpace.define_finalizer(self, self.class.finalize!(@data, @free))
     end
 
     # @private
-    def self.finalize!(data)
+    def self.finalize!(data, free)
       proc {
-        Cproton.pn_data_free(data) if @free
+        Cproton.pn_data_free(data) if free
       }
     end
 
@@ -441,6 +441,27 @@ module Qpid::Proton::Codec
       null
     end
 
+    # Puts an arbitrary object type.
+    #
+    # The Data instance will determine which AMQP type is appropriate and will
+    # use that to encode the object.
+    #
+    # @param object [Object] The value.
+    #
+    def object=(object)
+      Mapping.for_class(object.class).put(self, object)
+    end
+
+    # Gets the current node, based on how it was encoded.
+    #
+    # @return [Object] The current node.
+    #
+    def object
+      type = self.type
+      return nil if type.nil?
+      type.get(data)
+    end
+
     # Checks if the current node is null.
     #
     # @return [Boolean] True if the node is null.


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

Reply via email to