lib/amq/protocol/client.rb in amq-protocol-0.9.4 vs lib/amq/protocol/client.rb in amq-protocol-0.9.5

- old
+ new

@@ -15,24 +15,22 @@ DEFAULT_PORT = 5672 # caching EMPTY_STRING = "".freeze - PACK_CHAR = 'C'.freeze - PACK_UINT16 = 'n'.freeze - PACK_UINT16_X2 = 'n2'.freeze - PACK_UINT32 = 'N'.freeze - PACK_UINT32_X2 = 'N2'.freeze - PACK_INT64 = 'q'.freeze - PACK_UCHAR_UINT32 = 'CN'.freeze - PACK_CHAR_UINT16_UINT32 = 'cnN'.freeze + PACK_CHAR = "C".freeze + PACK_UINT16 = "n".freeze + PACK_UINT16_X2 = "n2".freeze + PACK_UINT32 = "N".freeze + PACK_UINT32_X2 = "N2".freeze + PACK_INT64 = "q".freeze + PACK_UCHAR_UINT32 = "CN".freeze + PACK_CHAR_UINT16_UINT32 = "cnN".freeze - PACK_32BIT_FLOAT = 'f'.freeze - PACK_64BIT_FLOAT = 'd'.freeze + PACK_32BIT_FLOAT = "f".freeze + PACK_64BIT_FLOAT = "d".freeze - - # @return [Array] Collection of subclasses of AMQ::Protocol::Class. def self.classes Protocol::Class.classes end @@ -168,24 +166,23 @@ class InternalError < HardError VALUE = 541 end - - # We don't instantiate the following classes, - # as we don't actually need any per-instance state. + # We don"t instantiate the following classes, + # as we don"t actually need any per-instance state. # Also, this is pretty low-level functionality, # hence it should have a reasonable performance. # As everyone knows, garbage collector in MRI performs # really badly, which is another good reason for # not creating any objects, but only use class as # a struct. Creating classes is quite expensive though, # but here the inheritance comes handy and mainly - # as we can't simply make a reference to a function, - # we can't use a hash or an object. I've been also + # as we can"t simply make a reference to a function, + # we can"t use a hash or an object. I"ve been also # considering to have just a bunch of methods, but - # here's the problem, that after we'd require this file, + # here"s the problem, that after we"d require this file, # all these methods would become global which would # be a bad, bad thing to do. class Class @classes = Array.new @@ -278,12 +275,10 @@ class Connection < Protocol::Class @name = "connection" @method_id = 10 - - class Start < Protocol::Method @name = "connection.start" @method_id = 10 @index = 0x000A000A # 10, 10, 655370 @packed_indexes = [10, 10].pack(PACK_UINT16_X2).freeze @@ -319,41 +314,37 @@ end def self.has_content? false end - - end class StartOk < Protocol::Method @name = "connection.start-ok" @method_id = 11 @index = 0x000A000B # 10, 11, 655371 @packed_indexes = [10, 11].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'client_properties = nil', u"mechanism = u'PLAIN'", u'response = nil', u"locale = u'en_US'"] + # ["client_properties = nil", "mechanism = "PLAIN"", "response = nil", "locale = "en_US""] def self.encode(client_properties, mechanism, response, locale) channel = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << AMQ::Protocol::Table.encode(client_properties) - buffer << mechanism.bytesize.chr - buffer << mechanism - buffer << [response.bytesize].pack(PACK_UINT32) - buffer << response - buffer << locale.bytesize.chr - buffer << locale + buffer << mechanism.to_s.bytesize.chr + buffer << mechanism.to_s + buffer << [response.to_s.bytesize].pack(PACK_UINT32) + buffer << response.to_s + buffer << locale.to_s.bytesize.chr + buffer << locale.to_s MethodFrame.new(buffer, channel) end - end class Secure < Protocol::Method @name = "connection.secure" @method_id = 20 @@ -376,36 +367,32 @@ end def self.has_content? false end - - end class SecureOk < Protocol::Method @name = "connection.secure-ok" @method_id = 21 @index = 0x000A0015 # 10, 21, 655381 @packed_indexes = [10, 21].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'response = nil'] + # ["response = nil"] def self.encode(response) channel = 0 - buffer = '' + buffer = "" buffer << @packed_indexes - buffer << [response.bytesize].pack(PACK_UINT32) - buffer << response + buffer << [response.to_s.bytesize].pack(PACK_UINT32) + buffer << response.to_s MethodFrame.new(buffer, channel) end - end class Tune < Protocol::Method @name = "connection.tune" @method_id = 30 @@ -432,68 +419,62 @@ end def self.has_content? false end - - end class TuneOk < Protocol::Method @name = "connection.tune-ok" @method_id = 31 @index = 0x000A001F # 10, 31, 655391 @packed_indexes = [10, 31].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'channel_max = false', u'frame_max = false', u'heartbeat = false'] + # ["channel_max = false", "frame_max = false", "heartbeat = false"] def self.encode(channel_max, frame_max, heartbeat) channel = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [channel_max].pack(PACK_UINT16) buffer << [frame_max].pack(PACK_UINT32) buffer << [heartbeat].pack(PACK_UINT16) MethodFrame.new(buffer, channel) end - end class Open < Protocol::Method @name = "connection.open" @method_id = 40 @index = 0x000A0028 # 10, 40, 655400 @packed_indexes = [10, 40].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u"virtual_host = u'/'", u'capabilities = EMPTY_STRING', u'insist = false'] + # ["virtual_host = "/"", "capabilities = EMPTY_STRING", "insist = false"] def self.encode(virtual_host) capabilities = EMPTY_STRING insist = false channel = 0 - buffer = '' + buffer = "" buffer << @packed_indexes - buffer << virtual_host.bytesize.chr - buffer << virtual_host - buffer << capabilities.bytesize.chr - buffer << capabilities + buffer << virtual_host.to_s.bytesize.chr + buffer << virtual_host.to_s + buffer << capabilities.to_s.bytesize.chr + buffer << capabilities.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if insist buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class OpenOk < Protocol::Method @name = "connection.open-ok" @method_id = 41 @@ -516,12 +497,10 @@ end def self.has_content? false end - - end class Close < Protocol::Method @name = "connection.close" @method_id = 50 @@ -555,23 +534,22 @@ def self.has_content? false end # @return - # [u'reply_code = nil', u'reply_text = EMPTY_STRING', u'class_id = nil', u'method_id = nil'] + # ["reply_code = nil", "reply_text = EMPTY_STRING", "class_id = nil", "method_id = nil"] def self.encode(reply_code, reply_text, class_id, method_id) channel = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [reply_code].pack(PACK_UINT16) - buffer << reply_text.bytesize.chr - buffer << reply_text + buffer << reply_text.to_s.bytesize.chr + buffer << reply_text.to_s buffer << [class_id].pack(PACK_UINT16) buffer << [method_id].pack(PACK_UINT16) MethodFrame.new(buffer, channel) end - end class CloseOk < Protocol::Method @name = "connection.close-ok" @method_id = 51 @@ -593,46 +571,40 @@ # @return # [] def self.encode() channel = 0 - buffer = '' + buffer = "" buffer << @packed_indexes MethodFrame.new(buffer, channel) end - end - end class Channel < Protocol::Class @name = "channel" @method_id = 20 - - class Open < Protocol::Method @name = "channel.open" @method_id = 10 @index = 0x0014000A # 20, 10, 1310730 @packed_indexes = [20, 10].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'out_of_band = EMPTY_STRING'] + # ["out_of_band = EMPTY_STRING"] def self.encode(channel, out_of_band) - buffer = '' + buffer = "" buffer << @packed_indexes - buffer << out_of_band.bytesize.chr - buffer << out_of_band + buffer << out_of_band.to_s.bytesize.chr + buffer << out_of_band.to_s MethodFrame.new(buffer, channel) end - end class OpenOk < Protocol::Method @name = "channel.open-ok" @method_id = 11 @@ -655,12 +627,10 @@ end def self.has_content? false end - - end class Flow < Protocol::Method @name = "channel.flow" @method_id = 20 @@ -684,20 +654,19 @@ def self.has_content? false end # @return - # [u'active = nil'] + # ["active = nil"] def self.encode(channel, active) - buffer = '' + buffer = "" buffer << @packed_indexes bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if active buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class FlowOk < Protocol::Method @name = "channel.flow-ok" @method_id = 21 @@ -721,20 +690,19 @@ def self.has_content? false end # @return - # [u'active = nil'] + # ["active = nil"] def self.encode(channel, active) - buffer = '' + buffer = "" buffer << @packed_indexes bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if active buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class Close < Protocol::Method @name = "channel.close" @method_id = 40 @@ -768,22 +736,21 @@ def self.has_content? false end # @return - # [u'reply_code = nil', u'reply_text = EMPTY_STRING', u'class_id = nil', u'method_id = nil'] + # ["reply_code = nil", "reply_text = EMPTY_STRING", "class_id = nil", "method_id = nil"] def self.encode(channel, reply_code, reply_text, class_id, method_id) - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [reply_code].pack(PACK_UINT16) - buffer << reply_text.bytesize.chr - buffer << reply_text + buffer << reply_text.to_s.bytesize.chr + buffer << reply_text.to_s buffer << [class_id].pack(PACK_UINT16) buffer << [method_id].pack(PACK_UINT16) MethodFrame.new(buffer, channel) end - end class CloseOk < Protocol::Method @name = "channel.close-ok" @method_id = 41 @@ -804,58 +771,52 @@ end # @return # [] def self.encode(channel) - buffer = '' + buffer = "" buffer << @packed_indexes MethodFrame.new(buffer, channel) end - end - end class Exchange < Protocol::Class @name = "exchange" @method_id = 40 - - class Declare < Protocol::Method @name = "exchange.declare" @method_id = 10 @index = 0x0028000A # 40, 10, 2621450 @packed_indexes = [40, 10].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'exchange = nil', u"type = u'direct'", u'passive = false', u'durable = false', u'auto_delete = false', u'internal = false', u'nowait = false', u'arguments = {}'] + # ["ticket = 0", "exchange = nil", "type = "direct"", "passive = false", "durable = false", "auto_delete = false", "internal = false", "nowait = false", "arguments = {}"] def self.encode(channel, exchange, type, passive, durable, auto_delete, internal, nowait, arguments) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << exchange.bytesize.chr - buffer << exchange - buffer << type.bytesize.chr - buffer << type + buffer << exchange.to_s.bytesize.chr + buffer << exchange.to_s + buffer << type.to_s.bytesize.chr + buffer << type.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if passive bit_buffer = bit_buffer | (1 << 1) if durable bit_buffer = bit_buffer | (1 << 2) if auto_delete bit_buffer = bit_buffer | (1 << 3) if internal bit_buffer = bit_buffer | (1 << 4) if nowait buffer << [bit_buffer].pack(PACK_CHAR) buffer << AMQ::Protocol::Table.encode(arguments) MethodFrame.new(buffer, channel) end - end class DeclareOk < Protocol::Method @name = "exchange.declare-ok" @method_id = 11 @@ -872,41 +833,37 @@ end def self.has_content? false end - - end class Delete < Protocol::Method @name = "exchange.delete" @method_id = 20 @index = 0x00280014 # 40, 20, 2621460 @packed_indexes = [40, 20].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'exchange = nil', u'if_unused = false', u'nowait = false'] + # ["ticket = 0", "exchange = nil", "if_unused = false", "nowait = false"] def self.encode(channel, exchange, if_unused, nowait) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << exchange.bytesize.chr - buffer << exchange + buffer << exchange.to_s.bytesize.chr + buffer << exchange.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if if_unused bit_buffer = bit_buffer | (1 << 1) if nowait buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class DeleteOk < Protocol::Method @name = "exchange.delete-ok" @method_id = 21 @@ -923,45 +880,41 @@ end def self.has_content? false end - - end class Bind < Protocol::Method @name = "exchange.bind" @method_id = 30 @index = 0x0028001E # 40, 30, 2621470 @packed_indexes = [40, 30].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'destination = nil', u'source = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}'] + # ["ticket = 0", "destination = nil", "source = nil", "routing_key = EMPTY_STRING", "nowait = false", "arguments = {}"] def self.encode(channel, destination, source, routing_key, nowait, arguments) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << destination.bytesize.chr - buffer << destination - buffer << source.bytesize.chr - buffer << source - buffer << routing_key.bytesize.chr - buffer << routing_key + buffer << destination.to_s.bytesize.chr + buffer << destination.to_s + buffer << source.to_s.bytesize.chr + buffer << source.to_s + buffer << routing_key.to_s.bytesize.chr + buffer << routing_key.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if nowait buffer << [bit_buffer].pack(PACK_CHAR) buffer << AMQ::Protocol::Table.encode(arguments) MethodFrame.new(buffer, channel) end - end class BindOk < Protocol::Method @name = "exchange.bind-ok" @method_id = 31 @@ -978,45 +931,41 @@ end def self.has_content? false end - - end class Unbind < Protocol::Method @name = "exchange.unbind" @method_id = 40 @index = 0x00280028 # 40, 40, 2621480 @packed_indexes = [40, 40].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'destination = nil', u'source = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}'] + # ["ticket = 0", "destination = nil", "source = nil", "routing_key = EMPTY_STRING", "nowait = false", "arguments = {}"] def self.encode(channel, destination, source, routing_key, nowait, arguments) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << destination.bytesize.chr - buffer << destination - buffer << source.bytesize.chr - buffer << source - buffer << routing_key.bytesize.chr - buffer << routing_key + buffer << destination.to_s.bytesize.chr + buffer << destination.to_s + buffer << source.to_s.bytesize.chr + buffer << source.to_s + buffer << routing_key.to_s.bytesize.chr + buffer << routing_key.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if nowait buffer << [bit_buffer].pack(PACK_CHAR) buffer << AMQ::Protocol::Table.encode(arguments) MethodFrame.new(buffer, channel) end - end class UnbindOk < Protocol::Method @name = "exchange.unbind-ok" @method_id = 51 @@ -1033,53 +982,46 @@ end def self.has_content? false end - - end - end class Queue < Protocol::Class @name = "queue" @method_id = 50 - - class Declare < Protocol::Method @name = "queue.declare" @method_id = 10 @index = 0x0032000A # 50, 10, 3276810 @packed_indexes = [50, 10].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'queue = EMPTY_STRING', u'passive = false', u'durable = false', u'exclusive = false', u'auto_delete = false', u'nowait = false', u'arguments = {}'] + # ["ticket = 0", "queue = EMPTY_STRING", "passive = false", "durable = false", "exclusive = false", "auto_delete = false", "nowait = false", "arguments = {}"] def self.encode(channel, queue, passive, durable, exclusive, auto_delete, nowait, arguments) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << queue.bytesize.chr - buffer << queue + buffer << queue.to_s.bytesize.chr + buffer << queue.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if passive bit_buffer = bit_buffer | (1 << 1) if durable bit_buffer = bit_buffer | (1 << 2) if exclusive bit_buffer = bit_buffer | (1 << 3) if auto_delete bit_buffer = bit_buffer | (1 << 4) if nowait buffer << [bit_buffer].pack(PACK_CHAR) buffer << AMQ::Protocol::Table.encode(arguments) MethodFrame.new(buffer, channel) end - end class DeclareOk < Protocol::Method @name = "queue.declare-ok" @method_id = 11 @@ -1108,45 +1050,41 @@ end def self.has_content? false end - - end class Bind < Protocol::Method @name = "queue.bind" @method_id = 20 @index = 0x00320014 # 50, 20, 3276820 @packed_indexes = [50, 20].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'queue = EMPTY_STRING', u'exchange = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}'] + # ["ticket = 0", "queue = EMPTY_STRING", "exchange = nil", "routing_key = EMPTY_STRING", "nowait = false", "arguments = {}"] def self.encode(channel, queue, exchange, routing_key, nowait, arguments) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << queue.bytesize.chr - buffer << queue - buffer << exchange.bytesize.chr - buffer << exchange - buffer << routing_key.bytesize.chr - buffer << routing_key + buffer << queue.to_s.bytesize.chr + buffer << queue.to_s + buffer << exchange.to_s.bytesize.chr + buffer << exchange.to_s + buffer << routing_key.to_s.bytesize.chr + buffer << routing_key.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if nowait buffer << [bit_buffer].pack(PACK_CHAR) buffer << AMQ::Protocol::Table.encode(arguments) MethodFrame.new(buffer, channel) end - end class BindOk < Protocol::Method @name = "queue.bind-ok" @method_id = 21 @@ -1163,40 +1101,36 @@ end def self.has_content? false end - - end class Purge < Protocol::Method @name = "queue.purge" @method_id = 30 @index = 0x0032001E # 50, 30, 3276830 @packed_indexes = [50, 30].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'queue = EMPTY_STRING', u'nowait = false'] + # ["ticket = 0", "queue = EMPTY_STRING", "nowait = false"] def self.encode(channel, queue, nowait) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << queue.bytesize.chr - buffer << queue + buffer << queue.to_s.bytesize.chr + buffer << queue.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if nowait buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class PurgeOk < Protocol::Method @name = "queue.purge-ok" @method_id = 31 @@ -1217,42 +1151,38 @@ end def self.has_content? false end - - end class Delete < Protocol::Method @name = "queue.delete" @method_id = 40 @index = 0x00320028 # 50, 40, 3276840 @packed_indexes = [50, 40].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'queue = EMPTY_STRING', u'if_unused = false', u'if_empty = false', u'nowait = false'] + # ["ticket = 0", "queue = EMPTY_STRING", "if_unused = false", "if_empty = false", "nowait = false"] def self.encode(channel, queue, if_unused, if_empty, nowait) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << queue.bytesize.chr - buffer << queue + buffer << queue.to_s.bytesize.chr + buffer << queue.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if if_unused bit_buffer = bit_buffer | (1 << 1) if if_empty bit_buffer = bit_buffer | (1 << 2) if nowait buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class DeleteOk < Protocol::Method @name = "queue.delete-ok" @method_id = 41 @@ -1273,42 +1203,38 @@ end def self.has_content? false end - - end class Unbind < Protocol::Method @name = "queue.unbind" @method_id = 50 @index = 0x00320032 # 50, 50, 3276850 @packed_indexes = [50, 50].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'queue = EMPTY_STRING', u'exchange = nil', u'routing_key = EMPTY_STRING', u'arguments = {}'] + # ["ticket = 0", "queue = EMPTY_STRING", "exchange = nil", "routing_key = EMPTY_STRING", "arguments = {}"] def self.encode(channel, queue, exchange, routing_key, arguments) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << queue.bytesize.chr - buffer << queue - buffer << exchange.bytesize.chr - buffer << exchange - buffer << routing_key.bytesize.chr - buffer << routing_key + buffer << queue.to_s.bytesize.chr + buffer << queue.to_s + buffer << exchange.to_s.bytesize.chr + buffer << exchange.to_s + buffer << routing_key.to_s.bytesize.chr + buffer << routing_key.to_s buffer << AMQ::Protocol::Table.encode(arguments) MethodFrame.new(buffer, channel) end - end class UnbindOk < Protocol::Method @name = "queue.unbind-ok" @method_id = 51 @@ -1325,14 +1251,11 @@ end def self.has_content? false end - - end - end class Basic < Protocol::Class @name = "basic" @method_id = 60 @@ -1354,128 +1277,126 @@ :cluster_id, # shortstr ] # 1 << 15 def self.encode_content_type(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [0, 0x8000, buffer] end # 1 << 14 def self.encode_content_encoding(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [1, 0x4000, buffer] end # 1 << 13 def self.encode_headers(value) - buffer = '' + buffer = "" buffer << AMQ::Protocol::Table.encode(value) [2, 0x2000, buffer] end # 1 << 12 def self.encode_delivery_mode(value) - buffer = '' + buffer = "" buffer << [value].pack(PACK_CHAR) [3, 0x1000, buffer] end # 1 << 11 def self.encode_priority(value) - buffer = '' + buffer = "" buffer << [value].pack(PACK_CHAR) [4, 0x0800, buffer] end # 1 << 10 def self.encode_correlation_id(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [5, 0x0400, buffer] end # 1 << 9 def self.encode_reply_to(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [6, 0x0200, buffer] end # 1 << 8 def self.encode_expiration(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [7, 0x0100, buffer] end # 1 << 7 def self.encode_message_id(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [8, 0x0080, buffer] end # 1 << 6 def self.encode_timestamp(value) - buffer = '' + buffer = "" buffer << AMQ::Hacks.pack_64_big_endian(value) [9, 0x0040, buffer] end # 1 << 5 def self.encode_type(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [10, 0x0020, buffer] end # 1 << 4 def self.encode_user_id(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [11, 0x0010, buffer] end # 1 << 3 def self.encode_app_id(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [12, 0x0008, buffer] end # 1 << 2 def self.encode_cluster_id(value) - buffer = '' - buffer << value.bytesize.chr - buffer << value + buffer = "" + buffer << value.to_s.bytesize.chr + buffer << value.to_s [13, 0x0004, buffer] end - - def self.encode_properties(body_size, properties) pieces, flags = [], 0 properties.reject {|key, value| value.nil?}.each do |key, value| i, f, result = self.__send__(:"encode_#{key}", value) flags |= f pieces[i] = result end - # result = [60, 0, body_size, flags].pack('n2Qn') + # result = [60, 0, body_size, flags].pack("n2Qn") result = [60, 0].pack(PACK_UINT16_X2) result += AMQ::Hacks.pack_64_big_endian(body_size) result += [flags].pack(PACK_UINT16) result + pieces.join(EMPTY_STRING) end @@ -1513,11 +1434,11 @@ 0x0010 => :shortstr, 0x0008 => :shortstr, 0x0004 => :shortstr, } - # Hash doesn't give any guarantees on keys order, we will do it in a + # Hash doesn"t give any guarantees on keys order, we will do it in a # straightforward way DECODE_PROPERTIES_KEYS = [ 0x8000, 0x4000, 0x2000, @@ -1571,28 +1492,26 @@ @name = "basic.qos" @method_id = 10 @index = 0x003C000A # 60, 10, 3932170 @packed_indexes = [60, 10].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'prefetch_size = false', u'prefetch_count = false', u'global = false'] + # ["prefetch_size = false", "prefetch_count = false", "global = false"] def self.encode(channel, prefetch_size, prefetch_count, global) - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [prefetch_size].pack(PACK_UINT32) buffer << [prefetch_count].pack(PACK_UINT16) bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if global buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class QosOk < Protocol::Method @name = "basic.qos-ok" @method_id = 11 @@ -1609,46 +1528,42 @@ end def self.has_content? false end - - end class Consume < Protocol::Method @name = "basic.consume" @method_id = 20 @index = 0x003C0014 # 60, 20, 3932180 @packed_indexes = [60, 20].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'queue = EMPTY_STRING', u'consumer_tag = EMPTY_STRING', u'no_local = false', u'no_ack = false', u'exclusive = false', u'nowait = false', u'arguments = {}'] + # ["ticket = 0", "queue = EMPTY_STRING", "consumer_tag = EMPTY_STRING", "no_local = false", "no_ack = false", "exclusive = false", "nowait = false", "arguments = {}"] def self.encode(channel, queue, consumer_tag, no_local, no_ack, exclusive, nowait, arguments) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << queue.bytesize.chr - buffer << queue - buffer << consumer_tag.bytesize.chr - buffer << consumer_tag + buffer << queue.to_s.bytesize.chr + buffer << queue.to_s + buffer << consumer_tag.to_s.bytesize.chr + buffer << consumer_tag.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if no_local bit_buffer = bit_buffer | (1 << 1) if no_ack bit_buffer = bit_buffer | (1 << 2) if exclusive bit_buffer = bit_buffer | (1 << 3) if nowait buffer << [bit_buffer].pack(PACK_CHAR) buffer << AMQ::Protocol::Table.encode(arguments) MethodFrame.new(buffer, channel) end - end class ConsumeOk < Protocol::Method @name = "basic.consume-ok" @method_id = 21 @@ -1671,12 +1586,10 @@ end def self.has_content? false end - - end class Cancel < Protocol::Method @name = "basic.cancel" @method_id = 30 @@ -1705,22 +1618,21 @@ def self.has_content? false end # @return - # [u'consumer_tag = nil', u'nowait = false'] + # ["consumer_tag = nil", "nowait = false"] def self.encode(channel, consumer_tag, nowait) - buffer = '' + buffer = "" buffer << @packed_indexes - buffer << consumer_tag.bytesize.chr - buffer << consumer_tag + buffer << consumer_tag.to_s.bytesize.chr + buffer << consumer_tag.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if nowait buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class CancelOk < Protocol::Method @name = "basic.cancel-ok" @method_id = 31 @@ -1743,36 +1655,33 @@ end def self.has_content? false end - - end class Publish < Protocol::Method @name = "basic.publish" @method_id = 40 @index = 0x003C0028 # 60, 40, 3932200 @packed_indexes = [60, 40].pack(PACK_UINT16_X2).freeze - def self.has_content? true end # @return - # [u'ticket = 0', u'exchange = EMPTY_STRING', u'routing_key = EMPTY_STRING', u'mandatory = false', u'immediate = false', 'user_headers = nil', 'payload = ""', 'frame_size = nil'] + # ["ticket = 0", "exchange = EMPTY_STRING", "routing_key = EMPTY_STRING", "mandatory = false", "immediate = false", "user_headers = nil", "payload = """, "frame_size = nil"] def self.encode(channel, payload, user_headers, exchange, routing_key, mandatory, immediate, frame_size) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << exchange.bytesize.chr - buffer << exchange - buffer << routing_key.bytesize.chr - buffer << routing_key + buffer << exchange.to_s.bytesize.chr + buffer << exchange.to_s + buffer << routing_key.to_s.bytesize.chr + buffer << routing_key.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if mandatory bit_buffer = bit_buffer | (1 << 1) if immediate buffer << [bit_buffer].pack(PACK_CHAR) frames = [MethodFrame.new(buffer, channel)] @@ -1783,11 +1692,10 @@ end properties_payload = Basic.encode_properties(payload.bytesize, properties) frames << HeaderFrame.new(properties_payload, channel) frames + self.encode_body(payload, channel, frame_size) end - end class Return < Protocol::Method @name = "basic.return" @method_id = 50 @@ -1823,12 +1731,10 @@ end def self.has_content? true end - - end class Deliver < Protocol::Method @name = "basic.deliver" @method_id = 60 @@ -1868,40 +1774,36 @@ end def self.has_content? true end - - end class Get < Protocol::Method @name = "basic.get" @method_id = 70 @index = 0x003C0046 # 60, 70, 3932230 @packed_indexes = [60, 70].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'ticket = 0', u'queue = EMPTY_STRING', u'no_ack = false'] + # ["ticket = 0", "queue = EMPTY_STRING", "no_ack = false"] def self.encode(channel, queue, no_ack) ticket = 0 - buffer = '' + buffer = "" buffer << @packed_indexes buffer << [ticket].pack(PACK_UINT16) - buffer << queue.bytesize.chr - buffer << queue + buffer << queue.to_s.bytesize.chr + buffer << queue.to_s bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if no_ack buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class GetOk < Protocol::Method @name = "basic.get-ok" @method_id = 71 @@ -1939,12 +1841,10 @@ end def self.has_content? true end - - end class GetEmpty < Protocol::Method @name = "basic.get-empty" @method_id = 72 @@ -1967,12 +1867,10 @@ end def self.has_content? false end - - end class Ack < Protocol::Method @name = "basic.ack" @method_id = 80 @@ -1999,94 +1897,87 @@ def self.has_content? false end # @return - # [u'delivery_tag = false', u'multiple = false'] + # ["delivery_tag = false", "multiple = false"] def self.encode(channel, delivery_tag, multiple) - buffer = '' + buffer = "" buffer << @packed_indexes buffer << AMQ::Hacks.pack_64_big_endian(delivery_tag) bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if multiple buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class Reject < Protocol::Method @name = "basic.reject" @method_id = 90 @index = 0x003C005A # 60, 90, 3932250 @packed_indexes = [60, 90].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'delivery_tag = nil', u'requeue = true'] + # ["delivery_tag = nil", "requeue = true"] def self.encode(channel, delivery_tag, requeue) - buffer = '' + buffer = "" buffer << @packed_indexes buffer << AMQ::Hacks.pack_64_big_endian(delivery_tag) bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if requeue buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class RecoverAsync < Protocol::Method @name = "basic.recover-async" @method_id = 100 @index = 0x003C0064 # 60, 100, 3932260 @packed_indexes = [60, 100].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'requeue = false'] + # ["requeue = false"] def self.encode(channel, requeue) - buffer = '' + buffer = "" buffer << @packed_indexes bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if requeue buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class Recover < Protocol::Method @name = "basic.recover" @method_id = 110 @index = 0x003C006E # 60, 110, 3932270 @packed_indexes = [60, 110].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return - # [u'requeue = false'] + # ["requeue = false"] def self.encode(channel, requeue) - buffer = '' + buffer = "" buffer << @packed_indexes bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if requeue buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class RecoverOk < Protocol::Method @name = "basic.recover-ok" @method_id = 111 @@ -2103,12 +1994,10 @@ end def self.has_content? false end - - end class Nack < Protocol::Method @name = "basic.nack" @method_id = 120 @@ -2137,51 +2026,45 @@ def self.has_content? false end # @return - # [u'delivery_tag = false', u'multiple = false', u'requeue = true'] + # ["delivery_tag = false", "multiple = false", "requeue = true"] def self.encode(channel, delivery_tag, multiple, requeue) - buffer = '' + buffer = "" buffer << @packed_indexes buffer << AMQ::Hacks.pack_64_big_endian(delivery_tag) bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if multiple bit_buffer = bit_buffer | (1 << 1) if requeue buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end - end class Tx < Protocol::Class @name = "tx" @method_id = 90 - - class Select < Protocol::Method @name = "tx.select" @method_id = 10 @index = 0x005A000A # 90, 10, 5898250 @packed_indexes = [90, 10].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return # [] def self.encode(channel) - buffer = '' + buffer = "" buffer << @packed_indexes MethodFrame.new(buffer, channel) end - end class SelectOk < Protocol::Method @name = "tx.select-ok" @method_id = 11 @@ -2198,33 +2081,29 @@ end def self.has_content? false end - - end class Commit < Protocol::Method @name = "tx.commit" @method_id = 20 @index = 0x005A0014 # 90, 20, 5898260 @packed_indexes = [90, 20].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return # [] def self.encode(channel) - buffer = '' + buffer = "" buffer << @packed_indexes MethodFrame.new(buffer, channel) end - end class CommitOk < Protocol::Method @name = "tx.commit-ok" @method_id = 21 @@ -2241,33 +2120,29 @@ end def self.has_content? false end - - end class Rollback < Protocol::Method @name = "tx.rollback" @method_id = 30 @index = 0x005A001E # 90, 30, 5898270 @packed_indexes = [90, 30].pack(PACK_UINT16_X2).freeze - def self.has_content? false end # @return # [] def self.encode(channel) - buffer = '' + buffer = "" buffer << @packed_indexes MethodFrame.new(buffer, channel) end - end class RollbackOk < Protocol::Method @name = "tx.rollback-ok" @method_id = 31 @@ -2284,22 +2159,17 @@ end def self.has_content? false end - - end - end class Confirm < Protocol::Class @name = "confirm" @method_id = 85 - - class Select < Protocol::Method @name = "confirm.select" @method_id = 10 @index = 0x0055000A # 85, 10, 5570570 @packed_indexes = [85, 10].pack(PACK_UINT16_X2).freeze @@ -2321,20 +2191,19 @@ def self.has_content? false end # @return - # [u'nowait = false'] + # ["nowait = false"] def self.encode(channel, nowait) - buffer = '' + buffer = "" buffer << @packed_indexes bit_buffer = 0 bit_buffer = bit_buffer | (1 << 0) if nowait buffer << [bit_buffer].pack(PACK_CHAR) MethodFrame.new(buffer, channel) end - end class SelectOk < Protocol::Method @name = "confirm.select-ok" @method_id = 11 @@ -2355,23 +2224,19 @@ end # @return # [] def self.encode(channel) - buffer = '' + buffer = "" buffer << @packed_indexes MethodFrame.new(buffer, channel) end - end - end - METHODS = begin Method.methods.inject(Hash.new) do |hash, klass| hash.merge!(klass.index => klass) end end end end -