Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed single bite conversion from signed to unsigned for 'b' frames #41

Merged
merged 1 commit into from
Dec 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/amq/protocol/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions lib/amq/protocol/table_value_decoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -173,11 +173,13 @@ def self.decode_hash(data, offset)
[v, 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)
Expand Down
2 changes: 1 addition & 1 deletion lib/amq/protocol/type_constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion spec/amq/protocol/value_decoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,27 @@ module Protocol
input = Float32Bit.new(10.0)
data = TableValueEncoder.encode(input)

value, offset = described_class.decode_32bit_float(data, 1)
value, offset = described_class.decode_decode_byte(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