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 CHANGED
@@ -3,5 +3,6 @@
3
3
  tmp
4
4
  *.pyc
5
5
  /vendor/bundle
6
+ /vendor/amq-*
6
7
  /coverage
7
- Gemfile.lock
8
+ Gemfile.lock
@@ -1,6 +1,7 @@
1
1
  script: "bundle exec rspec spec"
2
2
  rvm:
3
3
  - 1.8.7
4
+ - 1.8.7-p174
4
5
  - 1.9.2
5
6
  - jruby
6
7
  - rbx
@@ -1,2 +1,4 @@
1
- Jakub Šťastný aka Botanicus: 93 (5458 LOC)
2
- Michael S. Klishin: 26 (792 LOC)
1
+ Jakub Stastny aka Botanicus: 124 commits, 27692 LOC
2
+ Theo: 65 commits, 8068 LOC
3
+ Michael S. Klishin: 86 commits, 2972 LOC
4
+ Mark Abramov: 13 commits, 559 LOC
data/Gemfile CHANGED
@@ -1,16 +1,30 @@
1
1
  # encoding: utf-8
2
2
 
3
- source "http://gemcutter.org"
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 => :ruby_19
7
- gem "contributors", :platform => :ruby_19
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 => :mri
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 'simplecov', :platform => :ruby_19
29
+ gem "simplecov", :platform => :mri_19
16
30
  end
@@ -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
- file = ENV["FILE"] || "client"
45
- require_relative "lib/amq/protocol/#{file}.rb"
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/io/string"
57
+ require "amq/client/framing/string/frame"
50
58
 
51
59
  class AMQ::Protocol::Frame
52
60
  def self.decode(string)
53
- AMQ::Client::StringAdapter::Frame.decode(string)
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(StringIO.new(data))
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
@@ -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 = 'f'.freeze
30
- PACK_64BIT_FLOAT = 'd'.freeze
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) # TODO: rewrite more effectively
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
- # Spec is broken: Our errata says that it does define
249
- # something, but it just doesn"t relate do method and
250
- # properties frames. Which makes it, well, suboptimal.
251
- # https://dev.rabbitmq.com/wiki/Amqp091Errata#section_11
252
- limit = frame_size - 7 - 1
253
-
254
- Array.new.tap do |array|
255
- while body
256
- payload, body = body[0, limit + 1], body[limit + 1, body.length - limit]
257
- # array << [0x03, payload]
258
- array << BodyFrame.new(payload, channel)
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:
@@ -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
@@ -1,5 +1,5 @@
1
1
  module AMQ
2
2
  module Protocol
3
- VERSION = "0.7.0.alpha6"
3
+ VERSION = "0.7.0.alpha7"
4
4
  end # Protocol
5
5
  end # AMQ
@@ -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
- # @version 0.0.1
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) # TODO: rewrite more effectively
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
- # Spec is broken: Our errata says that it does define
185
- # something, but it just doesn't relate do method and
186
- # properties frames. Which makes it, well, suboptimal.
187
- # https://dev.rabbitmq.com/wiki/Amqp091Errata#section_11
188
- limit = frame_size - 7 - 1
189
-
190
- Array.new.tap do |array|
191
- while body
192
- payload, body = body[0, limit + 1], body[limit + 1, body.length - limit]
193
- # array << [0x03, payload]
194
- array << BodyFrame.new(payload, channel)
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
- # load "contributors.nake"
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 = %w{client} # add "server" to generate server code
17
- targets.each do |type|
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
- version: 0.7.0.alpha6
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
- date: 2011-05-29 00:00:00.000000000Z
22
+
23
+ date: 2011-06-16 00:00:00 Z
16
24
  dependencies: []
17
- description: ! " amq-protocol is an AMQP 0.9.1 serialization library for Ruby. It
18
- is not an\n AMQP client: amq-protocol only handles serialization and deserialization.\n
19
- \ If you want to write your own AMQP client, this gem can help you with that.\n"
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
- extra_rdoc_files:
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
- require_paths:
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
- version: '0'
80
- required_rubygems_version: !ruby/object:Gem::Requirement
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.4
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
+
@@ -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