Permalink
Browse files

Merge pull request #42 from OtherLevels/issue_40_resubmission

[Issue #40 resubmission] 'b' frame decoding changed from int8 to char (uint8)
  • Loading branch information...
2 parents 81d2d74 + f9016ff commit 79b372870970cd3a4e891c459d15da73e8f0d1fe @michaelklishin michaelklishin committed Dec 20, 2013
@@ -81,8 +81,8 @@ def self.decode(data)
when TYPE_BOOLEAN
v, offset = TableValueDecoder.decode_boolean(data, offset)
v
- when TYPE_SIGNED_8BIT then
- v, offset = TableValueDecoder.decode_short_short(data, offset)
+ when TYPE_BYTE then
+ v, offset = TableValueDecoder.decode_byte(data, offset)
v
when TYPE_SIGNED_16BIT then
v, offset = TableValueDecoder.decode_short(data, offset)
@@ -50,8 +50,8 @@ def self.decode_array(data, initial_offset)
when TYPE_BOOLEAN
v, offset = decode_boolean(data, offset)
v
- when TYPE_SIGNED_8BIT then
- v, offset = decode_short_short(data, offset)
+ when TYPE_BYTE then
+ v, offset = decode_byte(data, offset)
v
when TYPE_SIGNED_16BIT then
v, offset = decode_short(data, offset)
@@ -174,12 +174,16 @@ def self.decode_hash(data, offset)
end # self.decode_hash(data, offset)
- def self.decode_short_short(data, offset)
- v = data.slice(offset, 1).unpack(PACK_INT8).first
- offset += 1
- [v, offset]
+ # Decodes/Converts a byte value from the data at the provided offset.
+ #
+ # @param [Array] data - A big-endian ordered array of bytes.
+ # @param [Fixnum] offset - The offset which bytes the byte is consumed.
+ # @return [Array] - The Fixnum value and new offset pair.
+ def self.decode_byte(data, offset)
+ [data.slice(offset, 1).unpack(PACK_CHAR).first, offset += 1]
end
+
def self.decode_short(data, offset)
v = AMQ::Hacks.unpack_int16_big_endian(data.slice(offset, 2)).first
offset += 2
@@ -9,7 +9,7 @@ module TypeConstants
TYPE_DECIMAL = 'D'.freeze
TYPE_HASH = 'F'.freeze
TYPE_ARRAY = 'A'.freeze
- TYPE_SIGNED_8BIT = 'b'.freeze
+ TYPE_BYTE = 'b'.freeze
TYPE_64BIT_FLOAT = 'd'.freeze
TYPE_32BIT_FLOAT = 'f'.freeze
TYPE_SIGNED_64BIT = 'l'.freeze
@@ -1,5 +1,5 @@
module AMQ
module Protocol
- VERSION = "1.10.0.pre1"
+ VERSION = "1.9.2.pre"
end # Protocol
end # AMQ
@@ -176,8 +176,8 @@ module Protocol
end
it 'is capable of decoding 8bit signed integers' do
- output = TableValueDecoder.decode_short_short("\xC0",0).first
- output.should == -64
+ output = TableValueDecoder.decode_byte("\xC0",0).first
+ output.should == 192
end
it 'is capable of decoding 16bit signed integers' do
@@ -67,6 +67,23 @@ module Protocol
value, offset = described_class.decode_32bit_float(data, 1)
value.should == 10.0
end
+
+ context "8bit/byte decoding" do
+ let(:examples) {
+ {
+ 0x00 => "\x00",
+ 0x01 => "\x01",
+ 0x10 => "\x10",
+ 255 => "\xFF" # not -1
+ }
+ }
+
+ it "is capable of decoding byte values" do
+ examples.each do |key, value|
+ described_class.decode_byte(value, 0).first.should == key
+ end
+ end
+ end
end
end
end

0 comments on commit 79b3728

Please sign in to comment.