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 +2 -0
- data/lib/amq/protocol/client.rb +2 -3
- data/lib/amq/protocol/table.rb +7 -3
- data/lib/amq/protocol/table_value_decoder.rb +63 -35
- data/lib/amq/protocol/version.rb +1 -1
- data/protocol.rb.pytemplate +2 -2
- data/spec/amq/protocol/table_spec.rb +9 -0
- metadata +5 -5
data/.gitignore
CHANGED
data/lib/amq/protocol/client.rb
CHANGED
@@ -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.
|
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
|
data/lib/amq/protocol/table.rb
CHANGED
@@ -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
|
88
|
-
|
89
|
-
when
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
data/lib/amq/protocol/version.rb
CHANGED
data/protocol.rb.pytemplate
CHANGED
@@ -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.
|
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: -
|
4
|
+
hash: -3271493030
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- pre
|
11
|
-
-
|
12
|
-
version: 1.0.0.
|
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-
|
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.
|
114
|
+
rubygems_version: 1.8.24
|
115
115
|
signing_key:
|
116
116
|
specification_version: 3
|
117
117
|
summary: AMQP 0.9.1 encoder & decoder.
|