Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

1 participant

@ghost

A fix regarding issue #40

@michaelklishin michaelklishin merged commit a988b44 into ruby-amqp:1.9.x-stable
@michaelklishin

OK, I had to revert this. Please make sure all tests pass and CI does not fail.

@ghost

Sorry about that Michael, I've now made sure that all the tests pass. (changed the decode_short_short test to decode_byte)

@michaelklishin

I still get a failure:

1.9.x-stable* be rspec spec/
zsh: correct 'rspec' to 'spec' [nyae]? n
Running on 2.0.0
..............................................................................................................................................................................................................F............................................................................................................................................................................................................

Failures:

  1) AMQ::Protocol::Table.decode is capable of decoding 8bit unsigned integers
     Failure/Error: output = TableValueDecoder.decode_byte("\xC0",0).first
     NoMethodError:
       undefined method `decode_byte' for AMQ::Protocol::TableValueDecoder:Class
     # ./spec/amq/protocol/table_spec.rb:179:in `block (3 levels) in <module:Protocol>'

Finished in 0.13812 seconds
411 examples, 1 failure
@ghost

Ah, I think maybe it's isolated 215253a as a cherry pick (as it never updated the changes to fix this bug in this pull request). It looks like github ignores changes on a branch after its been merged (even if it is rejected thereafter?). Should I drop this pull request and see it if picks up all the changes on a new pull request?

@michaelklishin

Yes, just push another branch and submit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 19, 2013
This page is out of date. Refresh to see the latest.
View
4 lib/amq/protocol/table.rb
@@ -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)
View
16 lib/amq/protocol/table_value_decoder.rb
@@ -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)
@@ -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)
View
2  lib/amq/protocol/type_constants.rb
@@ -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
View
20 spec/amq/protocol/value_decoder_spec.rb
@@ -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
Something went wrong with that request. Please try again.