PROTON-799: Updated the Ruby namespaces.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/41b9b85e Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/41b9b85e Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/41b9b85e Branch: refs/heads/ruby-engine-apis Commit: 41b9b85e55fdbb0cc6682b74db63cf15f5132f91 Parents: 46b91f7 Author: Darryl L. Pierce <mcpie...@gmail.com> Authored: Wed Apr 29 16:08:50 2015 -0400 Committer: Darryl L. Pierce <mcpie...@gmail.com> Committed: Thu May 14 09:28:11 2015 -0400 ---------------------------------------------------------------------- examples/ruby/messenger/client.rb | 2 +- examples/ruby/messenger/mailserver.rb | 3 +- examples/ruby/messenger/passive_recv.rb | 2 +- examples/ruby/messenger/recv.rb | 2 +- examples/ruby/messenger/send.rb | 2 +- proton-c/bindings/ruby/lib/codec/data.rb | 1487 ++++++++++-------- proton-c/bindings/ruby/lib/codec/mapping.rb | 247 ++- proton-c/bindings/ruby/lib/core/exceptions.rb | 4 +- proton-c/bindings/ruby/lib/core/message.rb | 1060 +++++++------ proton-c/bindings/ruby/lib/messenger/filters.rb | 59 +- .../bindings/ruby/lib/messenger/messenger.rb | 1222 +++++++------- .../bindings/ruby/lib/messenger/selectable.rb | 200 ++- .../bindings/ruby/lib/messenger/subscription.rb | 24 +- proton-c/bindings/ruby/lib/messenger/tracker.rb | 24 +- .../ruby/lib/messenger/tracker_status.rb | 76 +- proton-c/bindings/ruby/lib/types/array.rb | 47 +- proton-c/bindings/ruby/lib/types/described.rb | 69 +- proton-c/bindings/ruby/lib/types/hash.rb | 3 +- proton-c/bindings/ruby/lib/types/strings.rb | 67 +- .../bindings/ruby/lib/util/error_handler.rb | 139 +- proton-c/bindings/ruby/lib/util/version.rb | 16 +- 21 files changed, 2420 insertions(+), 2335 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41b9b85e/examples/ruby/messenger/client.rb ---------------------------------------------------------------------- diff --git a/examples/ruby/messenger/client.rb b/examples/ruby/messenger/client.rb index 571744c..a2c2564 100644 --- a/examples/ruby/messenger/client.rb +++ b/examples/ruby/messenger/client.rb @@ -68,7 +68,7 @@ def log(text) printf "#{Time.new}: #{text}\n" if $options[:verbose] end -msgr = Qpid::Proton::Messenger.new +msgr = Qpid::Proton::Messenger::Messenger.new msgr.start msg = Qpid::Proton::Message.new http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41b9b85e/examples/ruby/messenger/mailserver.rb ---------------------------------------------------------------------- diff --git a/examples/ruby/messenger/mailserver.rb b/examples/ruby/messenger/mailserver.rb index 2d353ca..594a0e3 100644 --- a/examples/ruby/messenger/mailserver.rb +++ b/examples/ruby/messenger/mailserver.rb @@ -50,7 +50,7 @@ def log(text) STDOUT.puts "#{Time.new}: #{text}" if $options[:verbose] end -msgr = Qpid::Proton::Messenger.new +msgr = Qpid::Proton::Messenger::Messenger.new msgr.start $options[:address].each {|addr| msgr.subscribe(addr)} @@ -82,4 +82,3 @@ loop do end msgr.stop - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41b9b85e/examples/ruby/messenger/passive_recv.rb ---------------------------------------------------------------------- diff --git a/examples/ruby/messenger/passive_recv.rb b/examples/ruby/messenger/passive_recv.rb index a3625ac..d1fa854 100644 --- a/examples/ruby/messenger/passive_recv.rb +++ b/examples/ruby/messenger/passive_recv.rb @@ -31,7 +31,7 @@ end addresses = ["~0.0.0.0"] if addresses.empty? -messenger = Qpid::Proton::Messenger.new +messenger = Qpid::Proton::Messenger::Messenger.new messenger.passive = true begin http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41b9b85e/examples/ruby/messenger/recv.rb ---------------------------------------------------------------------- diff --git a/examples/ruby/messenger/recv.rb b/examples/ruby/messenger/recv.rb index 4e464f1..960de4d 100644 --- a/examples/ruby/messenger/recv.rb +++ b/examples/ruby/messenger/recv.rb @@ -31,7 +31,7 @@ end addresses = ["~0.0.0.0"] if addresses.empty? -messenger = Qpid::Proton::Messenger.new +messenger = Qpid::Proton::Messenger::Messenger.new begin messenger.start http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41b9b85e/examples/ruby/messenger/send.rb ---------------------------------------------------------------------- diff --git a/examples/ruby/messenger/send.rb b/examples/ruby/messenger/send.rb index 81ce733..bdbeb4d 100644 --- a/examples/ruby/messenger/send.rb +++ b/examples/ruby/messenger/send.rb @@ -37,7 +37,7 @@ end options[:address] = "0.0.0.0" unless options[:address] messages << "Hello world!" if messages.empty? -messenger = Qpid::Proton::Messenger.new +messenger = Qpid::Proton::Messenger::Messenger.new messenger.start msg = Qpid::Proton::Message.new http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41b9b85e/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 b6b3002..69e9ed1 100644 --- a/proton-c/bindings/ruby/lib/codec/data.rb +++ b/proton-c/bindings/ruby/lib/codec/data.rb @@ -17,772 +17,875 @@ # under the License. #++ -module Qpid # :nodoc: - - module Proton # :nodoc: - - # +DataError+ is raised when an error occurs while encoding - # or decoding data. - class DataError < Exception; end - - # The +Data+ class provides an interface for decoding, extracting, - # creating, and encoding arbitrary AMQP data. A +Data+ object - # contains a tree of AMQP values. Leaf nodes in this tree correspond - # to scalars in the AMQP type system such as INT or STRING. Interior - # nodes in this tree correspond to compound values in the AMQP type - # system such as *LIST*,*MAP*, *ARRAY*, or *DESCRIBED*. The root node - # of the tree is the +Data+ object itself and can have an arbitrary - # number of children. - # - # A +Data+ object maintains the notion of the current sibling node - # and a current parent node. Siblings are ordered within their parent. - # Values are accessed and/or added by using the #next, #prev, - # #enter, and #exit methods to navigate to the desired location in - # the tree and using the supplied variety of mutator and accessor - # methods to access or add a value of the desired type. - # - # The mutator methods will always add a value _after_ the current node - # in the tree. If the current node has a next sibling the mutator method - # will overwrite the value on this node. If there is no current node - # or the current node has no next sibling then one will be added. The - # accessor methods always set the added/modified node to the current - # node. The accessor methods read the value of the current node and do - # not change which node is current. - # - # The following types of scalar values are supported: - # - # * *NULL* - # * *BOOL* - # * *UBYTE* - # * *BYTE* - # * *USHORT* - # * *SHORT* - # * *UINT* - # * *INT* - # * *CHAR* - # * *ULONG* - # * *LONG* - # * *TIMESTAMP* - # * *FLOAT* - # * *DOUBLE* - # * *DECIMAL32* - # * *DECIMAL64* - # * *DECIMAL128* - # * *UUID* - # * *BINARY* - # * *STRING* - # * *SYMBOL* - # - # The following types of compound values are supported: - # - # * *DESCRIBED* - # * *ARRAY* - # * *LIST* - # * *MAP* - # - class Data - - # Creates a new instance with the specified capacity. - # - # ==== Options - # - # * capacity - the capacity - # - def initialize(capacity = 16) - if (!capacity.nil?) && - (capacity.is_a?(Fixnum) || - capacity.is_a?(Bignum)) - @data = Cproton.pn_data(capacity) - @free = true - else - @data = capacity - @free = false - end - - # destructor - ObjectSpace.define_finalizer(self, self.class.finalize!(@data)) - end +module Qpid::Proton::Codec + + # +DataError+ is raised when an error occurs while encoding + # or decoding data. + class DataError < Exception; end + + # The +Data+ class provides an interface for decoding, extracting, + # creating, and encoding arbitrary AMQP data. A +Data+ object + # contains a tree of AMQP values. Leaf nodes in this tree correspond + # to scalars in the AMQP type system such as INT or STRING. Interior + # nodes in this tree correspond to compound values in the AMQP type + # system such as *LIST*,*MAP*, *ARRAY*, or *DESCRIBED*. The root node + # of the tree is the +Data+ object itself and can have an arbitrary + # number of children. + # + # A +Data+ object maintains the notion of the current sibling node + # and a current parent node. Siblings are ordered within their parent. + # Values are accessed and/or added by using the #next, #prev, + # #enter, and #exit methods to navigate to the desired location in + # the tree and using the supplied variety of mutator and accessor + # methods to access or add a value of the desired type. + # + # The mutator methods will always add a value _after_ the current node + # in the tree. If the current node has a next sibling the mutator method + # will overwrite the value on this node. If there is no current node + # or the current node has no next sibling then one will be added. The + # accessor methods always set the added/modified node to the current + # node. The accessor methods read the value of the current node and do + # not change which node is current. + # + # The following types of scalar values are supported: + # + # * NULL + # * BOOL + # * UBYTE + # * BYTE + # * USHORT + # * SHORT + # * UINT + # * INT + # * CHAR + # * ULONG + # * LONG + # * TIMESTAMP + # * FLOAT + # * DOUBLE + # * DECIMAL32 + # * DECIMAL64 + # * DECIMAL128 + # * UUID + # * BINARY + # * STRING + # * SYMBOL + # + # The following types of compound values are supported: + # + # * DESCRIBED + # * ARRAY + # * LIST + # * MAP + # + class Data + + # Creates a new instance with the specified capacity. + # + # @param capacity [Fixnum, Object] The initial capacity or content. + # + def initialize(capacity = 16) + if (!capacity.nil?) && + (capacity.is_a?(Fixnum) || + capacity.is_a?(Bignum)) + @data = Cproton.pn_data(capacity) + @free = true + else + @data = capacity + @free = false + end + + # destructor + ObjectSpace.define_finalizer(self, self.class.finalize!(@data)) + end - def self.finalize!(data) # :nodoc: - proc { - Cproton.pn_data_free(data) if @free - } - end + # @private + def self.finalize!(data) + proc { + Cproton.pn_data_free(data) if @free + } + end - def to_s - tmp = Cproton.pn_string("") - Cproton.pn_inspect(@data, tmp) - result = Cproton.pn_string_get(tmp) - Cproton.pn_free(tmp) - return result - end + # @private + def to_s + tmp = Cproton.pn_string("") + Cproton.pn_inspect(@data, tmp) + result = Cproton.pn_string_get(tmp) + Cproton.pn_free(tmp) + return result + end - # Clears the object. - def clear - Cproton.pn_data_clear(@data) - end + # Clears the object. + # + def clear + Cproton.pn_data_clear(@data) + end - # Clears the current node and sets the parent to the root node. - # - # Clearing the current node sets it _before_ the first node, calling - # #next will advance to the first node. - def rewind - Cproton.pn_data_rewind(@data) - end + # Clears the current node and sets the parent to the root node. + # + # Clearing the current node sets it *before* the first node, calling + # #next will advance to the first node. + # + def rewind + Cproton.pn_data_rewind(@data) + end - # Advances the current node to its next sibling and returns its types. - # - # If there is no next sibling the current node remains unchanged - # and nil is returned. - def next(print = false) - Cproton.pn_data_next(@data) - end + # Advances the current node to its next sibling and returns its types. + # + # If there is no next sibling the current node remains unchanged + # and nil is returned. + # + def next + Cproton.pn_data_next(@data) + end - # Advances the current node to its previous sibling and returns its type. - # - # If there is no previous sibling then the current node remains unchanged - # and nil is return. - def prev - return Cproton.pn_data_prev(@data) ? type : nil - end + # Advances the current node to its previous sibling and returns its type. + # + # If there is no previous sibling then the current node remains unchanged + # and nil is return. + # + def prev + return Cproton.pn_data_prev(@data) ? type : nil + end - # Sets the parent node to the current node and clears the current node. - # - # Clearing the current node sets it _before_ the first child. - def enter - Cproton.pn_data_enter(@data) - end + # Sets the parent node to the current node and clears the current node. + # + # Clearing the current node sets it _before_ the first child. + # + def enter + Cproton.pn_data_enter(@data) + end - # Sets the current node to the parent node and the parent node to its own - # parent. - def exit - Cproton.pn_data_exit(@data) - end + # Sets the current node to the parent node and the parent node to its own + # parent. + # + def exit + Cproton.pn_data_exit(@data) + end - # Returns the numeric type code of the current node. - def type_code - dtype = Cproton.pn_data_type(@data) - return (dtype == -1) ? nil : dtype - end + # Returns the numeric type code of the current node. + # + # @return [Fixnum] The current node type. + # @return [nil] If there is no current node. + # + def type_code + dtype = Cproton.pn_data_type(@data) + return (dtype == -1) ? nil : dtype + end - # Return the Type object for the current node - def type - Mapping.for_code(type_code) - end + # Return the type object for the current node + # + # @param [Fixnum] The object type. + # + # @see #type_code + # + def type + Mapping.for_code(type_code) + end - # Returns a representation of the data encoded in AMQP format. - def encode - buffer = "\0"*1024 - loop do - cd = Cproton.pn_data_encode(@data, buffer, buffer.length) - if cd == Cproton::PN_OVERFLOW - buffer *= 2 - elsif cd >= 0 - return buffer[0...cd] - else - check(cd) - end + # Returns a representation of the data encoded in AMQP format. + # + # @return [String] The context of the Data as an AMQP data string. + # + # @example + # + # @data.string = "This is a test." + # @encoded = @data.encode + # + # # @encoded now contains the text "This is a test." encoded for + # # AMQP transport. + # + def encode + buffer = "\0"*1024 + loop do + cd = Cproton.pn_data_encode(@data, buffer, buffer.length) + if cd == Cproton::PN_OVERFLOW + buffer *= 2 + elsif cd >= 0 + return buffer[0...cd] + else + check(cd) end end + end - # Decodes the first value from supplied AMQP data and returns the number - # of bytes consumed. - # - # ==== Options - # - # * encoded - the encoded data - # - def decode(encoded) - check(Cproton.pn_data_decode(@data, encoded, encoded.length)) - end - - # Puts a list value. - # - # Elements may be filled by entering the list node and putting element - # values. - # - # ==== Examples - # - # data = Qpid::Proton::Data.new - # data.put_list - # data.enter - # data.int = 1 - # data.int = 2 - # data.int = 3 - # data.exit - # - def put_list - check(Cproton.pn_data_put_list(@data)) - end + # Decodes the first value from supplied AMQP data and returns the number + # of bytes consumed. + # + # @param encoded [String] The encoded data. + # + # @example + # + # # SCENARIO: A string of encoded data, @encoded, contains the text + # # of "This is a test." and is passed to an instance of Data + # # for decoding. + # + # @data.decode(@encoded) + # @data.string #=> "This is a test." + # + def decode(encoded) + check(Cproton.pn_data_decode(@data, encoded, encoded.length)) + end - # If the current node is a list, this returns the number of elements. - # Otherwise, it returns zero. - # - # List elements can be accessed by entering the list. - # - # ==== Examples - # - # count = @data.list - # @data.enter - # (0...count).each - # type = @data.next - # puts "Value: #{@data.string}" if type == STRING - # # ... process other node types - # end - def list - Cproton.pn_data_get_list(@data) - end + # Puts a list value. + # + # Elements may be filled by entering the list node and putting element + # values. + # + # @example + # + # data = Qpid::Proton::Data.new + # data.put_list + # data.enter + # data.int = 1 + # data.int = 2 + # data.int = 3 + # data.exit + # + def put_list + check(Cproton.pn_data_put_list(@data)) + end - # Puts a map value. - # - # Elements may be filled by entering the map node and putting alternating - # key/value pairs. - # - # ==== Examples - # - # data = Qpid::Proton::Data.new - # data.put_map - # data.enter - # data.string = "key" - # data.string = "value" - # data.exit - # - def put_map - check(Cproton.pn_data_put_map(@data)) - end + # If the current node is a list, this returns the number of elements. + # Otherwise, it returns zero. + # + # List elements can be accessed by entering the list. + # + # @example + # + # count = @data.list + # @data.enter + # (0...count).each + # type = @data.next + # puts "Value: #{@data.string}" if type == STRING + # # ... process other node types + # end + def list + Cproton.pn_data_get_list(@data) + end - # If the current node is a map, this returns the number of child - # elements. Otherwise, it returns zero. - # - # Key/value pairs can be accessed by entering the map. - # - # ==== Examples - # - # count = @data.map - # @data.enter - # (0...count).each do - # type = @data.next - # puts "Key=#{@data.string}" if type == STRING - # # ... process other key types - # type = @data.next - # puts "Value=#{@data.string}" if type == STRING - # # ... process other value types - # end - # @data.exit - def map - Cproton.pn_data_get_map(@data) - end + # Puts a map value. + # + # Elements may be filled by entering the map node and putting alternating + # key/value pairs. + # + # @example + # + # data = Qpid::Proton::Data.new + # data.put_map + # data.enter + # data.string = "key" + # data.string = "value" + # data.exit + # + def put_map + check(Cproton.pn_data_put_map(@data)) + end - def get_map # :nodoc: - ::Hash.proton_data_get(self) - end + # If the current node is a map, this returns the number of child + # elements. Otherwise, it returns zero. + # + # Key/value pairs can be accessed by entering the map. + # + # @example + # + # count = @data.map + # @data.enter + # (0...count).each do + # type = @data.next + # puts "Key=#{@data.string}" if type == STRING + # # ... process other key types + # type = @data.next + # puts "Value=#{@data.string}" if type == STRING + # # ... process other value types + # end + # @data.exit + def map + Cproton.pn_data_get_map(@data) + end - # Puts an array value. - # - # Elements may be filled by entering the array node and putting the - # element values. The values must all be of the specified array element - # type. - # - # If an array is *described* then the first child value of the array - # is the descriptor and may be of any type. - # - # ==== Options - # - # * described - specifies whether the array is described - # * element_type - the type of the array elements - # - # ==== Examples - # - # # create an array of integer values - # data = Qpid::Proton::Data.new - # data.put_array(false, INT) - # data.enter - # data.int = 1 - # data.int = 2 - # data.int = 3 - # data.exit - # - # # create an array of double values - # data.put_array(true, DOUBLE) - # data.enter - # data.symbol = "array-descriptor" - # data.double = 1.1 - # data.double = 1.2 - # data.double = 1.3 - # data.exit - # - def put_array(described, element_type) - check(Cproton.pn_data_put_array(@data, described, element_type.code)) - end + # @private + def get_map + ::Hash.proton_data_get(self) + end - # If the current node is an array, returns a tuple of the element count, a - # boolean indicating whether the array is described, and the type of each - # element. Otherwise it returns +(0, false, nil). - # - # Array data can be accessed by entering the array. - # - # ==== Examples - # - # # get the details of thecurrent array - # count, described, array_type = @data.array - # - # # enter the node - # data.enter - # - # # get the next node - # data.next - # puts "Descriptor: #{data.symbol}" if described - # (0...count).each do - # @data.next - # puts "Element: #{@data.string}" - # end - def array - count = Cproton.pn_data_get_array(@data) - described = Cproton.pn_data_is_array_described(@data) - array_type = Cproton.pn_data_get_array_type(@data) - return nil if array_type == -1 - [count, described, Mapping.for_code(array_type) ] - end + # Puts an array value. + # + # Elements may be filled by entering the array node and putting the + # element values. The values must all be of the specified array element + # type. + # + # If an array is *described* then the first child value of the array + # is the descriptor and may be of any type. + # + # @param described [Boolean] True if the array is described. + # @param element_type [Fixnum] The AMQP type for each element of the array. + # + # @example + # + # # create an array of integer values + # data = Qpid::Proton::Data.new + # data.put_array(false, INT) + # data.enter + # data.int = 1 + # data.int = 2 + # data.int = 3 + # data.exit + # + # # create a described array of double values + # data.put_array(true, DOUBLE) + # data.enter + # data.symbol = "array-descriptor" + # data.double = 1.1 + # data.double = 1.2 + # data.double = 1.3 + # data.exit + # + def put_array(described, element_type) + check(Cproton.pn_data_put_array(@data, described, element_type.code)) + end - def get_array # :nodoc: - ::Array.proton_get(self) - end + # If the current node is an array, returns a tuple of the element count, a + # boolean indicating whether the array is described, and the type of each + # element. Otherwise it returns +(0, false, nil). + # + # Array data can be accessed by entering the array. + # + # @example + # + # # get the details of thecurrent array + # count, described, array_type = @data.array + # + # # enter the node + # data.enter + # + # # get the next node + # data.next + # puts "Descriptor: #{data.symbol}" if described + # (0...count).each do + # @data.next + # puts "Element: #{@data.string}" + # end + def array + count = Cproton.pn_data_get_array(@data) + described = Cproton.pn_data_is_array_described(@data) + array_type = Cproton.pn_data_get_array_type(@data) + return nil if array_type == -1 + [count, described, Mapping.for_code(array_type) ] + end - # Puts a described value. - # - # A described node has two children, the descriptor and the value. - # These are specified by entering the node and putting the - # desired values. - # - # ==== Examples - # - # data = Qpid::Proton::Data.new - # data.put_described - # data.enter - # data.symbol = "value-descriptor" - # data.string = "the value" - # data.exit - # - def put_described - check(Cproton.pn_data_put_described(@data)) - end + # @private + def get_array + ::Array.proton_get(self) + end - def get_described # :nodoc: - raise TypeError, "not a described type" unless self.described? - self.enter - self.next - type = self.type - descriptor = type.get(self) - self.next - type = self.type - value = type.get(self) - self.exit - Described.new(descriptor, value) - end + # Puts a described value. + # + # A described node has two children, the descriptor and the value. + # These are specified by entering the node and putting the + # desired values. + # + # @example + # + # data = Qpid::Proton::Data.new + # data.put_described + # data.enter + # data.symbol = "value-descriptor" + # data.string = "the value" + # data.exit + # + def put_described + check(Cproton.pn_data_put_described(@data)) + end - # Checks if the current node is a described value. - # - # The described and value may be accessed by entering the described value. - # - # ==== Examples - # - # if @data.described? - # @data.enter - # puts "The symbol is #{@data.symbol}" - # puts "The value is #{@data.string}" - # end - def described? - Cproton.pn_data_is_described(@data) - end + # @private + def get_described + raise TypeError, "not a described type" unless self.described? + self.enter + self.next + type = self.type + descriptor = type.get(self) + self.next + type = self.type + value = type.get(self) + self.exit + Described.new(descriptor, value) + end - # Puts a null value. - def null - check(Cproton.pn_data_put_null(@data)) - end + # Checks if the current node is a described value. + # + # The described and value may be accessed by entering the described value. + # + # @example + # + # if @data.described? + # @data.enter + # puts "The symbol is #{@data.symbol}" + # puts "The value is #{@data.string}" + # end + def described? + Cproton.pn_data_is_described(@data) + end - # Utility method for Qpid::Proton::Mapping - def null=(value) # :nodoc: - null - end + # Puts a null value. + # + def null + check(Cproton.pn_data_put_null(@data)) + end - # Checks if the current node is null. - def null? - Cproton.pn_data_is_null(@data) - end + # Utility method for Qpid::Proton::Mapping + # + # @private + # + def null=(value) + null + end - # Puts a boolean value. - # - # ==== Options - # - # * value - the boolean value - def bool=(value) - check(Cproton.pn_data_put_bool(@data, value)) - end + # Checks if the current node is null. + # + # @return [Boolean] True if the node is null. + # + def null? + Cproton.pn_data_is_null(@data) + end - # If the current node is a boolean, then it returns the value. Otherwise, - # it returns false. - def bool - Cproton.pn_data_get_bool(@data) - end + # Puts a boolean value. + # + # @param value [Boolean] The boolean value. + # + def bool=(value) + check(Cproton.pn_data_put_bool(@data, value)) + end - # Puts an unsigned byte value. - # - # ==== Options - # - # * value - the unsigned byte value - def ubyte=(value) - check(Cproton.pn_data_put_ubyte(@data, value)) - end + # If the current node is a boolean, then it returns the value. Otherwise, + # it returns false. + # + # @return [Boolean] The boolean value. + # + def bool + Cproton.pn_data_get_bool(@data) + end - # If the current node is an unsigned byte, returns its value. Otherwise, - # it reutrns 0. - def ubyte - Cproton.pn_data_get_ubyte(@data) - end + # Puts an unsigned byte value. + # + # @param value [Fixnum] The unsigned byte value. + # + def ubyte=(value) + check(Cproton.pn_data_put_ubyte(@data, value)) + end - # Puts a byte value. - # - # ==== Options - # - # * value - the byte value - def byte=(value) - check(Cproton.pn_data_put_byte(@data, value)) - end + # If the current node is an unsigned byte, returns its value. Otherwise, + # it returns 0. + # + # @return [Fixnum] The unsigned byte value. + # + def ubyte + Cproton.pn_data_get_ubyte(@data) + end - # If the current node is an byte, returns its value. Otherwise, - # it returns 0. - def byte - Cproton.pn_data_get_byte(@data) - end + # Puts a byte value. + # + # @param value [Fixnum] The byte value. + # + def byte=(value) + check(Cproton.pn_data_put_byte(@data, value)) + end - # Puts an unsigned short value. - # - # ==== Options - # - # * value - the unsigned short value - def ushort=(value) - check(Cproton.pn_data_put_ushort(@data, value)) - end + # If the current node is an byte, returns its value. Otherwise, + # it returns 0. + # + # @return [Fixnum] The byte value. + # + def byte + Cproton.pn_data_get_byte(@data) + end - # If the current node is an unsigned short, returns its value. Otherwise, - # it returns 0. - def ushort - Cproton.pn_data_get_ushort(@data) - end + # Puts an unsigned short value. + # + # @param value [Fixnum] The unsigned short value + # + def ushort=(value) + check(Cproton.pn_data_put_ushort(@data, value)) + end - # Puts a short value. - # - # ==== Options - # - # * value - the short value - def short=(value) - check(Cproton.pn_data_put_short(@data, value)) - end + # If the current node is an unsigned short, returns its value. Otherwise, + # it returns 0. + # + # @return [Fixnum] The unsigned short value. + # + def ushort + Cproton.pn_data_get_ushort(@data) + end - # If the current node is a short, returns its value. Otherwise, - # returns a 0. - def short - Cproton.pn_data_get_short(@data) - end + # Puts a short value. + # + # @param value [Fixnum] The short value. + # + def short=(value) + check(Cproton.pn_data_put_short(@data, value)) + end - # Puts an unsigned integer value. - # - # ==== Options - # - # * value - the unsigned integer value - def uint=(value) - raise TypeError if value.nil? - raise RangeError, "invalid uint: #{value}" if value < 0 - check(Cproton.pn_data_put_uint(@data, value)) - end + # If the current node is a short, returns its value. Otherwise, + # returns a 0. + # + # @return [Fixnum] The short value. + # + def short + Cproton.pn_data_get_short(@data) + end - # If the current node is an unsigned int, returns its value. Otherwise, - # returns 0. - def uint - Cproton.pn_data_get_uint(@data) - end + # Puts an unsigned integer value. + # + # @param value [Fixnum] the unsigned integer value + # + def uint=(value) + raise TypeError if value.nil? + raise RangeError, "invalid uint: #{value}" if value < 0 + check(Cproton.pn_data_put_uint(@data, value)) + end - # Puts an integer value. - # - # ==== Options - # - # * value - the integer value - def int=(value) - check(Cproton.pn_data_put_int(@data, value)) - end + # If the current node is an unsigned int, returns its value. Otherwise, + # returns 0. + # + # @return [Fixnum] The unsigned integer value. + # + def uint + Cproton.pn_data_get_uint(@data) + end - # If the current node is an integer, returns its value. Otherwise, - # returns 0. - def int - Cproton.pn_data_get_int(@data) - end + # Puts an integer value. + # + # ==== Options + # + # * value - the integer value + def int=(value) + check(Cproton.pn_data_put_int(@data, value)) + end - # Puts a character value. - # - # ==== Options - # - # * value - the character value - def char=(value) - check(Cproton.pn_data_put_char(@data, value)) - end + # If the current node is an integer, returns its value. Otherwise, + # returns 0. + # + # @return [Fixnum] The integer value. + # + def int + Cproton.pn_data_get_int(@data) + end - # If the current node is a character, returns its value. Otherwise, - # returns 0. - def char - Cproton.pn_data_get_char(@data) - end + # Puts a character value. + # + # @param value [Fixnum] The character value. + # + def char=(value) + check(Cproton.pn_data_put_char(@data, value)) + end - # Puts an unsigned long value. - # - # ==== Options - # - # * value - the unsigned long value - def ulong=(value) - raise TypeError if value.nil? - raise RangeError, "invalid ulong: #{value}" if value < 0 - check(Cproton.pn_data_put_ulong(@data, value)) - end + # If the current node is a character, returns its value. Otherwise, + # returns 0. + # + # @return [Fixnum] The character value. + # + def char + Cproton.pn_data_get_char(@data) + end - # If the current node is an unsigned long, returns its value. Otherwise, - # returns 0. - def ulong - Cproton.pn_data_get_ulong(@data) - end + # Puts an unsigned long value. + # + # @param value [Fixnum] The unsigned long value. + # + def ulong=(value) + raise TypeError if value.nil? + raise RangeError, "invalid ulong: #{value}" if value < 0 + check(Cproton.pn_data_put_ulong(@data, value)) + end - # Puts a long value. - # - # ==== Options - # - # * value - the long value - def long=(value) - check(Cproton.pn_data_put_long(@data, value)) - end + # If the current node is an unsigned long, returns its value. Otherwise, + # returns 0. + # + # @return [Fixnum] The unsigned long value. + # + def ulong + Cproton.pn_data_get_ulong(@data) + end - # If the current node is a long, returns its value. Otherwise, returns 0. - def long - Cproton.pn_data_get_long(@data) - end + # Puts a long value. + # + # @param value [Fixnum] The long value. + # + def long=(value) + check(Cproton.pn_data_put_long(@data, value)) + end - # Puts a timestamp value. - # - # ==== Options - # - # * value - the timestamp value - def timestamp=(value) - value = value.to_i if (!value.nil? && value.is_a?(Time)) - check(Cproton.pn_data_put_timestamp(@data, value)) - end + # If the current node is a long, returns its value. Otherwise, returns 0. + # + # @return [Fixnum] The long value. + def long + Cproton.pn_data_get_long(@data) + end - # If the current node is a timestamp, returns its value. Otherwise, - # returns 0. - def timestamp - Cproton.pn_data_get_timestamp(@data) - end + # Puts a timestamp value. + # + # @param value [Fixnum] The timestamp value. + # + def timestamp=(value) + value = value.to_i if (!value.nil? && value.is_a?(Time)) + check(Cproton.pn_data_put_timestamp(@data, value)) + end - # Puts a float value. - # - # ==== Options - # - # * value - the float value - def float=(value) - check(Cproton.pn_data_put_float(@data, value)) - end + # If the current node is a timestamp, returns its value. Otherwise, + # returns 0. + # + # @return [Fixnum] The timestamp value. + # + def timestamp + Cproton.pn_data_get_timestamp(@data) + end - # If the current node is a float, returns its value. Otherwise, - # returns 0. - def float - Cproton.pn_data_get_float(@data) - end + # Puts a float value. + # + # @param value [Float] The floating point value. + # + def float=(value) + check(Cproton.pn_data_put_float(@data, value)) + end - # Puts a double value. - # - # ==== Options - # - # * value - the double value - def double=(value) - check(Cproton.pn_data_put_double(@data, value)) - end + # If the current node is a float, returns its value. Otherwise, + # returns 0. + # + # @return [Float] The floating point value. + # + def float + Cproton.pn_data_get_float(@data) + end - # If the current node is a double, returns its value. Otherwise, - # returns 0. - def double - Cproton.pn_data_get_double(@data) - end + # Puts a double value. + # + # @param value [Float] The double precision floating point value. + # + def double=(value) + check(Cproton.pn_data_put_double(@data, value)) + end - # Puts a decimal32 value. - # - # ==== Options - # - # * value - the decimal32 value - def decimal32=(value) - check(Cproton.pn_data_put_decimal32(@data, value)) - end + # If the current node is a double, returns its value. Otherwise, + # returns 0. + # + # @return [Float] The double precision floating point value. + # + def double + Cproton.pn_data_get_double(@data) + end - # If the current node is a decimal32, returns its value. Otherwise, - # returns 0. - def decimal32 - Cproton.pn_data_get_decimal32(@data) - end + # Puts a decimal32 value. + # + # @param value [Fixnum] The decimal32 value. + # + def decimal32=(value) + check(Cproton.pn_data_put_decimal32(@data, value)) + end - # Puts a decimal64 value. - # - # ==== Options - # - # * value - the decimal64 value - def decimal64=(value) - check(Cproton.pn_data_put_decimal64(@data, value)) - end + # If the current node is a decimal32, returns its value. Otherwise, + # returns 0. + # + # @return [Fixnum] The decimal32 value. + # + def decimal32 + Cproton.pn_data_get_decimal32(@data) + end - # If the current node is a decimal64, returns its value. Otherwise, - # it returns 0. - def decimal64 - Cproton.pn_data_get_decimal64(@data) - end + # Puts a decimal64 value. + # + # @param value [Fixnum] The decimal64 value. + # + def decimal64=(value) + check(Cproton.pn_data_put_decimal64(@data, value)) + end - # Puts a decimal128 value. - # - # ==== Options - # - # * value - the decimal128 value - def decimal128=(value) - raise TypeError, "invalid decimal128 value: #{value}" if value.nil? - value = value.to_s(16).rjust(32, "0") - bytes = [] - value.scan(/(..)/) {|v| bytes << v[0].to_i(16)} - check(Cproton.pn_data_put_decimal128(@data, bytes)) - end + # If the current node is a decimal64, returns its value. Otherwise, + # it returns 0. + # + # @return [Fixnum] The decimal64 value. + # + def decimal64 + Cproton.pn_data_get_decimal64(@data) + end - # If the current node is a decimal128, returns its value. Otherwise, - # returns 0. - def decimal128 - value = "" - Cproton.pn_data_get_decimal128(@data).each{|val| value += ("%02x" % val)} - value.to_i(16) - end + # Puts a decimal128 value. + # + # @param value [Fixnum] The decimal128 value. + # + def decimal128=(value) + raise TypeError, "invalid decimal128 value: #{value}" if value.nil? + value = value.to_s(16).rjust(32, "0") + bytes = [] + value.scan(/(..)/) {|v| bytes << v[0].to_i(16)} + check(Cproton.pn_data_put_decimal128(@data, bytes)) + end - # Puts a +UUID+ value. - # - # The UUID is expected to be in the format of a string or else a 128-bit - # integer value. - # - # ==== Options - # - # * value - the +UUID+ - # - # ==== Examples - # - # # set a uuid value from a string value - # require 'securerandom' - # @data.uuid = SecureRandom.uuid - # - # # or - # @data.uuid = "fd0289a5-8eec-4a08-9283-81d02c9d2fff" - # - # # set a uuid value from a 128-bit value - # @data.uuid = 0 # sets to 00000000-0000-0000-0000-000000000000 - # - def uuid=(value) - raise ArgumentError, "invalid uuid: #{value}" if value.nil? - - # if the uuid that was submitted was numeric value, then translated - # it into a hex string, otherwise assume it was a string represtation - # and attempt to decode it - if value.is_a? Numeric - value = "%032x" % value - else - raise ArgumentError, "invalid uuid: #{value}" if !valid_uuid?(value) + # If the current node is a decimal128, returns its value. Otherwise, + # returns 0. + # + # @return [Fixnum] The decimal128 value. + # + def decimal128 + value = "" + Cproton.pn_data_get_decimal128(@data).each{|val| value += ("%02x" % val)} + value.to_i(16) + end - value = (value[0, 8] + - value[9, 4] + - value[14, 4] + - value[19, 4] + - value[24, 12]) - end - bytes = [] - value.scan(/(..)/) {|v| bytes << v[0].to_i(16)} - check(Cproton.pn_data_put_uuid(@data, bytes)) - end + # Puts a +UUID+ value. + # + # The UUID is expected to be in the format of a string or else a 128-bit + # integer value. + # + # @param value [String, Numeric] A string or numeric representation of the UUID. + # + # @example + # + # # set a uuid value from a string value + # require 'securerandom' + # @data.uuid = SecureRandom.uuid + # + # # or + # @data.uuid = "fd0289a5-8eec-4a08-9283-81d02c9d2fff" + # + # # set a uuid value from a 128-bit value + # @data.uuid = 0 # sets to 00000000-0000-0000-0000-000000000000 + # + def uuid=(value) + raise ArgumentError, "invalid uuid: #{value}" if value.nil? + + # if the uuid that was submitted was numeric value, then translated + # it into a hex string, otherwise assume it was a string represtation + # and attempt to decode it + if value.is_a? Numeric + value = "%032x" % value + else + raise ArgumentError, "invalid uuid: #{value}" if !valid_uuid?(value) + + value = (value[0, 8] + + value[9, 4] + + value[14, 4] + + value[19, 4] + + value[24, 12]) + end + bytes = [] + value.scan(/(..)/) {|v| bytes << v[0].to_i(16)} + check(Cproton.pn_data_put_uuid(@data, bytes)) + end - # If the current value is a +UUID+, returns its value. Otherwise, - # it returns nil. - def uuid - value = "" - Cproton.pn_data_get_uuid(@data).each{|val| value += ("%02x" % val)} - value.insert(8, "-").insert(13, "-").insert(18, "-").insert(23, "-") - end + # If the current value is a +UUID+, returns its value. Otherwise, + # it returns nil. + # + # @return [String] The string representation of the UUID. + # + def uuid + value = "" + Cproton.pn_data_get_uuid(@data).each{|val| value += ("%02x" % val)} + value.insert(8, "-").insert(13, "-").insert(18, "-").insert(23, "-") + end - # Puts a binary value. - # - # ==== Options - # - # * value - the binary value - def binary=(value) - check(Cproton.pn_data_put_binary(@data, value)) - end + # Puts a binary value. + # + # A binary string is encoded as an ASCII 8-bit string value. This is in + # contranst to other strings, which are treated as UTF-8 encoded. + # + # @param value [String] An arbitrary string value. + # + # @see #string= + # + def binary=(value) + check(Cproton.pn_data_put_binary(@data, value)) + end - # If the current node is binary, returns its value. Otherwise, it returns - # an empty string (""). - def binary - Qpid::Proton::BinaryString.new(Cproton.pn_data_get_binary(@data)) - end + # If the current node is binary, returns its value. Otherwise, it returns + # an empty string (""). + # + # @return [String] The binary string. + # + # @see #string + # + def binary + Qpid::Proton::Types::BinaryString.new(Cproton.pn_data_get_binary(@data)) + end - # Puts a unicode string value. - # - # *NOTE:* A nil value is stored as an empty string rather than as a nil. - # - # ==== Options - # - # * value - the unicode string value - def string=(value) - check(Cproton.pn_data_put_string(@data, value)) - end + # Puts a UTF-8 encoded string value. + # + # *NOTE:* A nil value is stored as an empty string rather than as a nil. + # + # @param value [String] The UTF-8 encoded string value. + # + # @see #binary= + # + def string=(value) + check(Cproton.pn_data_put_string(@data, value)) + end - # If the current node is a string, returns its value. Otherwise, it - # returns an empty string (""). - def string - Qpid::Proton::UTFString.new(Cproton.pn_data_get_string(@data)) - end + # If the current node is a string, returns its value. Otherwise, it + # returns an empty string (""). + # + # @return [String] The UTF-8 encoded string. + # + # @see #binary + # + def string + Qpid::Proton::Types::UTFString.new(Cproton.pn_data_get_string(@data)) + end - # Puts a symbolic value. - # - # ==== Options - # - # * value - the symbol name - def symbol=(value) - check(Cproton.pn_data_put_symbol(@data, value)) - end + # Puts a symbolic value. + # + # @param value [String] The symbolic string value. + # + def symbol=(value) + check(Cproton.pn_data_put_symbol(@data, value)) + end - # If the current node is a symbol, returns its value. Otherwise, it - # returns an empty string (""). - def symbol - Cproton.pn_data_get_symbol(@data) - end + # If the current node is a symbol, returns its value. Otherwise, it + # returns an empty string (""). + # + # @return [String] The symbolic string value. + # + def symbol + Cproton.pn_data_get_symbol(@data) + end - # Get the current value as a single object. - def get - type.get(self); - end + # Get the current value as a single object. + # + # @return [Object] The current node's object. + # + # @see #type_code + # @see #type + # + def get + type.get(self); + end - # Put value as an object of type type_ - def put(value, type_); - type_.put(self, value); - end + # Puts a new value with the given type into the current node. + # + # @param value [Object] The value. + # @param type_code [Mapping] The value's type. + # + # @private + # + def put(value, type_code); + type_code.put(self, value); + end - private + private - def valid_uuid?(value) - # ensure that the UUID is in the right format - # xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx - value =~ /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ - end + def valid_uuid?(value) + # ensure that the UUID is in the right format + # xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx + value =~ /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ + end - def check(err) # :nodoc: - if err < 0 - raise DataError, "[#{err}]: #{Cproton.pn_data_error(@data)}" - else - return err - end + # @private + def check(err) + if err < 0 + raise DataError, "[#{err}]: #{Cproton.pn_data_error(@data)}" + else + return err end end + end + end http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41b9b85e/proton-c/bindings/ruby/lib/codec/mapping.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/codec/mapping.rb b/proton-c/bindings/ruby/lib/codec/mapping.rb index 9189cbc..4a7d5a7 100644 --- a/proton-c/bindings/ruby/lib/codec/mapping.rb +++ b/proton-c/bindings/ruby/lib/codec/mapping.rb @@ -17,154 +17,153 @@ # under the License. #++ -module Qpid # :nodoc: +module Qpid::Proton::Codec - module Proton # :nodoc: + # Maps between Proton types and their Ruby native language counterparts. + # + # @private + class Mapping - # Maps between Proton types and their Ruby native language counterparts. - # - class Mapping - - attr_reader :code - attr_reader :put_method - attr_reader :get_method - - # Creates a new mapping. - # - # ==== Arguments - # - # * code - the AMQP code for this type - # * name - the AMQP name for this type - # * klasses - the Ruby classes for this type - # * getter - overrides the get method for the type - def initialize(code, name, klasses = nil, getter = nil) - - @debug = (name == "bool") - - @code = code - @name = name - - @@by_preferred ||= {} - @@by_code ||= {} - @@by_code["#{code}"] = self - @@by_name ||= {} - @@by_name[name] = self - @@by_class ||= {} - - unless klasses.nil? - klasses.each do |klass| - raise "entry exists for #{klass}" if @@by_class.keys.include? klass - @@by_class[klass] = self unless klass.nil? - end - end - - @put_method = (name + "=").intern + attr_reader :code + attr_reader :put_method + attr_reader :get_method - if getter.nil? - @get_method = name.intern - else - @get_method = getter.intern + # Creates a new mapping. + # + # ==== Arguments + # + # * code - the AMQP code for this type + # * name - the AMQP name for this type + # * klasses - the Ruby classes for this type + # * getter - overrides the get method for the type + def initialize(code, name, klasses = nil, getter = nil) + + @debug = (name == "bool") + + @code = code + @name = name + + @@by_preferred ||= {} + @@by_code ||= {} + @@by_code["#{code}"] = self + @@by_name ||= {} + @@by_name[name] = self + @@by_class ||= {} + + unless klasses.nil? + klasses.each do |klass| + raise "entry exists for #{klass}" if @@by_class.keys.include? klass + @@by_class[klass] = self unless klass.nil? end end - def to_s; @name; end + @put_method = (name + "=").intern - def put(data, value) - data.__send__(@put_method, value) + if getter.nil? + @get_method = name.intern + else + @get_method = getter.intern end + end - def get(data) - data.__send__(@get_method) - end + def to_s; @name; end - def self.for_class(klass) # :nodoc: - @@by_class[klass] - end + def put(data, value) + data.__send__(@put_method, value) + end - def self.for_code(code) - @@by_code["#{code}"] - end + def get(data) + data.__send__(@get_method) + end + def self.for_class(klass) # :nodoc: + @@by_class[klass] end - NULL = Mapping.new(Cproton::PN_NULL, "null", [NilClass], "nil?") - BOOL = Mapping.new(Cproton::PN_BOOL, "bool", [TrueClass, FalseClass], "bool") - UBYTE = Mapping.new(Cproton::PN_UBYTE, "ubyte") - BYTE = Mapping.new(Cproton::PN_BYTE, "byte") - USHORT = Mapping.new(Cproton::PN_USHORT, "ushort") - SHORT = Mapping.new(Cproton::PN_SHORT, "short") - UINT = Mapping.new(Cproton::PN_UINT, "uint") - INT = Mapping.new(Cproton::PN_INT, "int") - CHAR = Mapping.new(Cproton::PN_CHAR, "char") - ULONG = Mapping.new(Cproton::PN_ULONG, "ulong") - LONG = Mapping.new(Cproton::PN_LONG, "long", [Fixnum, Bignum]) - TIMESTAMP = Mapping.new(Cproton::PN_TIMESTAMP, "timestamp", [Date, Time]) - FLOAT = Mapping.new(Cproton::PN_FLOAT, "float") - DOUBLE = Mapping.new(Cproton::PN_DOUBLE, "double", [Float]) - DECIMAL32 = Mapping.new(Cproton::PN_DECIMAL32, "decimal32") - DECIMAL64 = Mapping.new(Cproton::PN_DECIMAL64, "decimal64") - DECIMAL128 = Mapping.new(Cproton::PN_DECIMAL128, "decimal128") - UUID = Mapping.new(Cproton::PN_UUID, "uuid") - BINARY = Mapping.new(Cproton::PN_BINARY, "binary") - STRING = Mapping.new(Cproton::PN_STRING, "string", [String, Symbol, - UTFString, - BinaryString]) - - class << STRING # :nodoc: - def put(data, value) - # if we have a symbol then convert it to a string - value = value.to_s if value.is_a?(Symbol) - - isutf = false - - if value.is_a?(Qpid::Proton::UTFString) - isutf = true - else - # For Ruby 1.8 we will just treat all strings as binary. - # For Ruby 1.9+ we can check the encoding first to see what it is - if RUBY_VERSION >= "1.9" - # If the string is ASCII-8BIT then treat is as binary. Otherwise, - # try to convert it to UTF-8 and, if successful, send as that. - if value.encoding != Encoding::ASCII_8BIT && - value.encode(Encoding::UTF_8).valid_encoding? - isutf = true - end + def self.for_code(code) + @@by_code["#{code}"] + end + + end + + NULL = Mapping.new(Cproton::PN_NULL, "null", [NilClass], "nil?") + BOOL = Mapping.new(Cproton::PN_BOOL, "bool", [TrueClass, FalseClass], "bool") + UBYTE = Mapping.new(Cproton::PN_UBYTE, "ubyte") + BYTE = Mapping.new(Cproton::PN_BYTE, "byte") + USHORT = Mapping.new(Cproton::PN_USHORT, "ushort") + SHORT = Mapping.new(Cproton::PN_SHORT, "short") + UINT = Mapping.new(Cproton::PN_UINT, "uint") + INT = Mapping.new(Cproton::PN_INT, "int") + CHAR = Mapping.new(Cproton::PN_CHAR, "char") + ULONG = Mapping.new(Cproton::PN_ULONG, "ulong") + LONG = Mapping.new(Cproton::PN_LONG, "long", [Fixnum, Bignum]) + TIMESTAMP = Mapping.new(Cproton::PN_TIMESTAMP, "timestamp", [Date, Time]) + FLOAT = Mapping.new(Cproton::PN_FLOAT, "float") + DOUBLE = Mapping.new(Cproton::PN_DOUBLE, "double", [Float]) + DECIMAL32 = Mapping.new(Cproton::PN_DECIMAL32, "decimal32") + DECIMAL64 = Mapping.new(Cproton::PN_DECIMAL64, "decimal64") + DECIMAL128 = Mapping.new(Cproton::PN_DECIMAL128, "decimal128") + UUID = Mapping.new(Cproton::PN_UUID, "uuid") + BINARY = Mapping.new(Cproton::PN_BINARY, "binary") + STRING = Mapping.new(Cproton::PN_STRING, "string", [String, Symbol, + Qpid::Proton::Types::UTFString, + Qpid::Proton::Types::BinaryString]) + + # @private + class << STRING + def put(data, value) + # if we have a symbol then convert it to a string + value = value.to_s if value.is_a?(Symbol) + + isutf = false + + if value.is_a?(Qpid::Proton::Types::UTFString) + isutf = true + else + # For Ruby 1.8 we will just treat all strings as binary. + # For Ruby 1.9+ we can check the encoding first to see what it is + if RUBY_VERSION >= "1.9" + # If the string is ASCII-8BIT then treat is as binary. Otherwise, + # try to convert it to UTF-8 and, if successful, send as that. + if value.encoding != Encoding::ASCII_8BIT && + value.encode(Encoding::UTF_8).valid_encoding? + isutf = true end end + end - data.string = value if isutf - data.binary = value if !isutf + data.string = value if isutf + data.binary = value if !isutf - end end + end - SYMBOL = Mapping.new(Cproton::PN_SYMBOL, "symbol") - DESCRIBED = Mapping.new(Cproton::PN_DESCRIBED, "described", [Qpid::Proton::Described], "get_described") - ARRAY = Mapping.new(Cproton::PN_ARRAY, "array", nil, "get_array") - LIST = Mapping.new(Cproton::PN_LIST, "list", [::Array], "get_array") - MAP = Mapping.new(Cproton::PN_MAP, "map", [::Hash], "get_map") - - class << MAP # :nodoc: - def put(data, map, options = {}) - data.put_map - data.enter - map.each_pair do |key, value| - if options[:keys] == :SYMBOL - SYMBOL.put(data, key) - else - Mapping.for_class(key.class).put(data, key) - end + SYMBOL = Mapping.new(Cproton::PN_SYMBOL, "symbol") + DESCRIBED = Mapping.new(Cproton::PN_DESCRIBED, "described", [Qpid::Proton::Types::Described], "get_described") + ARRAY = Mapping.new(Cproton::PN_ARRAY, "array", nil, "get_array") + LIST = Mapping.new(Cproton::PN_LIST, "list", [::Array], "get_array") + MAP = Mapping.new(Cproton::PN_MAP, "map", [::Hash], "get_map") + + # @private + class << MAP + def put(data, map, options = {}) + data.put_map + data.enter + map.each_pair do |key, value| + if options[:keys] == :SYMBOL + SYMBOL.put(data, key) + else + Mapping.for_class(key.class).put(data, key) + end - if value.nil? - data.null - else - Mapping.for_class(value.class).put(data, value) - end + if value.nil? + data.null + else + Mapping.for_class(value.class).put(data, value) end - data.exit end + data.exit end - end end http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41b9b85e/proton-c/bindings/ruby/lib/core/exceptions.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/core/exceptions.rb b/proton-c/bindings/ruby/lib/core/exceptions.rb index 189f574..5e39ced 100644 --- a/proton-c/bindings/ruby/lib/core/exceptions.rb +++ b/proton-c/bindings/ruby/lib/core/exceptions.rb @@ -17,9 +17,9 @@ # under the License. #++ -module Qpid # :nodoc: +module Qpid - module Proton # :nodoc: + module Proton module Error --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org