amq-protocol 0.7.0.alpha6 → 0.7.0.alpha7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.travis.yml +1 -0
- data/CONTRIBUTORS +4 -2
- data/Gemfile +19 -5
- data/README.textile +6 -0
- data/codegen.py +1 -1
- data/irb.rb +25 -8
- data/lib/amq/protocol/client.rb +16 -16
- data/lib/amq/protocol/table.rb +0 -1
- data/lib/amq/protocol/version.rb +1 -1
- data/protocol.rb.pytemplate +25 -18
- data/tasks.rb +23 -6
- metadata +43 -23
- data/benchmark.rb +0 -24
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CONTRIBUTORS
CHANGED
data/Gemfile
CHANGED
@@ -1,16 +1,30 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
# Use local clones if possible.
|
4
|
+
# If you want to use your local copy, just symlink it to vendor.
|
5
|
+
extend Module.new {
|
6
|
+
def gem(name, options = Hash.new)
|
7
|
+
local_path = File.expand_path("../vendor/#{name}", __FILE__)
|
8
|
+
if File.exist?(local_path)
|
9
|
+
super name, options.merge(:path => local_path).delete_if { |key, _| [:git, :branch].include?(key) }
|
10
|
+
else
|
11
|
+
super name, options
|
12
|
+
end
|
13
|
+
end
|
14
|
+
}
|
15
|
+
|
16
|
+
source :rubygems
|
4
17
|
|
5
18
|
group(:development) do
|
6
|
-
gem "nake", :platform => :
|
7
|
-
gem "contributors", :platform => :
|
19
|
+
gem "nake", :platform => :mri_19
|
20
|
+
gem "contributors", :platform => :mri_19
|
21
|
+
gem "amq-client"
|
8
22
|
|
9
23
|
# excludes Windows, Rubinius and JRuby
|
10
|
-
gem "perftools.rb", :platform => :
|
24
|
+
gem "perftools.rb", :platform => :mri_18
|
11
25
|
end
|
12
26
|
|
13
27
|
group(:test) do
|
14
28
|
gem "rspec", ">=2.0.0"
|
15
|
-
gem
|
29
|
+
gem "simplecov", :platform => :mri_19
|
16
30
|
end
|
data/README.textile
CHANGED
@@ -20,6 +20,12 @@ gem 'amq-protocol', :git => 'https://github.com/ruby-amqp/amq-protocol.git'
|
|
20
20
|
|
21
21
|
h2. Development
|
22
22
|
|
23
|
+
h3. Inspection
|
24
|
+
|
25
|
+
If you need to see what AMQP methods are encoded, just regenerate the protocol file using @./tasks.rb generate --development@ and then set @$DEBUG@ to @true@ for which parts of code you want to see the debug statements.
|
26
|
+
|
27
|
+
!http://static.101ideas.cz/amqp-debug.png!
|
28
|
+
|
23
29
|
h3. Nightly Builds
|
24
30
|
|
25
31
|
You can always find nightly builds at "gems.101ideas.cz":http://gems.101ideas.cz.
|
data/codegen.py
CHANGED
@@ -152,4 +152,4 @@ def generateMain(type):
|
|
152
152
|
return main
|
153
153
|
|
154
154
|
if __name__ == "__main__":
|
155
|
-
do_main_dict({"client": generateMain("client"), "server": generateMain("server")})
|
155
|
+
do_main_dict({"client": generateMain("client"), "server": generateMain("server"), "all": generateMain("all")})
|
data/irb.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env bundle exec ruby
|
2
2
|
# encoding: binary
|
3
3
|
|
4
4
|
# This file is supposed to make inspecting AMQ protocol easier.
|
@@ -41,16 +41,24 @@ else
|
|
41
41
|
puts "~ Loading original #{irbrc} ..."
|
42
42
|
load irbrc
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
# TODO: Don't generate constants in all.rb multiple
|
45
|
+
# times, then we can remove this craziness with $VERBOSE.
|
46
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
47
|
+
begin
|
48
|
+
require_relative "lib/amq/protocol/all.rb"
|
49
|
+
rescue LoadError
|
50
|
+
abort "File lib/amq/protocol/all.rb doesn't exist! You have to generate it using ./tasks.rb generate --targets=all, executed from the root of AMQ Protocol repository."
|
51
|
+
end
|
52
|
+
$VERBOSE = old_verbose
|
53
|
+
|
46
54
|
include AMQ::Protocol
|
47
55
|
|
48
56
|
begin
|
49
|
-
require "amq/client/
|
57
|
+
require "amq/client/framing/string/frame"
|
50
58
|
|
51
59
|
class AMQ::Protocol::Frame
|
52
60
|
def self.decode(string)
|
53
|
-
AMQ::Client::
|
61
|
+
AMQ::Client::Framing::String::Frame.decode(string)
|
54
62
|
end
|
55
63
|
end
|
56
64
|
rescue LoadError
|
@@ -70,11 +78,20 @@ else
|
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
73
|
-
require "stringio"
|
74
|
-
|
75
81
|
def fd(data)
|
76
|
-
Frame.decode(
|
82
|
+
Frame.decode(data)
|
77
83
|
end
|
84
|
+
|
85
|
+
puts <<-EOF
|
86
|
+
|
87
|
+
This is an AMQP #{AMQ::Protocol::PROTOCOL_VERSION} console. You can:
|
88
|
+
|
89
|
+
- Decode data via: fd(frame_data).
|
90
|
+
- Encode data using AMQP classes directly:
|
91
|
+
frame = Connection::Open.encode("/")
|
92
|
+
frame.encode
|
93
|
+
|
94
|
+
EOF
|
78
95
|
rescue Exception => exception # it just discards all the exceptions!
|
79
96
|
abort exception.message + "\n - " + exception.backtrace.join("\n - ")
|
80
97
|
end
|
data/lib/amq/protocol/client.rb
CHANGED
@@ -26,9 +26,8 @@ module AMQ
|
|
26
26
|
PACK_UCHAR_UINT32 = "CN".freeze
|
27
27
|
PACK_CHAR_UINT16_UINT32 = "cnN".freeze
|
28
28
|
|
29
|
-
PACK_32BIT_FLOAT =
|
30
|
-
PACK_64BIT_FLOAT =
|
31
|
-
|
29
|
+
PACK_32BIT_FLOAT = "f".freeze
|
30
|
+
PACK_64BIT_FLOAT = "d".freeze
|
32
31
|
|
33
32
|
# @return [Array] Collection of subclasses of AMQ::Protocol::Class.
|
34
33
|
def self.classes
|
@@ -52,7 +51,7 @@ module AMQ
|
|
52
51
|
@_subclasses.select{ |k| defined?(k::VALUE) }
|
53
52
|
end # self.subclasses_with_values
|
54
53
|
|
55
|
-
def self.[](code)
|
54
|
+
def self.[](code)
|
56
55
|
if result = subclasses_with_values.detect { |klass| klass::VALUE == code }
|
57
56
|
result
|
58
57
|
else
|
@@ -245,19 +244,20 @@ module AMQ
|
|
245
244
|
end
|
246
245
|
|
247
246
|
def self.encode_body(body, channel, frame_size)
|
248
|
-
|
249
|
-
|
250
|
-
#
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
Array.new
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
end
|
247
|
+
return [BodyFrame.new(body, channel)] if body.empty?
|
248
|
+
|
249
|
+
# See https://dev.rabbitmq.com/wiki/Amqp091Errata#section_11
|
250
|
+
limit = frame_size - 8
|
251
|
+
limit_plus_1 = limit + 1
|
252
|
+
|
253
|
+
array = Array.new
|
254
|
+
while body
|
255
|
+
payload, body = body[0, limit_plus_1], body[limit_plus_1, body.length - limit]
|
256
|
+
# array << [0x03, payload]
|
257
|
+
array << BodyFrame.new(payload, channel)
|
260
258
|
end
|
259
|
+
|
260
|
+
array
|
261
261
|
end
|
262
262
|
|
263
263
|
# We can return different:
|
data/lib/amq/protocol/table.rb
CHANGED
@@ -109,7 +109,6 @@ module AMQ
|
|
109
109
|
offset += 5
|
110
110
|
value = BigDecimal.new(raw.to_s) * (BigDecimal.new(TEN) ** -decimals)
|
111
111
|
when TYPE_TIME
|
112
|
-
# TODO: what is the first unpacked value??? Zone, maybe? It's 0, so it'd make sense.
|
113
112
|
timestamp = data.slice(offset, 8).unpack(PACK_UINT32_X2).last
|
114
113
|
value = Time.at(timestamp)
|
115
114
|
offset += 8
|
data/lib/amq/protocol/version.rb
CHANGED
data/protocol.rb.pytemplate
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
# THIS IS AN AUTOGENERATED FILE, DO NOT MODIFY
|
5
5
|
# IT DIRECTLY ! FOR CHANGES, PLEASE UPDATE CODEGEN.PY
|
6
|
-
# IN THE ROOT DIRECTORY OF THE AMQ-PROTOCOL REPOSITORY.<% import codegen_helpers as helpers %><% import re, codegen %>
|
6
|
+
# IN THE ROOT DIRECTORY OF THE AMQ-PROTOCOL REPOSITORY.<% import codegen_helpers as helpers %><% import re, os, codegen %>
|
7
7
|
|
8
8
|
require "amq/protocol/table"
|
9
9
|
require "amq/protocol/frame"
|
@@ -27,13 +27,16 @@ module AMQ
|
|
27
27
|
PACK_UCHAR_UINT32 = 'CN'.freeze
|
28
28
|
PACK_CHAR_UINT16_UINT32 = 'cnN'.freeze
|
29
29
|
|
30
|
-
|
30
|
+
PACK_32BIT_FLOAT = 'f'.freeze
|
31
|
+
PACK_64BIT_FLOAT = 'd'.freeze
|
32
|
+
|
33
|
+
|
34
|
+
|
31
35
|
# @return [Array] Collection of subclasses of AMQ::Protocol::Class.
|
32
36
|
def self.classes
|
33
37
|
Protocol::Class.classes
|
34
38
|
end
|
35
39
|
|
36
|
-
# @version 0.0.1
|
37
40
|
# @return [Array] Collection of subclasses of AMQ::Protocol::Method.
|
38
41
|
def self.methods
|
39
42
|
Protocol::Method.methods
|
@@ -51,7 +54,7 @@ module AMQ
|
|
51
54
|
@_subclasses.select{ |k| defined?(k::VALUE) }
|
52
55
|
end # self.subclasses_with_values
|
53
56
|
|
54
|
-
def self.[](code)
|
57
|
+
def self.[](code)
|
55
58
|
if result = subclasses_with_values.detect { |klass| klass::VALUE == code }
|
56
59
|
result
|
57
60
|
else
|
@@ -181,19 +184,20 @@ module AMQ
|
|
181
184
|
end
|
182
185
|
|
183
186
|
def self.encode_body(body, channel, frame_size)
|
184
|
-
|
185
|
-
|
186
|
-
#
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
Array.new
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
end
|
187
|
+
return [BodyFrame.new(body, channel)] if body.empty?
|
188
|
+
|
189
|
+
# See https://dev.rabbitmq.com/wiki/Amqp091Errata#section_11
|
190
|
+
limit = frame_size - 8
|
191
|
+
limit_plus_1 = limit + 1
|
192
|
+
|
193
|
+
array = Array.new
|
194
|
+
while body
|
195
|
+
payload, body = body[0, limit_plus_1], body[limit_plus_1, body.length - limit]
|
196
|
+
# array << [0x03, payload]
|
197
|
+
array << BodyFrame.new(payload, channel)
|
196
198
|
end
|
199
|
+
|
200
|
+
array
|
197
201
|
end
|
198
202
|
|
199
203
|
# We can return different:
|
@@ -316,7 +320,7 @@ module AMQ
|
|
316
320
|
@index = ${method.binary()}
|
317
321
|
@packed_indexes = [${klass.index}, ${method.index}].pack(PACK_UINT16_X2).freeze
|
318
322
|
|
319
|
-
% if (spec.type == "client" and method.accepted_by("client")) or (spec.type == "server" and method.accepted_by("server")):
|
323
|
+
% if (spec.type == "client" and method.accepted_by("client")) or (spec.type == "server" and method.accepted_by("server") or spec.type == "all"):
|
320
324
|
# @return
|
321
325
|
def self.decode(data)
|
322
326
|
offset = 0
|
@@ -348,7 +352,7 @@ module AMQ
|
|
348
352
|
% endif
|
349
353
|
end
|
350
354
|
|
351
|
-
% if (spec.type == "client" and method.accepted_by("server")) or (spec.type == "server" and method.accepted_by("client")):
|
355
|
+
% if (spec.type == "client" and method.accepted_by("server")) or (spec.type == "server" and method.accepted_by("client")) or spec.type == "all":
|
352
356
|
# @return
|
353
357
|
# ${method.params()}
|
354
358
|
% if klass.name == "connection":
|
@@ -382,6 +386,9 @@ module AMQ
|
|
382
386
|
frames + self.encode_body(payload, channel, frame_size)
|
383
387
|
% endif
|
384
388
|
% else:
|
389
|
+
% if os.getenv("DEVELOPMENT"):
|
390
|
+
STDERR.puts("~ [\e[31m#{channel}\e[m] \e[32m${klass.name}.${method.name}\e[m(${", ".join([method + "=#{" + method + ".inspect}" for method in method.not_ignored_args()])})") if $DEBUG
|
391
|
+
% endif
|
385
392
|
MethodFrame.new(buffer, channel)
|
386
393
|
% endif
|
387
394
|
end
|
data/tasks.rb
CHANGED
@@ -1,22 +1,39 @@
|
|
1
|
-
#!/usr/bin/env nake
|
1
|
+
#!/usr/bin/env bundle exec nake
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
|
4
|
+
load "contributors.nake"
|
5
5
|
|
6
|
+
# ./tasks.rb generate
|
7
|
+
# ./tasks.rb generate --targets=all,
|
8
|
+
# ./tasks.rb generate --targets=client,server
|
9
|
+
# ./tasks.rb generate --development
|
6
10
|
Task.new(:generate) do |task|
|
7
11
|
task.description = "Generate lib/amq/protocol/client.rb"
|
12
|
+
|
13
|
+
def self.valid_choices
|
14
|
+
["client", "server", "all"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.check_validity_of_target(target)
|
18
|
+
unless self.valid_choices.include?(target)
|
19
|
+
abort "Target can be one #{valid_choices.inspect}, not #{target.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
8
23
|
task.define do |opts, spec = nil|
|
24
|
+
opts[:targets] ||= ["client"]
|
25
|
+
|
9
26
|
if spec.nil?
|
10
27
|
spec = "vendor/rabbitmq-codegen/amqp-rabbitmq-0.9.1.json"
|
11
28
|
unless File.exist?(spec)
|
12
29
|
sh "git submodule update --init"
|
13
30
|
end
|
14
31
|
end
|
15
|
-
|
16
|
-
targets
|
17
|
-
|
32
|
+
|
33
|
+
opts[:targets].each do |type|
|
34
|
+
self.check_validity_of_target(type)
|
18
35
|
path = "lib/amq/protocol/#{type}.rb"
|
19
|
-
sh "./codegen.py #{type} #{spec} #{path}"
|
36
|
+
sh "DEVELOPMENT=#{opts[:development]} ./codegen.py #{type} #{spec} #{path}"
|
20
37
|
if File.file?(path)
|
21
38
|
sh "./post-processing.rb #{path}"
|
22
39
|
sh "ruby -c #{path}"
|
metadata
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: amq-protocol
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: -3702664414
|
5
5
|
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
- alpha
|
11
|
+
- 7
|
12
|
+
version: 0.7.0.alpha7
|
6
13
|
platform: ruby
|
7
|
-
authors:
|
14
|
+
authors:
|
8
15
|
- Jakub Stastny
|
9
16
|
- Michael S. Klishin
|
10
17
|
- Theo Hultberg
|
@@ -12,19 +19,21 @@ authors:
|
|
12
19
|
autorequire:
|
13
20
|
bindir: bin
|
14
21
|
cert_chain: []
|
15
|
-
|
22
|
+
|
23
|
+
date: 2011-06-16 00:00:00 Z
|
16
24
|
dependencies: []
|
17
|
-
|
18
|
-
is not an\n AMQP client: amq-protocol only handles serialization and deserialization.\n
|
19
|
-
|
20
|
-
email:
|
25
|
+
|
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"
|
27
|
+
email:
|
21
28
|
- michael@novemberain.com
|
22
29
|
- stastny@101ideas.cz
|
23
30
|
executables: []
|
31
|
+
|
24
32
|
extensions: []
|
25
|
-
|
33
|
+
|
34
|
+
extra_rdoc_files:
|
26
35
|
- README.textile
|
27
|
-
files:
|
36
|
+
files:
|
28
37
|
- .gitignore
|
29
38
|
- .gitmodules
|
30
39
|
- .rspec
|
@@ -38,7 +47,6 @@ files:
|
|
38
47
|
- __init__.py
|
39
48
|
- amq-protocol.gemspec
|
40
49
|
- amqp_0.9.1_changes.json
|
41
|
-
- benchmark.rb
|
42
50
|
- codegen.py
|
43
51
|
- codegen_helpers.py
|
44
52
|
- examples/00_manual_test.rb
|
@@ -67,26 +75,38 @@ files:
|
|
67
75
|
- tasks.rb
|
68
76
|
homepage: http://github.com/ruby-amqp/amq-protocol
|
69
77
|
licenses: []
|
78
|
+
|
70
79
|
post_install_message:
|
71
80
|
rdoc_options: []
|
72
|
-
|
81
|
+
|
82
|
+
require_paths:
|
73
83
|
- lib
|
74
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
85
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
80
|
-
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
94
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
95
|
+
requirements:
|
96
|
+
- - ">"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 25
|
99
|
+
segments:
|
100
|
+
- 1
|
101
|
+
- 3
|
102
|
+
- 1
|
85
103
|
version: 1.3.1
|
86
104
|
requirements: []
|
105
|
+
|
87
106
|
rubyforge_project: amq-protocol
|
88
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.5
|
89
108
|
signing_key:
|
90
109
|
specification_version: 3
|
91
110
|
summary: AMQP 0.9.1 encoder & decoder.
|
92
111
|
test_files: []
|
112
|
+
|
data/benchmark.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: binary
|
3
|
-
|
4
|
-
begin
|
5
|
-
require "amq/spec"
|
6
|
-
rescue LoadError
|
7
|
-
abort "You have to install the amqp gem in order to run the benchmark against its AMQP encoder/decoder."
|
8
|
-
end
|
9
|
-
|
10
|
-
require "benchmark"
|
11
|
-
|
12
|
-
Benchmark.bmbm do |bm|
|
13
|
-
bm.report("Raw binary") do
|
14
|
-
# TODO
|
15
|
-
end
|
16
|
-
|
17
|
-
bm.report("AMQP Gem") do
|
18
|
-
# TODO
|
19
|
-
end
|
20
|
-
|
21
|
-
bm.report("AMQ Protocol Gem") do
|
22
|
-
# TODO
|
23
|
-
end
|
24
|
-
end
|