amq-protocol 1.0.0.pre5 → 1.0.0.pre6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -8,3 +8,5 @@ tmp
8
8
  Gemfile.lock
9
9
  .rbx/*
10
10
  .Apple*
11
+ .bundle/*
12
+ bin/*
@@ -13,7 +13,6 @@ module AMQ
13
13
  PROTOCOL_VERSION = "0.9.1".freeze
14
14
  PREAMBLE = "AMQP\x00\x00\x09\x01".freeze
15
15
  DEFAULT_PORT = 5672
16
- TLS_PORT = 5671
17
16
 
18
17
  # caching
19
18
  EMPTY_STRING = "".freeze
@@ -1468,8 +1467,8 @@ module AMQ
1468
1467
  def self.encode_properties(body_size, properties)
1469
1468
  pieces, flags = [], 0
1470
1469
 
1471
- properties.each do |key, value|
1472
- i, f, result = self.send(:"encode_#{key}", value)
1470
+ properties.reject {|key, value| value.nil?}.each do |key, value|
1471
+ i, f, result = self.__send__(:"encode_#{key}", value)
1473
1472
  flags |= f
1474
1473
  pieces[i] = result
1475
1474
  end
@@ -84,9 +84,13 @@ module AMQ
84
84
  when TYPE_BOOLEAN
85
85
  v, offset = TableValueDecoder.decode_boolean(data, offset)
86
86
  v
87
- when TYPE_SIGNED_8BIT then raise NotImplementedError.new
88
- when TYPE_SIGNED_16BIT then raise NotImplementedError.new
89
- when TYPE_SIGNED_64BIT then raise NotImplementedError.new
87
+ when TYPE_SIGNED_8BIT then
88
+ raise NotImplementedError.new
89
+ when TYPE_SIGNED_16BIT then
90
+ raise NotImplementedError.new
91
+ when TYPE_SIGNED_64BIT then
92
+ v, offset = TableValueDecoder.decode_long(data, offset)
93
+ v
90
94
  when TYPE_32BIT_FLOAT then
91
95
  v, offset = TableValueDecoder.decode_32bit_float(data, offset)
92
96
  v
@@ -20,6 +20,10 @@ module AMQ
20
20
  # API
21
21
  #
22
22
 
23
+ BIG_ENDIAN = ([1].pack("s") == "\x00\x01")
24
+ Q = "Q".freeze
25
+
26
+
23
27
  def self.decode_array(data, initial_offset)
24
28
  array_length = data.slice(initial_offset, 4).unpack(PACK_UINT32).first
25
29
 
@@ -30,41 +34,47 @@ module AMQ
30
34
  type, offset = decode_value_type(data, offset)
31
35
 
32
36
  i = case type
33
- when TYPE_STRING
34
- v, offset = decode_string(data, offset)
35
- v
36
- when TYPE_INTEGER
37
- v, offset = decode_integer(data, offset)
38
- v
39
- when TYPE_DECIMAL
40
- v, offset = decode_big_decimal(data, offset)
41
- v
42
- when TYPE_TIME
43
- v, offset = decode_time(data, offset)
44
- v
45
- when TYPE_HASH
46
- v, offset = decode_hash(data, offset)
47
- v
48
- when TYPE_BOOLEAN
49
- v, offset = decode_boolean(data, offset)
50
- v
51
- when TYPE_SIGNED_8BIT then raise NotImplementedError.new
52
- when TYPE_SIGNED_16BIT then raise NotImplementedError.new
53
- when TYPE_SIGNED_64BIT then raise NotImplementedError.new
54
- when TYPE_32BIT_FLOAT then
55
- v, offset = decode_32bit_float(data, offset)
56
- v
57
- when TYPE_64BIT_FLOAT then
58
- v, offset = decode_64bit_float(data, offset)
59
- v
60
- when TYPE_VOID
61
- nil
62
- when TYPE_ARRAY
63
- v, offset = TableValueDecoder.decode_array(data, offset)
64
- v
65
- else
66
- raise ArgumentError.new("unsupported type: #{type.inspect}")
67
- end
37
+ when TYPE_STRING
38
+ v, offset = decode_string(data, offset)
39
+ v
40
+ when TYPE_INTEGER
41
+ v, offset = decode_integer(data, offset)
42
+ v
43
+ when TYPE_DECIMAL
44
+ v, offset = decode_big_decimal(data, offset)
45
+ v
46
+ when TYPE_TIME
47
+ v, offset = decode_time(data, offset)
48
+ v
49
+ when TYPE_HASH
50
+ v, offset = decode_hash(data, offset)
51
+ v
52
+ when TYPE_BOOLEAN
53
+ v, offset = decode_boolean(data, offset)
54
+ v
55
+ when TYPE_SIGNED_8BIT then
56
+ # TODO
57
+ raise NotImplementedError.new
58
+ when TYPE_SIGNED_16BIT then
59
+ # TODO
60
+ raise NotImplementedError.new
61
+ when TYPE_SIGNED_64BIT then
62
+ v, offset = decode_long(data, offset)
63
+ v
64
+ when TYPE_32BIT_FLOAT then
65
+ v, offset = decode_32bit_float(data, offset)
66
+ v
67
+ when TYPE_64BIT_FLOAT then
68
+ v, offset = decode_64bit_float(data, offset)
69
+ v
70
+ when TYPE_VOID
71
+ nil
72
+ when TYPE_ARRAY
73
+ v, offset = TableValueDecoder.decode_array(data, offset)
74
+ v
75
+ else
76
+ raise ArgumentError.new("unsupported type in a table value: #{type.inspect}, do not know how to decode!")
77
+ end
68
78
 
69
79
  ary << i
70
80
  end
@@ -92,6 +102,24 @@ module AMQ
92
102
  end # self.decode_integer(data, offset)
93
103
 
94
104
 
105
+ if BIG_ENDIAN
106
+ def self.decode_long(data, offset)
107
+ v = data.slice(offset, 8).unpack(Q)
108
+
109
+ offset += 8
110
+ [v, offset]
111
+ end
112
+ else
113
+ def self.decode_long(data, offset)
114
+ slice = data.slice(offset, 8).bytes.to_a.reverse.map(&:chr).join
115
+ v = slice.unpack(Q).first
116
+
117
+ offset += 8
118
+ [v, offset]
119
+ end
120
+ end
121
+
122
+
95
123
  def self.decode_big_decimal(data, offset)
96
124
  decimals, raw = data.slice(offset, 5).unpack(PACK_UCHAR_UINT32)
97
125
  offset += 5
@@ -1,5 +1,5 @@
1
1
  module AMQ
2
2
  module Protocol
3
- VERSION = "1.0.0.pre5"
3
+ VERSION = "1.0.0.pre6"
4
4
  end # Protocol
5
5
  end # AMQ
@@ -244,8 +244,8 @@ module AMQ
244
244
  def self.encode_properties(body_size, properties)
245
245
  pieces, flags = [], 0
246
246
 
247
- properties.each do |key, value|
248
- i, f, result = self.send(:"encode_#{key}", value)
247
+ properties.reject {|key, value| value.nil?}.each do |key, value|
248
+ i, f, result = self.__send__(:"encode_#{key}", value)
249
249
  flags |= f
250
250
  pieces[i] = result
251
251
  end
@@ -94,6 +94,15 @@ module AMQ
94
94
  end
95
95
 
96
96
 
97
+ it "is capable of decoding nil table values" do
98
+ input = { "nilval" => nil }
99
+ Table.decode(Table.encode(input)).should == input
100
+ end
101
+
102
+ it "is capable of decoding nil table in nested hash/map values" do
103
+ input = { "hash" => {"nil" => nil} }
104
+ Table.decode(Table.encode(input)).should == input
105
+ end
97
106
 
98
107
  it "is capable of decoding string table values" do
99
108
  input = { "stringvalue" => "string" }
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amq-protocol
3
3
  version: !ruby/object:Gem::Version
4
- hash: -4085083884
4
+ hash: -3271493030
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
10
  - pre
11
- - 5
12
- version: 1.0.0.pre5
11
+ - 6
12
+ version: 1.0.0.pre6
13
13
  platform: ruby
14
14
  authors:
15
15
  - Jakub Stastny
@@ -20,7 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2012-06-26 00:00:00 Z
23
+ date: 2012-07-02 00:00:00 Z
24
24
  dependencies: []
25
25
 
26
26
  description: " amq-protocol is an AMQP 0.9.1 serialization library for Ruby. It is not an\n AMQP client: amq-protocol only handles serialization and deserialization.\n If you want to write your own AMQP client, this gem can help you with that.\n"
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements: []
112
112
 
113
113
  rubyforge_project: amq-protocol
114
- rubygems_version: 1.8.15
114
+ rubygems_version: 1.8.24
115
115
  signing_key:
116
116
  specification_version: 3
117
117
  summary: AMQP 0.9.1 encoder & decoder.