lib/amq/protocol/client.rb in amq-protocol-0.7.0.alpha6 vs lib/amq/protocol/client.rb in amq-protocol-0.7.0.alpha7
- old
+ new
@@ -24,14 +24,13 @@
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
@@ -50,11 +49,11 @@
def self.subclasses_with_values
@_subclasses.select{ |k| defined?(k::VALUE) }
end # self.subclasses_with_values
- def self.[](code) # TODO: rewrite more effectively
+ def self.[](code)
if result = subclasses_with_values.detect { |klass| klass::VALUE == code }
result
else
raise "No such exception class for code #{code}" unless result
end # if
@@ -243,22 +242,23 @@
return [properties, headers]
end
def self.encode_body(body, channel, frame_size)
- # Spec is broken: Our errata says that it does define
- # something, but it just doesn"t relate do method and
- # properties frames. Which makes it, well, suboptimal.
- # https://dev.rabbitmq.com/wiki/Amqp091Errata#section_11
- limit = frame_size - 7 - 1
+ return [BodyFrame.new(body, channel)] if body.empty?
- Array.new.tap do |array|
- while body
- payload, body = body[0, limit + 1], body[limit + 1, body.length - limit]
- # array << [0x03, payload]
- array << BodyFrame.new(payload, channel)
- end
+ # See https://dev.rabbitmq.com/wiki/Amqp091Errata#section_11
+ limit = frame_size - 8
+ limit_plus_1 = limit + 1
+
+ array = Array.new
+ while body
+ payload, body = body[0, limit_plus_1], body[limit_plus_1, body.length - limit]
+ # array << [0x03, payload]
+ array << BodyFrame.new(payload, channel)
end
+
+ array
end
# We can return different:
# - instantiate given subclass of Method
# - create an OpenStruct object