bunny 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -0
- data/Rakefile +0 -5
- data/bunny.gemspec +24 -24
- data/lib/bunny.rb +4 -11
- data/lib/bunny/client.rb +22 -22
- data/lib/bunny/exchange.rb +8 -8
- data/lib/bunny/queue.rb +17 -17
- data/lib/qrack/client.rb +5 -0
- data/lib/{bunny → qrack}/protocol/protocol.rb +1 -1
- data/lib/{bunny → qrack}/protocol/spec.rb +245 -259
- data/lib/qrack/qrack.rb +28 -0
- data/lib/{bunny → qrack}/transport/buffer.rb +8 -7
- data/lib/qrack/transport/frame.rb +100 -0
- metadata +8 -8
- data/ext/amqp-0.8.json +0 -617
- data/ext/codegen.rb +0 -177
- data/lib/bunny/transport/frame.rb +0 -62
data/ext/codegen.rb
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
name = 'amqp-0.8.json'
|
5
|
-
path = File.dirname(__FILE__)+'/'+name
|
6
|
-
s = JSON.parse(File.read(path))
|
7
|
-
|
8
|
-
# require 'pp'
|
9
|
-
# pp(s)
|
10
|
-
# exit
|
11
|
-
|
12
|
-
require 'erb'
|
13
|
-
|
14
|
-
puts ERB.new(%q[
|
15
|
-
#:stopdoc:
|
16
|
-
# this file was autogenerated on <%= Time.now.to_s %>
|
17
|
-
# using <%= name.ljust(16) %> (mtime: <%= File.mtime(path) %>)
|
18
|
-
#
|
19
|
-
# DO NOT EDIT! (edit ext/codegen.rb instead, and run `rake codegen`)
|
20
|
-
|
21
|
-
module Bunny
|
22
|
-
module Transport
|
23
|
-
class Frame
|
24
|
-
def self.types
|
25
|
-
@types ||= {}
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.Frame id
|
29
|
-
(@_base_frames ||= {})[id] ||= Class.new(Frame) do
|
30
|
-
class_eval %[
|
31
|
-
def self.inherited klass
|
32
|
-
klass.const_set(:ID, #{id})
|
33
|
-
Frame.types[#{id}] = klass
|
34
|
-
end
|
35
|
-
]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
<%- s['constants'].select{|c| (1..8).include? c['value'] }.each do |c| -%>
|
40
|
-
class <%= c['name'].gsub(/^FRAME-/,'').split('-').map{|w| w.downcase.capitalize}.join.ljust(9) -%> < Frame( <%= c['value'] -%> ); end
|
41
|
-
<%- end -%>
|
42
|
-
|
43
|
-
FOOTER = <%= frame_end = s['constants'].find{|c| c['name'] == 'FRAME-END' }['value'] %>
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
module Bunny
|
49
|
-
module Protocol
|
50
|
-
HEADER = <%= s['name'].dump %>.freeze
|
51
|
-
VERSION_MAJOR = <%= s['major-version'] %>
|
52
|
-
VERSION_MINOR = <%= s['minor-version'] %>
|
53
|
-
PORT = <%= s['port'] %>
|
54
|
-
|
55
|
-
RESPONSES = {
|
56
|
-
<%- s['constants'].select{|c| c['value'] != frame_end and (200..500).include? c['value'] }.each do |c| -%>
|
57
|
-
<%= c['value'] %> => :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
|
58
|
-
<%- end -%>
|
59
|
-
}
|
60
|
-
|
61
|
-
FIELDS = [
|
62
|
-
<%- s['domains'].select{|d| d.first == d.last }.each do |d| -%>
|
63
|
-
:<%= d.first -%>,
|
64
|
-
<%- end -%>
|
65
|
-
]
|
66
|
-
|
67
|
-
class Class
|
68
|
-
class << self
|
69
|
-
FIELDS.each do |f|
|
70
|
-
class_eval %[
|
71
|
-
def #{f} name
|
72
|
-
properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
|
73
|
-
attr_accessor name
|
74
|
-
end
|
75
|
-
]
|
76
|
-
end
|
77
|
-
|
78
|
-
def properties() @properties ||= [] end
|
79
|
-
|
80
|
-
def id() self::ID end
|
81
|
-
def name() self::NAME end
|
82
|
-
end
|
83
|
-
|
84
|
-
class Method
|
85
|
-
class << self
|
86
|
-
FIELDS.each do |f|
|
87
|
-
class_eval %[
|
88
|
-
def #{f} name
|
89
|
-
arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
|
90
|
-
attr_accessor name
|
91
|
-
end
|
92
|
-
]
|
93
|
-
end
|
94
|
-
|
95
|
-
def arguments() @arguments ||= [] end
|
96
|
-
|
97
|
-
def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
|
98
|
-
def id() self::ID end
|
99
|
-
def name() self::NAME end
|
100
|
-
end
|
101
|
-
|
102
|
-
def == b
|
103
|
-
self.class.arguments.inject(true) do |eql, (type, name)|
|
104
|
-
eql and __send__("#{name}") == b.__send__("#{name}")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.methods() @methods ||= {} end
|
110
|
-
|
111
|
-
def self.Method(id, name)
|
112
|
-
@_base_methods ||= {}
|
113
|
-
@_base_methods[id] ||= ::Class.new(Method) do
|
114
|
-
class_eval %[
|
115
|
-
def self.inherited klass
|
116
|
-
klass.const_set(:ID, #{id})
|
117
|
-
klass.const_set(:NAME, :#{name.to_s})
|
118
|
-
klass.parent.methods[#{id}] = klass
|
119
|
-
klass.parent.methods[klass::NAME] = klass
|
120
|
-
end
|
121
|
-
]
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def self.classes() @classes ||= {} end
|
127
|
-
|
128
|
-
def self.Class(id, name)
|
129
|
-
@_base_classes ||= {}
|
130
|
-
@_base_classes[id] ||= ::Class.new(Class) do
|
131
|
-
class_eval %[
|
132
|
-
def self.inherited klass
|
133
|
-
klass.const_set(:ID, #{id})
|
134
|
-
klass.const_set(:NAME, :#{name.to_s})
|
135
|
-
Protocol.classes[#{id}] = klass
|
136
|
-
Protocol.classes[klass::NAME] = klass
|
137
|
-
end
|
138
|
-
]
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
module Bunny
|
145
|
-
module Protocol
|
146
|
-
<%- s['classes'].each do |c| -%>
|
147
|
-
class <%= c['name'].capitalize.ljust(12) %> < Class( <%= c['id'].to_s.rjust(3) %>, :<%= c['name'].ljust(12) %> ); end
|
148
|
-
<%- end -%>
|
149
|
-
|
150
|
-
<%- s['classes'].each do |c| -%>
|
151
|
-
class <%= c['name'].capitalize %>
|
152
|
-
<%- c['properties'].each do |p| -%>
|
153
|
-
<%= p['type'].ljust(10) %> :<%= p['name'].tr('-','_') %>
|
154
|
-
<%- end if c['properties'] -%>
|
155
|
-
|
156
|
-
<%- c['methods'].each do |m| -%>
|
157
|
-
class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"}.ljust(12) %> < Method( <%= m['id'].to_s.rjust(3) %>, :<%= m['name'].tr('- ','_').ljust(14) %> ); end
|
158
|
-
<%- end -%>
|
159
|
-
|
160
|
-
<%- c['methods'].each do |m| -%>
|
161
|
-
class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"} %>
|
162
|
-
<%- m['arguments'].each do |a| -%>
|
163
|
-
<%- if a['domain'] -%>
|
164
|
-
<%= s['domains'].find{|k,v| k == a['domain']}.last.ljust(10) %> :<%= a['name'].tr('- ','_') %>
|
165
|
-
<%- else -%>
|
166
|
-
<%= a['type'].ljust(10) %> :<%= a['name'].tr('- ','_') %>
|
167
|
-
<%- end -%>
|
168
|
-
<%- end if m['arguments'] -%>
|
169
|
-
end
|
170
|
-
|
171
|
-
<%- end -%>
|
172
|
-
end
|
173
|
-
|
174
|
-
<%- end -%>
|
175
|
-
end
|
176
|
-
end
|
177
|
-
].gsub!(/^ /,''), nil, '>-%').result(binding)
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Bunny
|
2
|
-
module Transport #:nodoc: all
|
3
|
-
class Frame
|
4
|
-
def initialize payload = nil, channel = 0
|
5
|
-
@channel, @payload = channel, payload
|
6
|
-
end
|
7
|
-
attr_accessor :channel, :payload
|
8
|
-
|
9
|
-
def id
|
10
|
-
self.class::ID
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_binary
|
14
|
-
buf = Transport::Buffer.new
|
15
|
-
buf.write :octet, id
|
16
|
-
buf.write :short, channel
|
17
|
-
buf.write :longstr, payload
|
18
|
-
buf.write :octet, Transport::Frame::FOOTER
|
19
|
-
buf.rewind
|
20
|
-
buf
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
to_binary.to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
def == frame
|
28
|
-
[ :id, :channel, :payload ].inject(true) do |eql, field|
|
29
|
-
eql and __send__(field) == frame.__send__(field)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Method
|
34
|
-
def initialize payload = nil, channel = 0
|
35
|
-
super
|
36
|
-
unless @payload.is_a? Protocol::Class::Method or @payload.nil?
|
37
|
-
@payload = Protocol.parse(@payload)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class Header
|
43
|
-
def initialize payload = nil, channel = 0
|
44
|
-
super
|
45
|
-
unless @payload.is_a? Protocol::Header or @payload.nil?
|
46
|
-
@payload = Protocol::Header.new(@payload)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class Body; end
|
52
|
-
|
53
|
-
def self.parse buf
|
54
|
-
buf = Transport::Buffer.new(buf) unless buf.is_a? Transport::Buffer
|
55
|
-
buf.extract do
|
56
|
-
id, channel, payload, footer = buf.read(:octet, :short, :longstr, :octet)
|
57
|
-
Transport::Frame.types[id].new(payload, channel) if footer == Transport::Frame::FOOTER
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|