amq-protocol 2.3.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AGENTS.md +23 -0
- data/CLAUDE.md +1 -0
- data/ChangeLog.md +30 -3
- data/GEMINI.md +1 -0
- data/Gemfile +5 -0
- data/README.md +2 -7
- data/benchmarks/frame_encoding.rb +75 -0
- data/benchmarks/method_encoding.rb +198 -0
- data/benchmarks/pack_unpack.rb +158 -0
- data/benchmarks/run_all.rb +64 -0
- data/benchmarks/table_encoding.rb +110 -0
- data/lib/amq/bit_set.rb +1 -0
- data/lib/amq/endianness.rb +2 -0
- data/lib/amq/int_allocator.rb +1 -0
- data/lib/amq/pack.rb +33 -42
- data/lib/amq/protocol/client.rb +30 -37
- data/lib/amq/protocol/constants.rb +2 -0
- data/lib/amq/protocol/exceptions.rb +3 -1
- data/lib/amq/protocol/float_32bit.rb +2 -0
- data/lib/amq/protocol/frame.rb +9 -3
- data/lib/amq/protocol/table.rb +20 -17
- data/lib/amq/protocol/table_value_decoder.rb +48 -52
- data/lib/amq/protocol/table_value_encoder.rb +1 -0
- data/lib/amq/protocol/type_constants.rb +1 -0
- data/lib/amq/protocol/version.rb +1 -1
- data/lib/amq/settings.rb +1 -0
- data/spec/amq/bit_set_spec.rb +22 -0
- data/spec/amq/endianness_spec.rb +23 -0
- data/spec/amq/int_allocator_spec.rb +26 -3
- data/spec/amq/pack_spec.rb +14 -24
- data/spec/amq/protocol/exceptions_spec.rb +70 -0
- data/spec/amq/protocol/float_32bit_spec.rb +27 -0
- data/spec/amq/protocol/frame_spec.rb +64 -0
- data/spec/amq/protocol/table_spec.rb +32 -0
- data/spec/amq/protocol/value_decoder_spec.rb +97 -0
- data/spec/amq/protocol/value_encoder_spec.rb +21 -0
- data/spec/amq/settings_spec.rb +37 -1
- data/spec/amq/uri_parsing_spec.rb +7 -0
- metadata +14 -3
|
@@ -81,6 +81,103 @@ module AMQ
|
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
|
+
|
|
85
|
+
describe ".decode_string" do
|
|
86
|
+
it "decodes string values" do
|
|
87
|
+
# 4 bytes length + string content
|
|
88
|
+
data = "\x00\x00\x00\x05hello"
|
|
89
|
+
value, offset = described_class.decode_string(data, 0)
|
|
90
|
+
expect(value).to eq("hello")
|
|
91
|
+
expect(offset).to eq(9)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe ".decode_integer" do
|
|
96
|
+
it "decodes 32-bit unsigned integers" do
|
|
97
|
+
data = "\x00\x00\x00\x0A"
|
|
98
|
+
value, offset = described_class.decode_integer(data, 0)
|
|
99
|
+
expect(value).to eq(10)
|
|
100
|
+
expect(offset).to eq(4)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe ".decode_long" do
|
|
105
|
+
it "decodes 64-bit signed integers" do
|
|
106
|
+
data = "\x00\x00\x00\x00\x00\x00\x00\x0A"
|
|
107
|
+
value, offset = described_class.decode_long(data, 0)
|
|
108
|
+
expect(value).to eq(10)
|
|
109
|
+
expect(offset).to eq(8)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe ".decode_time" do
|
|
114
|
+
it "decodes timestamp values" do
|
|
115
|
+
timestamp = Time.now.to_i
|
|
116
|
+
data = [timestamp].pack('Q>')
|
|
117
|
+
value, offset = described_class.decode_time(data, 0)
|
|
118
|
+
expect(value.to_i).to eq(timestamp)
|
|
119
|
+
expect(offset).to eq(8)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe ".decode_boolean" do
|
|
124
|
+
it "decodes true" do
|
|
125
|
+
value, offset = described_class.decode_boolean("\x01", 0)
|
|
126
|
+
expect(value).to eq(true)
|
|
127
|
+
expect(offset).to eq(1)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "decodes false" do
|
|
131
|
+
value, offset = described_class.decode_boolean("\x00", 0)
|
|
132
|
+
expect(value).to eq(false)
|
|
133
|
+
expect(offset).to eq(1)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
describe ".decode_64bit_float" do
|
|
138
|
+
it "decodes 64-bit floats" do
|
|
139
|
+
data = [3.14159].pack('G')
|
|
140
|
+
value, offset = described_class.decode_64bit_float(data, 0)
|
|
141
|
+
expect(value).to be_within(0.00001).of(3.14159)
|
|
142
|
+
expect(offset).to eq(8)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe ".decode_value_type" do
|
|
147
|
+
it "returns the type byte and incremented offset" do
|
|
148
|
+
data = "Shello"
|
|
149
|
+
type, offset = described_class.decode_value_type(data, 0)
|
|
150
|
+
expect(type).to eq("S")
|
|
151
|
+
expect(offset).to eq(1)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
describe ".decode_short" do
|
|
156
|
+
it "decodes 16-bit signed integers" do
|
|
157
|
+
data = "\x06\x8D"
|
|
158
|
+
value, offset = described_class.decode_short(data, 0)
|
|
159
|
+
expect(value).to eq(1677)
|
|
160
|
+
expect(offset).to eq(2)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
describe ".decode_big_decimal" do
|
|
165
|
+
it "decodes BigDecimal values" do
|
|
166
|
+
# Scale 2, raw value 100 = 1.00
|
|
167
|
+
data = "\x02\x00\x00\x00\x64"
|
|
168
|
+
value, offset = described_class.decode_big_decimal(data, 0)
|
|
169
|
+
expect(value).to be_a(BigDecimal)
|
|
170
|
+
expect(offset).to eq(5)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
describe ".decode_hash" do
|
|
175
|
+
it "decodes nested hash values" do
|
|
176
|
+
encoded = AMQ::Protocol::Table.encode({"nested" => "value"})
|
|
177
|
+
value, _offset = described_class.decode_hash(encoded, 0)
|
|
178
|
+
expect(value).to eq({"nested" => "value"})
|
|
179
|
+
end
|
|
180
|
+
end
|
|
84
181
|
end
|
|
85
182
|
end
|
|
86
183
|
end
|
|
@@ -134,6 +134,27 @@ module AMQ
|
|
|
134
134
|
expect(described_class.encode(input4).bytesize).to eq(69)
|
|
135
135
|
end
|
|
136
136
|
|
|
137
|
+
it "encodes symbols as strings" do
|
|
138
|
+
encoded = described_class.encode(:test_symbol)
|
|
139
|
+
expect(encoded).to start_with("S")
|
|
140
|
+
expect(encoded).to include("test_symbol")
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "encodes BigDecimal values" do
|
|
144
|
+
bd = BigDecimal("123.45")
|
|
145
|
+
encoded = described_class.encode(bd)
|
|
146
|
+
expect(encoded).to start_with("D")
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "encodes BigDecimal with zero exponent" do
|
|
150
|
+
bd = BigDecimal("100")
|
|
151
|
+
encoded = described_class.encode(bd)
|
|
152
|
+
expect(encoded).to start_with("D")
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "raises ArgumentError for unsupported types" do
|
|
156
|
+
expect { described_class.encode(Object.new) }.to raise_error(ArgumentError)
|
|
157
|
+
end
|
|
137
158
|
|
|
138
159
|
end # TableValueEncoder
|
|
139
160
|
end # Protocol
|
data/spec/amq/settings_spec.rb
CHANGED
|
@@ -6,9 +6,18 @@ RSpec.describe AMQ::Settings do
|
|
|
6
6
|
expect(AMQ::Settings.default).to_not be_nil
|
|
7
7
|
expect(AMQ::Settings.default[:host]).to_not be_nil
|
|
8
8
|
end
|
|
9
|
+
|
|
10
|
+
it "includes default port" do
|
|
11
|
+
expect(AMQ::Settings.default[:port]).to eq(5672)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "includes default credentials" do
|
|
15
|
+
expect(AMQ::Settings.default[:user]).to eq("guest")
|
|
16
|
+
expect(AMQ::Settings.default[:pass]).to eq("guest")
|
|
17
|
+
end
|
|
9
18
|
end
|
|
10
19
|
|
|
11
|
-
describe ".configure
|
|
20
|
+
describe ".configure" do
|
|
12
21
|
it "should merge custom settings with default settings" do
|
|
13
22
|
settings = AMQ::Settings.configure(:host => "tagadab")
|
|
14
23
|
expect(settings[:host]).to eql("tagadab")
|
|
@@ -18,5 +27,32 @@ RSpec.describe AMQ::Settings do
|
|
|
18
27
|
settings = AMQ::Settings.configure("amqp://tagadab")
|
|
19
28
|
expect(settings[:host]).to eql("tagadab")
|
|
20
29
|
end
|
|
30
|
+
|
|
31
|
+
it "returns default when passed nil" do
|
|
32
|
+
settings = AMQ::Settings.configure(nil)
|
|
33
|
+
expect(settings).to eq(AMQ::Settings.default)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "normalizes username to user" do
|
|
37
|
+
settings = AMQ::Settings.configure(:username => "admin")
|
|
38
|
+
expect(settings[:user]).to eq("admin")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "normalizes password to pass" do
|
|
42
|
+
settings = AMQ::Settings.configure(:password => "secret")
|
|
43
|
+
expect(settings[:pass]).to eq("secret")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "prefers user over username when both provided" do
|
|
47
|
+
settings = AMQ::Settings.configure(:user => "admin", :username => "other")
|
|
48
|
+
expect(settings[:user]).to eq("admin")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe ".parse_amqp_url" do
|
|
53
|
+
it "delegates to AMQ::URI.parse" do
|
|
54
|
+
result = AMQ::Settings.parse_amqp_url("amqp://localhost")
|
|
55
|
+
expect(result[:host]).to eq("localhost")
|
|
56
|
+
end
|
|
21
57
|
end
|
|
22
58
|
end
|
|
@@ -277,4 +277,11 @@ RSpec.describe AMQ::URI do
|
|
|
277
277
|
end
|
|
278
278
|
end
|
|
279
279
|
end
|
|
280
|
+
|
|
281
|
+
describe ".parse_amqp_url" do
|
|
282
|
+
it "is an alias for .parse" do
|
|
283
|
+
result = described_class.parse_amqp_url("amqp://localhost")
|
|
284
|
+
expect(result[:host]).to eq("localhost")
|
|
285
|
+
end
|
|
286
|
+
end
|
|
280
287
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: amq-protocol
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jakub Stastny
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
- Mark Abramov
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description: |2
|
|
16
16
|
amq-protocol is an AMQP 0.9.1 serialization library for Ruby. It is not a
|
|
@@ -28,15 +28,23 @@ files:
|
|
|
28
28
|
- ".gitmodules"
|
|
29
29
|
- ".rspec"
|
|
30
30
|
- ".travis.yml"
|
|
31
|
+
- AGENTS.md
|
|
32
|
+
- CLAUDE.md
|
|
31
33
|
- ChangeLog.md
|
|
34
|
+
- GEMINI.md
|
|
32
35
|
- Gemfile
|
|
33
36
|
- LICENSE
|
|
34
37
|
- README.md
|
|
35
38
|
- Rakefile
|
|
36
39
|
- amq-protocol.gemspec
|
|
40
|
+
- benchmarks/frame_encoding.rb
|
|
37
41
|
- benchmarks/int_allocator.rb
|
|
42
|
+
- benchmarks/method_encoding.rb
|
|
43
|
+
- benchmarks/pack_unpack.rb
|
|
38
44
|
- benchmarks/pure/body_framing_with_256k_payload.rb
|
|
39
45
|
- benchmarks/pure/body_framing_with_2k_payload.rb
|
|
46
|
+
- benchmarks/run_all.rb
|
|
47
|
+
- benchmarks/table_encoding.rb
|
|
40
48
|
- codegen/__init__.py
|
|
41
49
|
- codegen/amqp_0.9.1_changes.json
|
|
42
50
|
- codegen/codegen.py
|
|
@@ -63,6 +71,7 @@ files:
|
|
|
63
71
|
- profiling/README.md
|
|
64
72
|
- profiling/stackprof/body_framing_with_2k_payload.rb
|
|
65
73
|
- spec/amq/bit_set_spec.rb
|
|
74
|
+
- spec/amq/endianness_spec.rb
|
|
66
75
|
- spec/amq/int_allocator_spec.rb
|
|
67
76
|
- spec/amq/pack_spec.rb
|
|
68
77
|
- spec/amq/protocol/basic_spec.rb
|
|
@@ -71,7 +80,9 @@ files:
|
|
|
71
80
|
- spec/amq/protocol/confirm_spec.rb
|
|
72
81
|
- spec/amq/protocol/connection_spec.rb
|
|
73
82
|
- spec/amq/protocol/constants_spec.rb
|
|
83
|
+
- spec/amq/protocol/exceptions_spec.rb
|
|
74
84
|
- spec/amq/protocol/exchange_spec.rb
|
|
85
|
+
- spec/amq/protocol/float_32bit_spec.rb
|
|
75
86
|
- spec/amq/protocol/frame_spec.rb
|
|
76
87
|
- spec/amq/protocol/method_spec.rb
|
|
77
88
|
- spec/amq/protocol/queue_spec.rb
|
|
@@ -101,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
101
112
|
- !ruby/object:Gem::Version
|
|
102
113
|
version: '0'
|
|
103
114
|
requirements: []
|
|
104
|
-
rubygems_version: 3.6.
|
|
115
|
+
rubygems_version: 3.6.9
|
|
105
116
|
specification_version: 4
|
|
106
117
|
summary: AMQP 0.9.1 encoding & decoding library.
|
|
107
118
|
test_files: []
|