lib/amq/protocol/table_value_decoder.rb in amq-protocol-1.2.0 vs lib/amq/protocol/table_value_decoder.rb in amq-protocol-1.3.0

- old
+ new

@@ -1,7 +1,8 @@ # encoding: binary +require "amq/endianness" require "amq/protocol/client" require "amq/protocol/type_constants" require "amq/protocol/table" module AMQ @@ -18,14 +19,10 @@ # # API # - BIG_ENDIAN = ([1].pack("s") == "\x00\x01") - Q = "q".freeze - - def self.decode_array(data, initial_offset) array_length = data.slice(initial_offset, 4).unpack(PACK_UINT32).first ary = Array.new offset = initial_offset + 4 @@ -100,21 +97,21 @@ [v, offset] end # self.decode_integer(data, offset) - if BIG_ENDIAN + if AMQ::Endianness.big_endian? def self.decode_long(data, offset) - v = data.slice(offset, 8).unpack(Q) + v = data.slice(offset, 8).unpack(PACK_INT64) offset += 8 [v, offset] end else def self.decode_long(data, offset) slice = data.slice(offset, 8).bytes.to_a.reverse.map(&:chr).join - v = slice.unpack(Q).first + v = slice.unpack(PACK_INT64).first offset += 8 [v, offset] end end @@ -175,16 +172,16 @@ [v, offset] end # self.decode_hash(data, offset) def self.decode_short_short(data, offset) - v = data.slice(offset, 1).unpack(PACK_SIGNED_8BIT).first + v = data.slice(offset, 1).unpack(PACK_INT8).first offset += 1 [v, offset] end def self.decode_short(data, offset) - v = data.slice(offset, 2).unpack(PACK_SIGNED_16BIT).first + v = AMQ::Hacks.unpack_int16_big_endian(data.slice(offset, 2)).first offset += 2 [v, offset] end end # TableValueDecoder end # Protocol