gorgon 0.5.0.rc1 → 0.6.0.rc1

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.
Files changed (68) hide show
  1. data/Gemfile.lock +2 -4
  2. data/gorgon.gemspec +0 -1
  3. data/lib/gorgon/amqp_service.rb +5 -5
  4. data/lib/gorgon/gem_command_handler.rb +2 -1
  5. data/lib/gorgon/listener.rb +7 -5
  6. data/lib/gorgon/originator_protocol.rb +1 -0
  7. data/lib/gorgon/version.rb +1 -1
  8. data/lib/gorgon/worker_manager.rb +5 -2
  9. data/lib/gorgon_amq-protocol/.gitignore +15 -0
  10. data/lib/gorgon_amq-protocol/.gitmodules +3 -0
  11. data/lib/gorgon_amq-protocol/.rspec +3 -0
  12. data/lib/gorgon_amq-protocol/.travis.yml +19 -0
  13. data/lib/gorgon_amq-protocol/lib/gorgon_amq/bit_set.rb +82 -0
  14. data/lib/gorgon_amq-protocol/lib/gorgon_amq/endianness.rb +15 -0
  15. data/lib/gorgon_amq-protocol/lib/gorgon_amq/int_allocator.rb +96 -0
  16. data/lib/gorgon_amq-protocol/lib/gorgon_amq/pack.rb +53 -0
  17. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol.rb +4 -0
  18. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/client.rb +2322 -0
  19. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/constants.rb +22 -0
  20. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/exceptions.rb +60 -0
  21. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/float_32bit.rb +14 -0
  22. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb +210 -0
  23. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/table.rb +142 -0
  24. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/table_value_decoder.rb +190 -0
  25. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/table_value_encoder.rb +123 -0
  26. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/type_constants.rb +26 -0
  27. data/lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/version.rb +5 -0
  28. data/lib/gorgon_amq-protocol/lib/gorgon_amq/settings.rb +114 -0
  29. data/lib/gorgon_amq-protocol/lib/gorgon_amq/uri.rb +37 -0
  30. data/lib/gorgon_bunny/lib/gorgon_amq/protocol/extensions.rb +16 -0
  31. data/lib/gorgon_bunny/lib/gorgon_bunny.rb +89 -0
  32. data/lib/gorgon_bunny/lib/gorgon_bunny/authentication/credentials_encoder.rb +55 -0
  33. data/lib/gorgon_bunny/lib/gorgon_bunny/authentication/external_mechanism_encoder.rb +27 -0
  34. data/lib/gorgon_bunny/lib/gorgon_bunny/authentication/plain_mechanism_encoder.rb +19 -0
  35. data/lib/gorgon_bunny/lib/gorgon_bunny/channel.rb +1875 -0
  36. data/lib/gorgon_bunny/lib/gorgon_bunny/channel_id_allocator.rb +80 -0
  37. data/lib/gorgon_bunny/lib/gorgon_bunny/compatibility.rb +24 -0
  38. data/lib/gorgon_bunny/lib/gorgon_bunny/concurrent/atomic_fixnum.rb +74 -0
  39. data/lib/gorgon_bunny/lib/gorgon_bunny/concurrent/condition.rb +66 -0
  40. data/lib/gorgon_bunny/lib/gorgon_bunny/concurrent/continuation_queue.rb +41 -0
  41. data/lib/gorgon_bunny/lib/gorgon_bunny/concurrent/linked_continuation_queue.rb +61 -0
  42. data/lib/gorgon_bunny/lib/gorgon_bunny/concurrent/synchronized_sorted_set.rb +56 -0
  43. data/lib/gorgon_bunny/lib/gorgon_bunny/consumer.rb +123 -0
  44. data/lib/gorgon_bunny/lib/gorgon_bunny/consumer_tag_generator.rb +23 -0
  45. data/lib/gorgon_bunny/lib/gorgon_bunny/consumer_work_pool.rb +94 -0
  46. data/lib/gorgon_bunny/lib/gorgon_bunny/delivery_info.rb +93 -0
  47. data/lib/gorgon_bunny/lib/gorgon_bunny/exceptions.rb +236 -0
  48. data/lib/gorgon_bunny/lib/gorgon_bunny/exchange.rb +271 -0
  49. data/lib/gorgon_bunny/lib/gorgon_bunny/framing.rb +56 -0
  50. data/lib/gorgon_bunny/lib/gorgon_bunny/heartbeat_sender.rb +70 -0
  51. data/lib/gorgon_bunny/lib/gorgon_bunny/message_properties.rb +119 -0
  52. data/lib/gorgon_bunny/lib/gorgon_bunny/queue.rb +387 -0
  53. data/lib/gorgon_bunny/lib/gorgon_bunny/reader_loop.rb +116 -0
  54. data/lib/gorgon_bunny/lib/gorgon_bunny/return_info.rb +74 -0
  55. data/lib/gorgon_bunny/lib/gorgon_bunny/session.rb +1044 -0
  56. data/lib/gorgon_bunny/lib/gorgon_bunny/socket.rb +83 -0
  57. data/lib/gorgon_bunny/lib/gorgon_bunny/ssl_socket.rb +57 -0
  58. data/lib/gorgon_bunny/lib/gorgon_bunny/system_timer.rb +20 -0
  59. data/lib/gorgon_bunny/lib/gorgon_bunny/test_kit.rb +27 -0
  60. data/lib/gorgon_bunny/lib/gorgon_bunny/timeout.rb +18 -0
  61. data/lib/gorgon_bunny/lib/gorgon_bunny/transport.rb +398 -0
  62. data/lib/gorgon_bunny/lib/gorgon_bunny/version.rb +6 -0
  63. data/lib/gorgon_bunny/lib/gorgon_bunny/versioned_delivery_tag.rb +28 -0
  64. data/spec/crash_reporter_spec.rb +1 -1
  65. data/spec/gem_command_handler_spec.rb +2 -2
  66. data/spec/listener_spec.rb +5 -5
  67. data/spec/worker_manager_spec.rb +3 -3
  68. metadata +56 -17
data/Gemfile.lock CHANGED
@@ -1,10 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gorgon (0.4.5)
4
+ gorgon (0.6.0.rc1)
5
5
  amqp (~> 0.9.7)
6
6
  awesome_print
7
- bunny (= 0.8.0)
8
7
  colorize (~> 0.5.8)
9
8
  open4 (~> 1.3.0)
10
9
  ruby-progressbar (~> 1.0.1)
@@ -22,8 +21,7 @@ GEM
22
21
  amq-client (~> 0.9.12)
23
22
  amq-protocol (~> 1.2.0)
24
23
  eventmachine
25
- awesome_print (1.2.0)
26
- bunny (0.8.0)
24
+ awesome_print (1.1.0)
27
25
  colorize (0.5.8)
28
26
  diff-lcs (1.1.3)
29
27
  eventmachine (1.0.3)
data/gorgon.gemspec CHANGED
@@ -32,5 +32,4 @@ Gem::Specification.new do |s|
32
32
  # This problem should be fixed
33
33
  s.add_runtime_dependency "yajl-ruby", '=1.1.0'
34
34
  s.add_runtime_dependency "uuidtools", '=2.1.3'
35
- s.add_runtime_dependency "bunny", '=0.8.0'
36
35
  end
@@ -1,4 +1,4 @@
1
- require 'bunny'
1
+ require 'gorgon_bunny/lib/gorgon_bunny'
2
2
  require 'yajl'
3
3
 
4
4
  class AmqpQueueDecorator
@@ -8,8 +8,8 @@ class AmqpQueueDecorator
8
8
 
9
9
  def pop
10
10
  m = @queue.pop
11
- p = m[:payload]
12
- p == :queue_empty ? nil : p
11
+ payload = m[2]
12
+ return payload
13
13
  end
14
14
  end
15
15
 
@@ -30,10 +30,10 @@ class AmqpService
30
30
  end
31
31
 
32
32
  def start_worker file_queue_name, reply_exchange_name
33
- Bunny.run @connection_config do |b|
33
+ GorgonBunny.run @connection_config do |b|
34
34
  queue = b.queue file_queue_name
35
35
  exchange = b.exchange reply_exchange_name
36
36
  yield AmqpQueueDecorator.new(queue), AmqpExchangeDecorator.new(exchange)
37
37
  end
38
38
  end
39
- end
39
+ end
@@ -1,6 +1,7 @@
1
1
  require "socket"
2
2
  require "yajl"
3
- require "bunny"
3
+
4
+ require "gorgon_bunny/lib/gorgon_bunny"
4
5
  require 'open4'
5
6
 
6
7
  class GemCommandHandler
@@ -9,7 +9,7 @@ require "gorgon/crash_reporter"
9
9
  require "gorgon/gem_command_handler"
10
10
 
11
11
  require "yajl"
12
- require "bunny"
12
+ require "gorgon_bunny/lib/gorgon_bunny"
13
13
  require "awesome_print"
14
14
  require "open4"
15
15
  require "tmpdir"
@@ -38,7 +38,7 @@ class Listener
38
38
  end
39
39
 
40
40
  def connect
41
- @bunny = Bunny.new(connection_information)
41
+ @bunny = GorgonBunny.new(connection_information)
42
42
  @bunny.start
43
43
  end
44
44
 
@@ -50,10 +50,12 @@ class Listener
50
50
 
51
51
  def poll
52
52
  message = @job_queue.pop
53
- return false if message[:payload] == :queue_empty
54
- log "Received: #{message[:payload]}"
53
+ return false if message == [nil, nil, nil]
54
+ log "Received: #{message}"
55
55
 
56
- handle_request message[:payload]
56
+ payload = message[2]
57
+
58
+ handle_request payload
57
59
 
58
60
  log "Waiting for more jobs..."
59
61
  return true
@@ -1,3 +1,4 @@
1
+
1
2
  require 'gorgon/job_definition'
2
3
 
3
4
  require 'amqp'
@@ -1,3 +1,3 @@
1
1
  module Gorgon
2
- VERSION = "0.5.0.rc1"
2
+ VERSION = "0.6.0.rc1"
3
3
  end
@@ -56,7 +56,7 @@ class WorkerManager
56
56
  private
57
57
 
58
58
  def connect
59
- @bunny = Bunny.new(@config[:connection])
59
+ @bunny = GorgonBunny.new(@config[:connection])
60
60
  @bunny.start
61
61
  @reply_exchange = @bunny.exchange(@job_definition.reply_exchange_name)
62
62
 
@@ -156,8 +156,11 @@ class WorkerManager
156
156
  def subscribe_to_originator_queue
157
157
 
158
158
  originator_watcher = proc do
159
+ payload = nil
159
160
  while true
160
- if (payload = @originator_queue.pop[:payload]) != :queue_empty
161
+ response = @originator_queue.pop
162
+ if response != [nil, nil, nil]
163
+ payload = response[2]
161
164
  break
162
165
  end
163
166
  sleep 0.5
@@ -0,0 +1,15 @@
1
+ /*.gem
2
+ /.rvmrc
3
+ /.ruby-version
4
+ tmp
5
+ *.pyc
6
+ /vendor/bundle
7
+ /vendor/amq-*
8
+ /coverage
9
+ Gemfile.lock
10
+ .rbx/*
11
+ .Apple*
12
+ .bundle/*
13
+ bin/*
14
+ *.bundle
15
+ Makefile
@@ -0,0 +1,3 @@
1
+ [submodule "codegen/rabbitmq-codegen"]
2
+ path = codegen/rabbitmq-codegen
3
+ url = git://github.com/rabbitmq/rabbitmq-codegen.git
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format
3
+ progress
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ script: "bundle exec rspec spec"
4
+ rvm:
5
+ - 2.0
6
+ - 1.9.3
7
+ - jruby-19mode
8
+ - 1.9.2
9
+ - rbx-19mode
10
+ - ruby-head
11
+ - jruby-head
12
+ - 1.8.7
13
+ - rbx-18mode
14
+ notifications:
15
+ recipients:
16
+ - michael@novemberain.com
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: ruby-head
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+
3
+ module GorgonAMQ
4
+ # Very minimalistic, pure Ruby implementation of bit set. Inspired by java.util.BitSet,
5
+ # although significantly smaller in scope.
6
+ #
7
+ # Originally part of amqp gem. Extracted to make it possible for Bunny to use it.
8
+ class BitSet
9
+
10
+ #
11
+ # API
12
+ #
13
+
14
+ ADDRESS_BITS_PER_WORD = 6
15
+ BITS_PER_WORD = (1 << ADDRESS_BITS_PER_WORD)
16
+ WORD_MASK = 0xffffffffffffffff
17
+
18
+ # @param [Integer] Number of bits in the set
19
+ # @api public
20
+ def initialize(nbits)
21
+ @nbits = nbits
22
+
23
+ self.init_words(nbits)
24
+ end # initialize(nbits)
25
+
26
+ # Sets (flags) given bit. This method allows bits to be set more than once in a row, no exception will be raised.
27
+ #
28
+ # @param [Integer] A bit to set
29
+ # @api public
30
+ def set(i)
31
+ w = self.word_index(i)
32
+ @words[w] |= (1 << i)
33
+ end # set(i)
34
+
35
+ # Fetches flag value for given bit.
36
+ #
37
+ # @param [Integer] A bit to fetch
38
+ # @return [Boolean] true if given bit is set, false otherwise
39
+ # @api public
40
+ def get(i)
41
+ w = self.word_index(i)
42
+
43
+ (@words[w] & (1 << i)) != 0
44
+ end # get(i)
45
+ alias [] get
46
+
47
+ # Unsets (unflags) given bit. This method allows bits to be unset more than once in a row, no exception will be raised.
48
+ #
49
+ # @param [Integer] A bit to unset
50
+ # @api public
51
+ def unset(i)
52
+ w = self.word_index(i)
53
+ return if w.nil?
54
+
55
+ @words[w] &= ~(1 << i)
56
+ end # unset(i)
57
+
58
+ # Clears all bits in the set
59
+ # @api public
60
+ def clear
61
+ self.init_words(@nbits)
62
+ end # clear
63
+
64
+
65
+ #
66
+ # Implementation
67
+ #
68
+
69
+ protected
70
+
71
+ # @private
72
+ def init_words(nbits)
73
+ n = word_index(nbits-1) + 1
74
+ @words = Array.new(n) { 1 }
75
+ end # init_words
76
+
77
+ # @private
78
+ def word_index(i)
79
+ i >> ADDRESS_BITS_PER_WORD
80
+ end # word_index(i)
81
+ end # BitSet
82
+ end # AMQ
@@ -0,0 +1,15 @@
1
+ module GorgonAMQ
2
+ module Endianness
3
+ BIG_ENDIAN = ([1].pack("s") == "\x00\x01")
4
+
5
+ def big_endian?
6
+ BIG_ENDIAN
7
+ end
8
+
9
+ def little_endian?
10
+ !BIG_ENDIAN
11
+ end
12
+
13
+ extend self
14
+ end
15
+ end
@@ -0,0 +1,96 @@
1
+ # encoding: utf-8
2
+
3
+ require "gorgon_amq/bit_set"
4
+
5
+ module GorgonAMQ
6
+ # Simple bitset-based integer allocator, heavily inspired by com.rabbitmq.utility.IntAllocator class
7
+ # in the RabbitMQ Java client.
8
+ #
9
+ # Unlike monotonically incrementing identifier, this allocator is suitable for very long running programs
10
+ # that aggressively allocate and release channels.
11
+ class IntAllocator
12
+
13
+ #
14
+ # API
15
+ #
16
+
17
+ # @return [Integer] Number of integers in the allocation range
18
+ attr_reader :number_of_bits
19
+ # @return [Integer] Upper boundary of the integer range available for allocation
20
+ attr_reader :hi
21
+ # @return [Integer] Lower boundary of the integer range available for allocation
22
+ attr_reader :lo
23
+
24
+ # @param [Integer] lo Lower boundary of the integer range available for allocation
25
+ # @param [Integer] hi Upper boundary of the integer range available for allocation
26
+ # @raise [ArgumentError] if upper boundary is not greater than the lower one
27
+ def initialize(lo, hi)
28
+ raise ArgumentError.new "upper boundary must be greater than the lower one (given: hi = #{hi}, lo = #{lo})" unless hi > lo
29
+
30
+ @hi = hi
31
+ @lo = lo
32
+
33
+ @number_of_bits = hi - lo
34
+ @range = Range.new(1, @number_of_bits)
35
+ @free_set = BitSet.new(@number_of_bits)
36
+ end # initialize(hi, lo)
37
+
38
+ # Attempts to allocate next available integer. If allocation succeeds, allocated value is returned.
39
+ # Otherwise, nil is returned.
40
+ #
41
+ # Current implementation of this method is O(n), where n is number of bits in the range available for
42
+ # allocation.
43
+ #
44
+ # @return [Integer] Allocated integer if allocation succeeded. nil otherwise.
45
+ def allocate
46
+ if n = find_unallocated_position
47
+ @free_set.set(n)
48
+
49
+ n
50
+ else
51
+ -1
52
+ end
53
+ end # allocate
54
+
55
+ # Releases previously allocated integer. If integer provided as argument was not previously allocated,
56
+ # this method has no effect.
57
+ #
58
+ # @return [NilClass] nil
59
+ def free(reservation)
60
+ @free_set.unset(reservation)
61
+ end # free(reservation)
62
+ alias release free
63
+
64
+ # @return [Boolean] true if provided argument was previously allocated, false otherwise
65
+ def allocated?(reservation)
66
+ @free_set.get(reservation)
67
+ end # allocated?(reservation)
68
+
69
+ # Releases the whole allocation range
70
+ def reset
71
+ @free_set.clear
72
+ end # reset
73
+
74
+
75
+
76
+ protected
77
+
78
+ # This implementation is significantly less efficient
79
+ # that what the RabbitMQ Java client has (based on java.lang.Long#nextSetBit and
80
+ # java.lang.Long.numberOfTrailingZeros, and thus binary search over bits).
81
+ # But for channel id generation, this is a good enough implementation.
82
+ #
83
+ # @private
84
+ def find_unallocated_position
85
+ r = nil
86
+ @range.each do |i|
87
+ if !@free_set.get(i)
88
+ r = i
89
+ break;
90
+ end
91
+ end
92
+
93
+ r
94
+ end # find_unallocated_position
95
+ end # IntAllocator
96
+ end # AMQ
@@ -0,0 +1,53 @@
1
+ # encoding: binary
2
+
3
+ require 'gorgon_amq/endianness'
4
+
5
+ module GorgonAMQ
6
+ # Implements pack to/unpack from 64bit string in network byte order
7
+ # compatible with Ruby 1.8+.
8
+ module Pack
9
+ UINT64 = "Q".freeze
10
+ INT16 = "c".freeze
11
+
12
+ if Endianness.big_endian?
13
+ def self.pack_uint64_big_endian(long_long)
14
+ [long_long].pack(UINT64)
15
+ end
16
+
17
+ def self.unpack_uint64_big_endian(data)
18
+ data.unpack(UINT64)
19
+ end
20
+
21
+ def self.pack_int16_big_endian(short)
22
+ [long_long].pack(INT16)
23
+ end
24
+
25
+ def self.unpack_int16_big_endian(data)
26
+ data.unpack(INT16)
27
+ end
28
+ else
29
+ def self.pack_uint64_big_endian(long_long)
30
+ result = [long_long].pack(UINT64)
31
+ result.bytes.to_a.reverse.map(&:chr).join
32
+ end
33
+
34
+ def self.unpack_uint64_big_endian(data)
35
+ data = data.bytes.to_a.reverse.map(&:chr).join
36
+ data.unpack(UINT64)
37
+ end
38
+
39
+ def self.pack_int16_big_endian(short)
40
+ result = [long_long].pack(INT16)
41
+ result.bytes.to_a.reverse.map(&:chr).join
42
+ end
43
+
44
+ def self.unpack_int16_big_endian(data)
45
+ data = data.bytes.to_a.reverse.map(&:chr).join
46
+ data.unpack(INT16)
47
+ end
48
+ end
49
+ end
50
+
51
+ # Backwards compatibility
52
+ Hacks = Pack
53
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "gorgon_amq/protocol/version"
4
+ require "gorgon_amq/protocol/client"
@@ -0,0 +1,2322 @@
1
+ # encoding: binary
2
+
3
+ # THIS IS AN AUTOGENERATED FILE, DO NOT MODIFY
4
+ # IT DIRECTLY ! FOR CHANGES, PLEASE UPDATE FILES
5
+ # IN THE ./codegen DIRECTORY OF THE AMQ-PROTOCOL REPOSITORY.
6
+
7
+ require "gorgon_amq/pack"
8
+
9
+ require "gorgon_amq/protocol/table"
10
+ require "gorgon_amq/protocol/frame"
11
+
12
+ require "gorgon_amq/protocol/constants"
13
+ require "gorgon_amq/protocol/exceptions"
14
+
15
+ module GorgonAMQ
16
+ module Protocol
17
+ PROTOCOL_VERSION = "0.9.1".freeze
18
+ PREAMBLE = "AMQP\x00\x00\x09\x01".freeze
19
+ DEFAULT_PORT = 5672
20
+
21
+ # @return [Array] Collection of subclasses of GorgonAMQ::Protocol::Class.
22
+ def self.classes
23
+ Protocol::Class.classes
24
+ end
25
+
26
+ # @return [Array] Collection of subclasses of GorgonAMQ::Protocol::Method.
27
+ def self.methods
28
+ Protocol::Method.methods
29
+ end
30
+
31
+ class ContentTooLarge < SoftError
32
+ VALUE = 311
33
+ end
34
+
35
+ class NoRoute < SoftError
36
+ VALUE = 312
37
+ end
38
+
39
+ class NoConsumers < SoftError
40
+ VALUE = 313
41
+ end
42
+
43
+ class AccessRefused < SoftError
44
+ VALUE = 403
45
+ end
46
+
47
+ class NotFound < SoftError
48
+ VALUE = 404
49
+ end
50
+
51
+ class ResourceLocked < SoftError
52
+ VALUE = 405
53
+ end
54
+
55
+ class PreconditionFailed < SoftError
56
+ VALUE = 406
57
+ end
58
+
59
+ class ConnectionForced < HardError
60
+ VALUE = 320
61
+ end
62
+
63
+ class InvalidPath < HardError
64
+ VALUE = 402
65
+ end
66
+
67
+ class FrameError < HardError
68
+ VALUE = 501
69
+ end
70
+
71
+ class SyntaxError < HardError
72
+ VALUE = 502
73
+ end
74
+
75
+ class CommandInvalid < HardError
76
+ VALUE = 503
77
+ end
78
+
79
+ class ChannelError < HardError
80
+ VALUE = 504
81
+ end
82
+
83
+ class UnexpectedFrame < HardError
84
+ VALUE = 505
85
+ end
86
+
87
+ class ResourceError < HardError
88
+ VALUE = 506
89
+ end
90
+
91
+ class NotAllowed < HardError
92
+ VALUE = 530
93
+ end
94
+
95
+ class NotImplemented < HardError
96
+ VALUE = 540
97
+ end
98
+
99
+ class InternalError < HardError
100
+ VALUE = 541
101
+ end
102
+
103
+
104
+ class Class
105
+ @classes = Array.new
106
+
107
+ def self.method_id
108
+ @method_id
109
+ end
110
+
111
+ def self.name
112
+ @name
113
+ end
114
+
115
+ def self.inherited(base)
116
+ if self == Protocol::Class
117
+ @classes << base
118
+ end
119
+ end
120
+
121
+ def self.classes
122
+ @classes
123
+ end
124
+ end
125
+
126
+ class Method
127
+ @methods = Array.new
128
+ def self.method_id
129
+ @method_id
130
+ end
131
+
132
+ def self.name
133
+ @name
134
+ end
135
+
136
+ def self.index
137
+ @index
138
+ end
139
+
140
+ def self.inherited(base)
141
+ if self == Protocol::Method
142
+ @methods << base
143
+ end
144
+ end
145
+
146
+ def self.methods
147
+ @methods
148
+ end
149
+
150
+ def self.split_headers(user_headers)
151
+ properties, headers = {}, {}
152
+ user_headers.each do |key, value|
153
+ # key MUST be a symbol since symbols are not garbage-collected
154
+ if Basic::PROPERTIES.include?(key)
155
+ properties[key] = value
156
+ else
157
+ headers[key] = value
158
+ end
159
+ end
160
+
161
+ return [properties, headers]
162
+ end
163
+
164
+ def self.encode_body(body, channel, frame_size)
165
+ return [] if body.empty?
166
+
167
+ # 8 = 1 + 2 + 4 + 1
168
+ # 1 byte of frame type
169
+ # 2 bytes of channel number
170
+ # 4 bytes of frame payload length
171
+ # 1 byte of payload trailer FRAME_END byte
172
+ limit = frame_size - 8
173
+ return [BodyFrame.new(body, channel)] if body.bytesize < limit
174
+
175
+ # Otherwise String#slice on 1.9 will operate with code points,
176
+ # and we need bytes. MK.
177
+ body.force_encoding("ASCII-8BIT") if RUBY_VERSION.to_f >= 1.9
178
+
179
+ array = Array.new
180
+ while body && !body.empty?
181
+ payload, body = body[0, limit], body[limit, body.length - limit]
182
+ array << BodyFrame.new(payload, channel)
183
+ end
184
+
185
+ array
186
+ end
187
+
188
+ def self.instantiate(*args, &block)
189
+ self.new(*args, &block)
190
+ end
191
+ end
192
+
193
+ class Connection < Protocol::Class
194
+ @name = "connection"
195
+ @method_id = 10
196
+
197
+
198
+
199
+ class Start < Protocol::Method
200
+ @name = "connection.start"
201
+ @method_id = 10
202
+ @index = 0x000A000A # 10, 10, 655370
203
+ @packed_indexes = [10, 10].pack(PACK_UINT16_X2).freeze
204
+
205
+ # @return
206
+ def self.decode(data)
207
+ offset = 0
208
+ version_major = data[offset, 1].unpack(PACK_CHAR).first
209
+ offset += 1
210
+ version_minor = data[offset, 1].unpack(PACK_CHAR).first
211
+ offset += 1
212
+ table_length = Table.length(data[offset, 4])
213
+ server_properties = Table.decode(data[offset, table_length + 4])
214
+ offset += table_length + 4
215
+ length = data[offset, 4].unpack(PACK_UINT32).first
216
+ offset += 4
217
+ mechanisms = data[offset, length]
218
+ offset += length
219
+ length = data[offset, 4].unpack(PACK_UINT32).first
220
+ offset += 4
221
+ locales = data[offset, length]
222
+ offset += length
223
+ self.new(version_major, version_minor, server_properties, mechanisms, locales)
224
+ end
225
+
226
+ attr_reader :version_major, :version_minor, :server_properties, :mechanisms, :locales
227
+ def initialize(version_major, version_minor, server_properties, mechanisms, locales)
228
+ @version_major = version_major
229
+ @version_minor = version_minor
230
+ @server_properties = server_properties
231
+ @mechanisms = mechanisms
232
+ @locales = locales
233
+ end
234
+
235
+ def self.has_content?
236
+ false
237
+ end
238
+
239
+
240
+ end
241
+
242
+ class StartOk < Protocol::Method
243
+ @name = "connection.start-ok"
244
+ @method_id = 11
245
+ @index = 0x000A000B # 10, 11, 655371
246
+ @packed_indexes = [10, 11].pack(PACK_UINT16_X2).freeze
247
+
248
+
249
+ def self.has_content?
250
+ false
251
+ end
252
+
253
+ # @return
254
+ # [u'client_properties = nil', u"mechanism = u'PLAIN'", u'response = nil', u"locale = u'en_US'"]
255
+ def self.encode(client_properties, mechanism, response, locale)
256
+ channel = 0
257
+ buffer = @packed_indexes.dup
258
+ buffer << GorgonAMQ::Protocol::Table.encode(client_properties)
259
+ buffer << mechanism.to_s.bytesize.chr
260
+ buffer << mechanism.to_s
261
+ buffer << [response.to_s.bytesize].pack(PACK_UINT32)
262
+ buffer << response.to_s
263
+ buffer << locale.to_s.bytesize.chr
264
+ buffer << locale.to_s
265
+ MethodFrame.new(buffer, channel)
266
+ end
267
+
268
+ end
269
+
270
+ class Secure < Protocol::Method
271
+ @name = "connection.secure"
272
+ @method_id = 20
273
+ @index = 0x000A0014 # 10, 20, 655380
274
+ @packed_indexes = [10, 20].pack(PACK_UINT16_X2).freeze
275
+
276
+ # @return
277
+ def self.decode(data)
278
+ offset = 0
279
+ length = data[offset, 4].unpack(PACK_UINT32).first
280
+ offset += 4
281
+ challenge = data[offset, length]
282
+ offset += length
283
+ self.new(challenge)
284
+ end
285
+
286
+ attr_reader :challenge
287
+ def initialize(challenge)
288
+ @challenge = challenge
289
+ end
290
+
291
+ def self.has_content?
292
+ false
293
+ end
294
+
295
+
296
+ end
297
+
298
+ class SecureOk < Protocol::Method
299
+ @name = "connection.secure-ok"
300
+ @method_id = 21
301
+ @index = 0x000A0015 # 10, 21, 655381
302
+ @packed_indexes = [10, 21].pack(PACK_UINT16_X2).freeze
303
+
304
+
305
+ def self.has_content?
306
+ false
307
+ end
308
+
309
+ # @return
310
+ # [u'response = nil']
311
+ def self.encode(response)
312
+ channel = 0
313
+ buffer = @packed_indexes.dup
314
+ buffer << [response.to_s.bytesize].pack(PACK_UINT32)
315
+ buffer << response.to_s
316
+ MethodFrame.new(buffer, channel)
317
+ end
318
+
319
+ end
320
+
321
+ class Tune < Protocol::Method
322
+ @name = "connection.tune"
323
+ @method_id = 30
324
+ @index = 0x000A001E # 10, 30, 655390
325
+ @packed_indexes = [10, 30].pack(PACK_UINT16_X2).freeze
326
+
327
+ # @return
328
+ def self.decode(data)
329
+ offset = 0
330
+ channel_max = data[offset, 2].unpack(PACK_UINT16).first
331
+ offset += 2
332
+ frame_max = data[offset, 4].unpack(PACK_UINT32).first
333
+ offset += 4
334
+ heartbeat = data[offset, 2].unpack(PACK_UINT16).first
335
+ offset += 2
336
+ self.new(channel_max, frame_max, heartbeat)
337
+ end
338
+
339
+ attr_reader :channel_max, :frame_max, :heartbeat
340
+ def initialize(channel_max, frame_max, heartbeat)
341
+ @channel_max = channel_max
342
+ @frame_max = frame_max
343
+ @heartbeat = heartbeat
344
+ end
345
+
346
+ def self.has_content?
347
+ false
348
+ end
349
+
350
+
351
+ end
352
+
353
+ class TuneOk < Protocol::Method
354
+ @name = "connection.tune-ok"
355
+ @method_id = 31
356
+ @index = 0x000A001F # 10, 31, 655391
357
+ @packed_indexes = [10, 31].pack(PACK_UINT16_X2).freeze
358
+
359
+
360
+ def self.has_content?
361
+ false
362
+ end
363
+
364
+ # @return
365
+ # [u'channel_max = false', u'frame_max = false', u'heartbeat = false']
366
+ def self.encode(channel_max, frame_max, heartbeat)
367
+ channel = 0
368
+ buffer = @packed_indexes.dup
369
+ buffer << [channel_max].pack(PACK_UINT16)
370
+ buffer << [frame_max].pack(PACK_UINT32)
371
+ buffer << [heartbeat].pack(PACK_UINT16)
372
+ MethodFrame.new(buffer, channel)
373
+ end
374
+
375
+ end
376
+
377
+ class Open < Protocol::Method
378
+ @name = "connection.open"
379
+ @method_id = 40
380
+ @index = 0x000A0028 # 10, 40, 655400
381
+ @packed_indexes = [10, 40].pack(PACK_UINT16_X2).freeze
382
+
383
+
384
+ def self.has_content?
385
+ false
386
+ end
387
+
388
+ # @return
389
+ # [u"virtual_host = u'/'", u'capabilities = EMPTY_STRING', u'insist = false']
390
+ def self.encode(virtual_host)
391
+ capabilities = EMPTY_STRING
392
+ insist = false
393
+ channel = 0
394
+ buffer = @packed_indexes.dup
395
+ buffer << virtual_host.to_s.bytesize.chr
396
+ buffer << virtual_host.to_s
397
+ buffer << capabilities.to_s.bytesize.chr
398
+ buffer << capabilities.to_s
399
+ bit_buffer = 0
400
+ bit_buffer = bit_buffer | (1 << 0) if insist
401
+ buffer << [bit_buffer].pack(PACK_CHAR)
402
+ MethodFrame.new(buffer, channel)
403
+ end
404
+
405
+ end
406
+
407
+ class OpenOk < Protocol::Method
408
+ @name = "connection.open-ok"
409
+ @method_id = 41
410
+ @index = 0x000A0029 # 10, 41, 655401
411
+ @packed_indexes = [10, 41].pack(PACK_UINT16_X2).freeze
412
+
413
+ # @return
414
+ def self.decode(data)
415
+ offset = 0
416
+ length = data[offset, 1].unpack(PACK_CHAR).first
417
+ offset += 1
418
+ known_hosts = data[offset, length]
419
+ offset += length
420
+ self.new(known_hosts)
421
+ end
422
+
423
+ attr_reader :known_hosts
424
+ def initialize(known_hosts)
425
+ @known_hosts = known_hosts
426
+ end
427
+
428
+ def self.has_content?
429
+ false
430
+ end
431
+
432
+
433
+ end
434
+
435
+ class Close < Protocol::Method
436
+ @name = "connection.close"
437
+ @method_id = 50
438
+ @index = 0x000A0032 # 10, 50, 655410
439
+ @packed_indexes = [10, 50].pack(PACK_UINT16_X2).freeze
440
+
441
+ # @return
442
+ def self.decode(data)
443
+ offset = 0
444
+ reply_code = data[offset, 2].unpack(PACK_UINT16).first
445
+ offset += 2
446
+ length = data[offset, 1].unpack(PACK_CHAR).first
447
+ offset += 1
448
+ reply_text = data[offset, length]
449
+ offset += length
450
+ class_id = data[offset, 2].unpack(PACK_UINT16).first
451
+ offset += 2
452
+ method_id = data[offset, 2].unpack(PACK_UINT16).first
453
+ offset += 2
454
+ self.new(reply_code, reply_text, class_id, method_id)
455
+ end
456
+
457
+ attr_reader :reply_code, :reply_text, :class_id, :method_id
458
+ def initialize(reply_code, reply_text, class_id, method_id)
459
+ @reply_code = reply_code
460
+ @reply_text = reply_text
461
+ @class_id = class_id
462
+ @method_id = method_id
463
+ end
464
+
465
+ def self.has_content?
466
+ false
467
+ end
468
+
469
+ # @return
470
+ # [u'reply_code = nil', u'reply_text = EMPTY_STRING', u'class_id = nil', u'method_id = nil']
471
+ def self.encode(reply_code, reply_text, class_id, method_id)
472
+ channel = 0
473
+ buffer = @packed_indexes.dup
474
+ buffer << [reply_code].pack(PACK_UINT16)
475
+ buffer << reply_text.to_s.bytesize.chr
476
+ buffer << reply_text.to_s
477
+ buffer << [class_id].pack(PACK_UINT16)
478
+ buffer << [method_id].pack(PACK_UINT16)
479
+ MethodFrame.new(buffer, channel)
480
+ end
481
+
482
+ end
483
+
484
+ class CloseOk < Protocol::Method
485
+ @name = "connection.close-ok"
486
+ @method_id = 51
487
+ @index = 0x000A0033 # 10, 51, 655411
488
+ @packed_indexes = [10, 51].pack(PACK_UINT16_X2).freeze
489
+
490
+ # @return
491
+ def self.decode(data)
492
+ offset = 0
493
+ self.new()
494
+ end
495
+
496
+ def initialize()
497
+ end
498
+
499
+ def self.has_content?
500
+ false
501
+ end
502
+
503
+ # @return
504
+ # []
505
+ def self.encode()
506
+ channel = 0
507
+ buffer = @packed_indexes.dup
508
+ MethodFrame.new(buffer, channel)
509
+ end
510
+
511
+ end
512
+
513
+ class Blocked < Protocol::Method
514
+ @name = "connection.blocked"
515
+ @method_id = 60
516
+ @index = 0x000A003C # 10, 60, 655420
517
+ @packed_indexes = [10, 60].pack(PACK_UINT16_X2).freeze
518
+
519
+ # @return
520
+ def self.decode(data)
521
+ offset = 0
522
+ length = data[offset, 1].unpack(PACK_CHAR).first
523
+ offset += 1
524
+ reason = data[offset, length]
525
+ offset += length
526
+ self.new(reason)
527
+ end
528
+
529
+ attr_reader :reason
530
+ def initialize(reason)
531
+ @reason = reason
532
+ end
533
+
534
+ def self.has_content?
535
+ false
536
+ end
537
+
538
+ # @return
539
+ # [u'reason = EMPTY_STRING']
540
+ def self.encode(reason)
541
+ channel = 0
542
+ buffer = @packed_indexes.dup
543
+ buffer << reason.to_s.bytesize.chr
544
+ buffer << reason.to_s
545
+ MethodFrame.new(buffer, channel)
546
+ end
547
+
548
+ end
549
+
550
+ class Unblocked < Protocol::Method
551
+ @name = "connection.unblocked"
552
+ @method_id = 61
553
+ @index = 0x000A003D # 10, 61, 655421
554
+ @packed_indexes = [10, 61].pack(PACK_UINT16_X2).freeze
555
+
556
+ # @return
557
+ def self.decode(data)
558
+ offset = 0
559
+ self.new()
560
+ end
561
+
562
+ def initialize()
563
+ end
564
+
565
+ def self.has_content?
566
+ false
567
+ end
568
+
569
+ # @return
570
+ # []
571
+ def self.encode()
572
+ channel = 0
573
+ buffer = @packed_indexes.dup
574
+ MethodFrame.new(buffer, channel)
575
+ end
576
+
577
+ end
578
+
579
+ end
580
+
581
+ class Channel < Protocol::Class
582
+ @name = "channel"
583
+ @method_id = 20
584
+
585
+
586
+
587
+ class Open < Protocol::Method
588
+ @name = "channel.open"
589
+ @method_id = 10
590
+ @index = 0x0014000A # 20, 10, 1310730
591
+ @packed_indexes = [20, 10].pack(PACK_UINT16_X2).freeze
592
+
593
+
594
+ def self.has_content?
595
+ false
596
+ end
597
+
598
+ # @return
599
+ # [u'out_of_band = EMPTY_STRING']
600
+ def self.encode(channel, out_of_band)
601
+ buffer = @packed_indexes.dup
602
+ buffer << out_of_band.to_s.bytesize.chr
603
+ buffer << out_of_band.to_s
604
+ MethodFrame.new(buffer, channel)
605
+ end
606
+
607
+ end
608
+
609
+ class OpenOk < Protocol::Method
610
+ @name = "channel.open-ok"
611
+ @method_id = 11
612
+ @index = 0x0014000B # 20, 11, 1310731
613
+ @packed_indexes = [20, 11].pack(PACK_UINT16_X2).freeze
614
+
615
+ # @return
616
+ def self.decode(data)
617
+ offset = 0
618
+ length = data[offset, 4].unpack(PACK_UINT32).first
619
+ offset += 4
620
+ channel_id = data[offset, length]
621
+ offset += length
622
+ self.new(channel_id)
623
+ end
624
+
625
+ attr_reader :channel_id
626
+ def initialize(channel_id)
627
+ @channel_id = channel_id
628
+ end
629
+
630
+ def self.has_content?
631
+ false
632
+ end
633
+
634
+
635
+ end
636
+
637
+ class Flow < Protocol::Method
638
+ @name = "channel.flow"
639
+ @method_id = 20
640
+ @index = 0x00140014 # 20, 20, 1310740
641
+ @packed_indexes = [20, 20].pack(PACK_UINT16_X2).freeze
642
+
643
+ # @return
644
+ def self.decode(data)
645
+ offset = 0
646
+ bit_buffer = data[offset, 1].unpack(PACK_CHAR).first
647
+ offset += 1
648
+ active = (bit_buffer & (1 << 0)) != 0
649
+ self.new(active)
650
+ end
651
+
652
+ attr_reader :active
653
+ def initialize(active)
654
+ @active = active
655
+ end
656
+
657
+ def self.has_content?
658
+ false
659
+ end
660
+
661
+ # @return
662
+ # [u'active = nil']
663
+ def self.encode(channel, active)
664
+ buffer = @packed_indexes.dup
665
+ bit_buffer = 0
666
+ bit_buffer = bit_buffer | (1 << 0) if active
667
+ buffer << [bit_buffer].pack(PACK_CHAR)
668
+ MethodFrame.new(buffer, channel)
669
+ end
670
+
671
+ end
672
+
673
+ class FlowOk < Protocol::Method
674
+ @name = "channel.flow-ok"
675
+ @method_id = 21
676
+ @index = 0x00140015 # 20, 21, 1310741
677
+ @packed_indexes = [20, 21].pack(PACK_UINT16_X2).freeze
678
+
679
+ # @return
680
+ def self.decode(data)
681
+ offset = 0
682
+ bit_buffer = data[offset, 1].unpack(PACK_CHAR).first
683
+ offset += 1
684
+ active = (bit_buffer & (1 << 0)) != 0
685
+ self.new(active)
686
+ end
687
+
688
+ attr_reader :active
689
+ def initialize(active)
690
+ @active = active
691
+ end
692
+
693
+ def self.has_content?
694
+ false
695
+ end
696
+
697
+ # @return
698
+ # [u'active = nil']
699
+ def self.encode(channel, active)
700
+ buffer = @packed_indexes.dup
701
+ bit_buffer = 0
702
+ bit_buffer = bit_buffer | (1 << 0) if active
703
+ buffer << [bit_buffer].pack(PACK_CHAR)
704
+ MethodFrame.new(buffer, channel)
705
+ end
706
+
707
+ end
708
+
709
+ class Close < Protocol::Method
710
+ @name = "channel.close"
711
+ @method_id = 40
712
+ @index = 0x00140028 # 20, 40, 1310760
713
+ @packed_indexes = [20, 40].pack(PACK_UINT16_X2).freeze
714
+
715
+ # @return
716
+ def self.decode(data)
717
+ offset = 0
718
+ reply_code = data[offset, 2].unpack(PACK_UINT16).first
719
+ offset += 2
720
+ length = data[offset, 1].unpack(PACK_CHAR).first
721
+ offset += 1
722
+ reply_text = data[offset, length]
723
+ offset += length
724
+ class_id = data[offset, 2].unpack(PACK_UINT16).first
725
+ offset += 2
726
+ method_id = data[offset, 2].unpack(PACK_UINT16).first
727
+ offset += 2
728
+ self.new(reply_code, reply_text, class_id, method_id)
729
+ end
730
+
731
+ attr_reader :reply_code, :reply_text, :class_id, :method_id
732
+ def initialize(reply_code, reply_text, class_id, method_id)
733
+ @reply_code = reply_code
734
+ @reply_text = reply_text
735
+ @class_id = class_id
736
+ @method_id = method_id
737
+ end
738
+
739
+ def self.has_content?
740
+ false
741
+ end
742
+
743
+ # @return
744
+ # [u'reply_code = nil', u'reply_text = EMPTY_STRING', u'class_id = nil', u'method_id = nil']
745
+ def self.encode(channel, reply_code, reply_text, class_id, method_id)
746
+ buffer = @packed_indexes.dup
747
+ buffer << [reply_code].pack(PACK_UINT16)
748
+ buffer << reply_text.to_s.bytesize.chr
749
+ buffer << reply_text.to_s
750
+ buffer << [class_id].pack(PACK_UINT16)
751
+ buffer << [method_id].pack(PACK_UINT16)
752
+ MethodFrame.new(buffer, channel)
753
+ end
754
+
755
+ end
756
+
757
+ class CloseOk < Protocol::Method
758
+ @name = "channel.close-ok"
759
+ @method_id = 41
760
+ @index = 0x00140029 # 20, 41, 1310761
761
+ @packed_indexes = [20, 41].pack(PACK_UINT16_X2).freeze
762
+
763
+ # @return
764
+ def self.decode(data)
765
+ offset = 0
766
+ self.new()
767
+ end
768
+
769
+ def initialize()
770
+ end
771
+
772
+ def self.has_content?
773
+ false
774
+ end
775
+
776
+ # @return
777
+ # []
778
+ def self.encode(channel)
779
+ buffer = @packed_indexes.dup
780
+ MethodFrame.new(buffer, channel)
781
+ end
782
+
783
+ end
784
+
785
+ end
786
+
787
+ class Exchange < Protocol::Class
788
+ @name = "exchange"
789
+ @method_id = 40
790
+
791
+
792
+
793
+ class Declare < Protocol::Method
794
+ @name = "exchange.declare"
795
+ @method_id = 10
796
+ @index = 0x0028000A # 40, 10, 2621450
797
+ @packed_indexes = [40, 10].pack(PACK_UINT16_X2).freeze
798
+
799
+
800
+ def self.has_content?
801
+ false
802
+ end
803
+
804
+ # @return
805
+ # [u'ticket = 0', u'exchange = nil', u"type = u'direct'", u'passive = false', u'durable = false', u'auto_delete = false', u'internal = false', u'nowait = false', u'arguments = {}']
806
+ def self.encode(channel, exchange, type, passive, durable, auto_delete, internal, nowait, arguments)
807
+ ticket = 0
808
+ buffer = @packed_indexes.dup
809
+ buffer << [ticket].pack(PACK_UINT16)
810
+ buffer << exchange.to_s.bytesize.chr
811
+ buffer << exchange.to_s
812
+ buffer << type.to_s.bytesize.chr
813
+ buffer << type.to_s
814
+ bit_buffer = 0
815
+ bit_buffer = bit_buffer | (1 << 0) if passive
816
+ bit_buffer = bit_buffer | (1 << 1) if durable
817
+ bit_buffer = bit_buffer | (1 << 2) if auto_delete
818
+ bit_buffer = bit_buffer | (1 << 3) if internal
819
+ bit_buffer = bit_buffer | (1 << 4) if nowait
820
+ buffer << [bit_buffer].pack(PACK_CHAR)
821
+ buffer << GorgonAMQ::Protocol::Table.encode(arguments)
822
+ MethodFrame.new(buffer, channel)
823
+ end
824
+
825
+ end
826
+
827
+ class DeclareOk < Protocol::Method
828
+ @name = "exchange.declare-ok"
829
+ @method_id = 11
830
+ @index = 0x0028000B # 40, 11, 2621451
831
+ @packed_indexes = [40, 11].pack(PACK_UINT16_X2).freeze
832
+
833
+ # @return
834
+ def self.decode(data)
835
+ offset = 0
836
+ self.new()
837
+ end
838
+
839
+ def initialize()
840
+ end
841
+
842
+ def self.has_content?
843
+ false
844
+ end
845
+
846
+
847
+ end
848
+
849
+ class Delete < Protocol::Method
850
+ @name = "exchange.delete"
851
+ @method_id = 20
852
+ @index = 0x00280014 # 40, 20, 2621460
853
+ @packed_indexes = [40, 20].pack(PACK_UINT16_X2).freeze
854
+
855
+
856
+ def self.has_content?
857
+ false
858
+ end
859
+
860
+ # @return
861
+ # [u'ticket = 0', u'exchange = nil', u'if_unused = false', u'nowait = false']
862
+ def self.encode(channel, exchange, if_unused, nowait)
863
+ ticket = 0
864
+ buffer = @packed_indexes.dup
865
+ buffer << [ticket].pack(PACK_UINT16)
866
+ buffer << exchange.to_s.bytesize.chr
867
+ buffer << exchange.to_s
868
+ bit_buffer = 0
869
+ bit_buffer = bit_buffer | (1 << 0) if if_unused
870
+ bit_buffer = bit_buffer | (1 << 1) if nowait
871
+ buffer << [bit_buffer].pack(PACK_CHAR)
872
+ MethodFrame.new(buffer, channel)
873
+ end
874
+
875
+ end
876
+
877
+ class DeleteOk < Protocol::Method
878
+ @name = "exchange.delete-ok"
879
+ @method_id = 21
880
+ @index = 0x00280015 # 40, 21, 2621461
881
+ @packed_indexes = [40, 21].pack(PACK_UINT16_X2).freeze
882
+
883
+ # @return
884
+ def self.decode(data)
885
+ offset = 0
886
+ self.new()
887
+ end
888
+
889
+ def initialize()
890
+ end
891
+
892
+ def self.has_content?
893
+ false
894
+ end
895
+
896
+
897
+ end
898
+
899
+ class Bind < Protocol::Method
900
+ @name = "exchange.bind"
901
+ @method_id = 30
902
+ @index = 0x0028001E # 40, 30, 2621470
903
+ @packed_indexes = [40, 30].pack(PACK_UINT16_X2).freeze
904
+
905
+
906
+ def self.has_content?
907
+ false
908
+ end
909
+
910
+ # @return
911
+ # [u'ticket = 0', u'destination = nil', u'source = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}']
912
+ def self.encode(channel, destination, source, routing_key, nowait, arguments)
913
+ ticket = 0
914
+ buffer = @packed_indexes.dup
915
+ buffer << [ticket].pack(PACK_UINT16)
916
+ buffer << destination.to_s.bytesize.chr
917
+ buffer << destination.to_s
918
+ buffer << source.to_s.bytesize.chr
919
+ buffer << source.to_s
920
+ buffer << routing_key.to_s.bytesize.chr
921
+ buffer << routing_key.to_s
922
+ bit_buffer = 0
923
+ bit_buffer = bit_buffer | (1 << 0) if nowait
924
+ buffer << [bit_buffer].pack(PACK_CHAR)
925
+ buffer << GorgonAMQ::Protocol::Table.encode(arguments)
926
+ MethodFrame.new(buffer, channel)
927
+ end
928
+
929
+ end
930
+
931
+ class BindOk < Protocol::Method
932
+ @name = "exchange.bind-ok"
933
+ @method_id = 31
934
+ @index = 0x0028001F # 40, 31, 2621471
935
+ @packed_indexes = [40, 31].pack(PACK_UINT16_X2).freeze
936
+
937
+ # @return
938
+ def self.decode(data)
939
+ offset = 0
940
+ self.new()
941
+ end
942
+
943
+ def initialize()
944
+ end
945
+
946
+ def self.has_content?
947
+ false
948
+ end
949
+
950
+
951
+ end
952
+
953
+ class Unbind < Protocol::Method
954
+ @name = "exchange.unbind"
955
+ @method_id = 40
956
+ @index = 0x00280028 # 40, 40, 2621480
957
+ @packed_indexes = [40, 40].pack(PACK_UINT16_X2).freeze
958
+
959
+
960
+ def self.has_content?
961
+ false
962
+ end
963
+
964
+ # @return
965
+ # [u'ticket = 0', u'destination = nil', u'source = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}']
966
+ def self.encode(channel, destination, source, routing_key, nowait, arguments)
967
+ ticket = 0
968
+ buffer = @packed_indexes.dup
969
+ buffer << [ticket].pack(PACK_UINT16)
970
+ buffer << destination.to_s.bytesize.chr
971
+ buffer << destination.to_s
972
+ buffer << source.to_s.bytesize.chr
973
+ buffer << source.to_s
974
+ buffer << routing_key.to_s.bytesize.chr
975
+ buffer << routing_key.to_s
976
+ bit_buffer = 0
977
+ bit_buffer = bit_buffer | (1 << 0) if nowait
978
+ buffer << [bit_buffer].pack(PACK_CHAR)
979
+ buffer << GorgonAMQ::Protocol::Table.encode(arguments)
980
+ MethodFrame.new(buffer, channel)
981
+ end
982
+
983
+ end
984
+
985
+ class UnbindOk < Protocol::Method
986
+ @name = "exchange.unbind-ok"
987
+ @method_id = 51
988
+ @index = 0x00280033 # 40, 51, 2621491
989
+ @packed_indexes = [40, 51].pack(PACK_UINT16_X2).freeze
990
+
991
+ # @return
992
+ def self.decode(data)
993
+ offset = 0
994
+ self.new()
995
+ end
996
+
997
+ def initialize()
998
+ end
999
+
1000
+ def self.has_content?
1001
+ false
1002
+ end
1003
+
1004
+
1005
+ end
1006
+
1007
+ end
1008
+
1009
+ class Queue < Protocol::Class
1010
+ @name = "queue"
1011
+ @method_id = 50
1012
+
1013
+
1014
+
1015
+ class Declare < Protocol::Method
1016
+ @name = "queue.declare"
1017
+ @method_id = 10
1018
+ @index = 0x0032000A # 50, 10, 3276810
1019
+ @packed_indexes = [50, 10].pack(PACK_UINT16_X2).freeze
1020
+
1021
+
1022
+ def self.has_content?
1023
+ false
1024
+ end
1025
+
1026
+ # @return
1027
+ # [u'ticket = 0', u'queue = EMPTY_STRING', u'passive = false', u'durable = false', u'exclusive = false', u'auto_delete = false', u'nowait = false', u'arguments = {}']
1028
+ def self.encode(channel, queue, passive, durable, exclusive, auto_delete, nowait, arguments)
1029
+ ticket = 0
1030
+ buffer = @packed_indexes.dup
1031
+ buffer << [ticket].pack(PACK_UINT16)
1032
+ buffer << queue.to_s.bytesize.chr
1033
+ buffer << queue.to_s
1034
+ bit_buffer = 0
1035
+ bit_buffer = bit_buffer | (1 << 0) if passive
1036
+ bit_buffer = bit_buffer | (1 << 1) if durable
1037
+ bit_buffer = bit_buffer | (1 << 2) if exclusive
1038
+ bit_buffer = bit_buffer | (1 << 3) if auto_delete
1039
+ bit_buffer = bit_buffer | (1 << 4) if nowait
1040
+ buffer << [bit_buffer].pack(PACK_CHAR)
1041
+ buffer << GorgonAMQ::Protocol::Table.encode(arguments)
1042
+ MethodFrame.new(buffer, channel)
1043
+ end
1044
+
1045
+ end
1046
+
1047
+ class DeclareOk < Protocol::Method
1048
+ @name = "queue.declare-ok"
1049
+ @method_id = 11
1050
+ @index = 0x0032000B # 50, 11, 3276811
1051
+ @packed_indexes = [50, 11].pack(PACK_UINT16_X2).freeze
1052
+
1053
+ # @return
1054
+ def self.decode(data)
1055
+ offset = 0
1056
+ length = data[offset, 1].unpack(PACK_CHAR).first
1057
+ offset += 1
1058
+ queue = data[offset, length]
1059
+ offset += length
1060
+ message_count = data[offset, 4].unpack(PACK_UINT32).first
1061
+ offset += 4
1062
+ consumer_count = data[offset, 4].unpack(PACK_UINT32).first
1063
+ offset += 4
1064
+ self.new(queue, message_count, consumer_count)
1065
+ end
1066
+
1067
+ attr_reader :queue, :message_count, :consumer_count
1068
+ def initialize(queue, message_count, consumer_count)
1069
+ @queue = queue
1070
+ @message_count = message_count
1071
+ @consumer_count = consumer_count
1072
+ end
1073
+
1074
+ def self.has_content?
1075
+ false
1076
+ end
1077
+
1078
+
1079
+ end
1080
+
1081
+ class Bind < Protocol::Method
1082
+ @name = "queue.bind"
1083
+ @method_id = 20
1084
+ @index = 0x00320014 # 50, 20, 3276820
1085
+ @packed_indexes = [50, 20].pack(PACK_UINT16_X2).freeze
1086
+
1087
+
1088
+ def self.has_content?
1089
+ false
1090
+ end
1091
+
1092
+ # @return
1093
+ # [u'ticket = 0', u'queue = EMPTY_STRING', u'exchange = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}']
1094
+ def self.encode(channel, queue, exchange, routing_key, nowait, arguments)
1095
+ ticket = 0
1096
+ buffer = @packed_indexes.dup
1097
+ buffer << [ticket].pack(PACK_UINT16)
1098
+ buffer << queue.to_s.bytesize.chr
1099
+ buffer << queue.to_s
1100
+ buffer << exchange.to_s.bytesize.chr
1101
+ buffer << exchange.to_s
1102
+ buffer << routing_key.to_s.bytesize.chr
1103
+ buffer << routing_key.to_s
1104
+ bit_buffer = 0
1105
+ bit_buffer = bit_buffer | (1 << 0) if nowait
1106
+ buffer << [bit_buffer].pack(PACK_CHAR)
1107
+ buffer << GorgonAMQ::Protocol::Table.encode(arguments)
1108
+ MethodFrame.new(buffer, channel)
1109
+ end
1110
+
1111
+ end
1112
+
1113
+ class BindOk < Protocol::Method
1114
+ @name = "queue.bind-ok"
1115
+ @method_id = 21
1116
+ @index = 0x00320015 # 50, 21, 3276821
1117
+ @packed_indexes = [50, 21].pack(PACK_UINT16_X2).freeze
1118
+
1119
+ # @return
1120
+ def self.decode(data)
1121
+ offset = 0
1122
+ self.new()
1123
+ end
1124
+
1125
+ def initialize()
1126
+ end
1127
+
1128
+ def self.has_content?
1129
+ false
1130
+ end
1131
+
1132
+
1133
+ end
1134
+
1135
+ class Purge < Protocol::Method
1136
+ @name = "queue.purge"
1137
+ @method_id = 30
1138
+ @index = 0x0032001E # 50, 30, 3276830
1139
+ @packed_indexes = [50, 30].pack(PACK_UINT16_X2).freeze
1140
+
1141
+
1142
+ def self.has_content?
1143
+ false
1144
+ end
1145
+
1146
+ # @return
1147
+ # [u'ticket = 0', u'queue = EMPTY_STRING', u'nowait = false']
1148
+ def self.encode(channel, queue, nowait)
1149
+ ticket = 0
1150
+ buffer = @packed_indexes.dup
1151
+ buffer << [ticket].pack(PACK_UINT16)
1152
+ buffer << queue.to_s.bytesize.chr
1153
+ buffer << queue.to_s
1154
+ bit_buffer = 0
1155
+ bit_buffer = bit_buffer | (1 << 0) if nowait
1156
+ buffer << [bit_buffer].pack(PACK_CHAR)
1157
+ MethodFrame.new(buffer, channel)
1158
+ end
1159
+
1160
+ end
1161
+
1162
+ class PurgeOk < Protocol::Method
1163
+ @name = "queue.purge-ok"
1164
+ @method_id = 31
1165
+ @index = 0x0032001F # 50, 31, 3276831
1166
+ @packed_indexes = [50, 31].pack(PACK_UINT16_X2).freeze
1167
+
1168
+ # @return
1169
+ def self.decode(data)
1170
+ offset = 0
1171
+ message_count = data[offset, 4].unpack(PACK_UINT32).first
1172
+ offset += 4
1173
+ self.new(message_count)
1174
+ end
1175
+
1176
+ attr_reader :message_count
1177
+ def initialize(message_count)
1178
+ @message_count = message_count
1179
+ end
1180
+
1181
+ def self.has_content?
1182
+ false
1183
+ end
1184
+
1185
+
1186
+ end
1187
+
1188
+ class Delete < Protocol::Method
1189
+ @name = "queue.delete"
1190
+ @method_id = 40
1191
+ @index = 0x00320028 # 50, 40, 3276840
1192
+ @packed_indexes = [50, 40].pack(PACK_UINT16_X2).freeze
1193
+
1194
+
1195
+ def self.has_content?
1196
+ false
1197
+ end
1198
+
1199
+ # @return
1200
+ # [u'ticket = 0', u'queue = EMPTY_STRING', u'if_unused = false', u'if_empty = false', u'nowait = false']
1201
+ def self.encode(channel, queue, if_unused, if_empty, nowait)
1202
+ ticket = 0
1203
+ buffer = @packed_indexes.dup
1204
+ buffer << [ticket].pack(PACK_UINT16)
1205
+ buffer << queue.to_s.bytesize.chr
1206
+ buffer << queue.to_s
1207
+ bit_buffer = 0
1208
+ bit_buffer = bit_buffer | (1 << 0) if if_unused
1209
+ bit_buffer = bit_buffer | (1 << 1) if if_empty
1210
+ bit_buffer = bit_buffer | (1 << 2) if nowait
1211
+ buffer << [bit_buffer].pack(PACK_CHAR)
1212
+ MethodFrame.new(buffer, channel)
1213
+ end
1214
+
1215
+ end
1216
+
1217
+ class DeleteOk < Protocol::Method
1218
+ @name = "queue.delete-ok"
1219
+ @method_id = 41
1220
+ @index = 0x00320029 # 50, 41, 3276841
1221
+ @packed_indexes = [50, 41].pack(PACK_UINT16_X2).freeze
1222
+
1223
+ # @return
1224
+ def self.decode(data)
1225
+ offset = 0
1226
+ message_count = data[offset, 4].unpack(PACK_UINT32).first
1227
+ offset += 4
1228
+ self.new(message_count)
1229
+ end
1230
+
1231
+ attr_reader :message_count
1232
+ def initialize(message_count)
1233
+ @message_count = message_count
1234
+ end
1235
+
1236
+ def self.has_content?
1237
+ false
1238
+ end
1239
+
1240
+
1241
+ end
1242
+
1243
+ class Unbind < Protocol::Method
1244
+ @name = "queue.unbind"
1245
+ @method_id = 50
1246
+ @index = 0x00320032 # 50, 50, 3276850
1247
+ @packed_indexes = [50, 50].pack(PACK_UINT16_X2).freeze
1248
+
1249
+
1250
+ def self.has_content?
1251
+ false
1252
+ end
1253
+
1254
+ # @return
1255
+ # [u'ticket = 0', u'queue = EMPTY_STRING', u'exchange = nil', u'routing_key = EMPTY_STRING', u'arguments = {}']
1256
+ def self.encode(channel, queue, exchange, routing_key, arguments)
1257
+ ticket = 0
1258
+ buffer = @packed_indexes.dup
1259
+ buffer << [ticket].pack(PACK_UINT16)
1260
+ buffer << queue.to_s.bytesize.chr
1261
+ buffer << queue.to_s
1262
+ buffer << exchange.to_s.bytesize.chr
1263
+ buffer << exchange.to_s
1264
+ buffer << routing_key.to_s.bytesize.chr
1265
+ buffer << routing_key.to_s
1266
+ buffer << GorgonAMQ::Protocol::Table.encode(arguments)
1267
+ MethodFrame.new(buffer, channel)
1268
+ end
1269
+
1270
+ end
1271
+
1272
+ class UnbindOk < Protocol::Method
1273
+ @name = "queue.unbind-ok"
1274
+ @method_id = 51
1275
+ @index = 0x00320033 # 50, 51, 3276851
1276
+ @packed_indexes = [50, 51].pack(PACK_UINT16_X2).freeze
1277
+
1278
+ # @return
1279
+ def self.decode(data)
1280
+ offset = 0
1281
+ self.new()
1282
+ end
1283
+
1284
+ def initialize()
1285
+ end
1286
+
1287
+ def self.has_content?
1288
+ false
1289
+ end
1290
+
1291
+
1292
+ end
1293
+
1294
+ end
1295
+
1296
+ class Basic < Protocol::Class
1297
+ @name = "basic"
1298
+ @method_id = 60
1299
+
1300
+ PROPERTIES = [
1301
+ :content_type, # shortstr
1302
+ :content_encoding, # shortstr
1303
+ :headers, # table
1304
+ :delivery_mode, # octet
1305
+ :priority, # octet
1306
+ :correlation_id, # shortstr
1307
+ :reply_to, # shortstr
1308
+ :expiration, # shortstr
1309
+ :message_id, # shortstr
1310
+ :timestamp, # timestamp
1311
+ :type, # shortstr
1312
+ :user_id, # shortstr
1313
+ :app_id, # shortstr
1314
+ :cluster_id, # shortstr
1315
+ ]
1316
+
1317
+ # 1 << 15
1318
+ def self.encode_content_type(value)
1319
+ buffer = ''
1320
+ buffer << value.to_s.bytesize.chr
1321
+ buffer << value.to_s
1322
+ [0, 0x8000, buffer]
1323
+ end
1324
+
1325
+ # 1 << 14
1326
+ def self.encode_content_encoding(value)
1327
+ buffer = ''
1328
+ buffer << value.to_s.bytesize.chr
1329
+ buffer << value.to_s
1330
+ [1, 0x4000, buffer]
1331
+ end
1332
+
1333
+ # 1 << 13
1334
+ def self.encode_headers(value)
1335
+ buffer = ''
1336
+ buffer << GorgonAMQ::Protocol::Table.encode(value)
1337
+ [2, 0x2000, buffer]
1338
+ end
1339
+
1340
+ # 1 << 12
1341
+ def self.encode_delivery_mode(value)
1342
+ buffer = ''
1343
+ buffer << [value].pack(PACK_CHAR)
1344
+ [3, 0x1000, buffer]
1345
+ end
1346
+
1347
+ # 1 << 11
1348
+ def self.encode_priority(value)
1349
+ buffer = ''
1350
+ buffer << [value].pack(PACK_CHAR)
1351
+ [4, 0x0800, buffer]
1352
+ end
1353
+
1354
+ # 1 << 10
1355
+ def self.encode_correlation_id(value)
1356
+ buffer = ''
1357
+ buffer << value.to_s.bytesize.chr
1358
+ buffer << value.to_s
1359
+ [5, 0x0400, buffer]
1360
+ end
1361
+
1362
+ # 1 << 9
1363
+ def self.encode_reply_to(value)
1364
+ buffer = ''
1365
+ buffer << value.to_s.bytesize.chr
1366
+ buffer << value.to_s
1367
+ [6, 0x0200, buffer]
1368
+ end
1369
+
1370
+ # 1 << 8
1371
+ def self.encode_expiration(value)
1372
+ buffer = ''
1373
+ buffer << value.to_s.bytesize.chr
1374
+ buffer << value.to_s
1375
+ [7, 0x0100, buffer]
1376
+ end
1377
+
1378
+ # 1 << 7
1379
+ def self.encode_message_id(value)
1380
+ buffer = ''
1381
+ buffer << value.to_s.bytesize.chr
1382
+ buffer << value.to_s
1383
+ [8, 0x0080, buffer]
1384
+ end
1385
+
1386
+ # 1 << 6
1387
+ def self.encode_timestamp(value)
1388
+ buffer = ''
1389
+ buffer << GorgonAMQ::Pack.pack_uint64_big_endian(value)
1390
+ [9, 0x0040, buffer]
1391
+ end
1392
+
1393
+ # 1 << 5
1394
+ def self.encode_type(value)
1395
+ buffer = ''
1396
+ buffer << value.to_s.bytesize.chr
1397
+ buffer << value.to_s
1398
+ [10, 0x0020, buffer]
1399
+ end
1400
+
1401
+ # 1 << 4
1402
+ def self.encode_user_id(value)
1403
+ buffer = ''
1404
+ buffer << value.to_s.bytesize.chr
1405
+ buffer << value.to_s
1406
+ [11, 0x0010, buffer]
1407
+ end
1408
+
1409
+ # 1 << 3
1410
+ def self.encode_app_id(value)
1411
+ buffer = ''
1412
+ buffer << value.to_s.bytesize.chr
1413
+ buffer << value.to_s
1414
+ [12, 0x0008, buffer]
1415
+ end
1416
+
1417
+ # 1 << 2
1418
+ def self.encode_cluster_id(value)
1419
+ buffer = ''
1420
+ buffer << value.to_s.bytesize.chr
1421
+ buffer << value.to_s
1422
+ [13, 0x0004, buffer]
1423
+ end
1424
+
1425
+
1426
+
1427
+ def self.encode_properties(body_size, properties)
1428
+ pieces, flags = [], 0
1429
+
1430
+ properties.reject {|key, value| value.nil?}.each do |key, value|
1431
+ i, f, result = self.__send__(:"encode_#{key}", value)
1432
+ flags |= f
1433
+ pieces[i] = result
1434
+ end
1435
+
1436
+ # result = [60, 0, body_size, flags].pack('n2Qn')
1437
+ result = [60, 0].pack(PACK_UINT16_X2)
1438
+ result += GorgonAMQ::Pack.pack_uint64_big_endian(body_size)
1439
+ result += [flags].pack(PACK_UINT16)
1440
+ result + pieces.join(EMPTY_STRING)
1441
+ end
1442
+
1443
+ # THIS DECODES ONLY FLAGS
1444
+ DECODE_PROPERTIES = {
1445
+ 0x8000 => :content_type,
1446
+ 0x4000 => :content_encoding,
1447
+ 0x2000 => :headers,
1448
+ 0x1000 => :delivery_mode,
1449
+ 0x0800 => :priority,
1450
+ 0x0400 => :correlation_id,
1451
+ 0x0200 => :reply_to,
1452
+ 0x0100 => :expiration,
1453
+ 0x0080 => :message_id,
1454
+ 0x0040 => :timestamp,
1455
+ 0x0020 => :type,
1456
+ 0x0010 => :user_id,
1457
+ 0x0008 => :app_id,
1458
+ 0x0004 => :cluster_id,
1459
+ }
1460
+
1461
+ DECODE_PROPERTIES_TYPE = {
1462
+ 0x8000 => :shortstr,
1463
+ 0x4000 => :shortstr,
1464
+ 0x2000 => :table,
1465
+ 0x1000 => :octet,
1466
+ 0x0800 => :octet,
1467
+ 0x0400 => :shortstr,
1468
+ 0x0200 => :shortstr,
1469
+ 0x0100 => :shortstr,
1470
+ 0x0080 => :shortstr,
1471
+ 0x0040 => :timestamp,
1472
+ 0x0020 => :shortstr,
1473
+ 0x0010 => :shortstr,
1474
+ 0x0008 => :shortstr,
1475
+ 0x0004 => :shortstr,
1476
+ }
1477
+
1478
+ # Hash doesn't give any guarantees on keys order, we will do it in a
1479
+ # straightforward way
1480
+ DECODE_PROPERTIES_KEYS = [
1481
+ 0x8000,
1482
+ 0x4000,
1483
+ 0x2000,
1484
+ 0x1000,
1485
+ 0x0800,
1486
+ 0x0400,
1487
+ 0x0200,
1488
+ 0x0100,
1489
+ 0x0080,
1490
+ 0x0040,
1491
+ 0x0020,
1492
+ 0x0010,
1493
+ 0x0008,
1494
+ 0x0004,
1495
+ ]
1496
+
1497
+ def self.decode_properties(data)
1498
+ offset, data_length, properties = 0, data.bytesize, {}
1499
+
1500
+ compressed_index = data[offset, 2].unpack(PACK_UINT16)[0]
1501
+ offset += 2
1502
+ while data_length > offset
1503
+ DECODE_PROPERTIES_KEYS.each do |key|
1504
+ next unless compressed_index >= key
1505
+ compressed_index -= key
1506
+ name = DECODE_PROPERTIES[key] || raise(RuntimeError.new("No property found for index #{index.inspect}!"))
1507
+ case DECODE_PROPERTIES_TYPE[key]
1508
+ when :shortstr
1509
+ size = data[offset, 1].unpack(PACK_CHAR)[0]
1510
+ offset += 1
1511
+ result = data[offset, size]
1512
+ when :octet
1513
+ size = 1
1514
+ result = data[offset, size].unpack(PACK_CHAR).first
1515
+ when :timestamp
1516
+ size = 8
1517
+ result = Time.at(data[offset, size].unpack(PACK_UINT32_X2).last)
1518
+ when :table
1519
+ size = 4 + data[offset, 4].unpack(PACK_UINT32)[0]
1520
+ result = Table.decode(data[offset, size])
1521
+ end
1522
+ properties[name] = result
1523
+ offset += size
1524
+ end
1525
+ end
1526
+
1527
+ properties
1528
+ end
1529
+
1530
+ class Qos < Protocol::Method
1531
+ @name = "basic.qos"
1532
+ @method_id = 10
1533
+ @index = 0x003C000A # 60, 10, 3932170
1534
+ @packed_indexes = [60, 10].pack(PACK_UINT16_X2).freeze
1535
+
1536
+
1537
+ def self.has_content?
1538
+ false
1539
+ end
1540
+
1541
+ # @return
1542
+ # [u'prefetch_size = false', u'prefetch_count = false', u'global = false']
1543
+ def self.encode(channel, prefetch_size, prefetch_count, global)
1544
+ buffer = @packed_indexes.dup
1545
+ buffer << [prefetch_size].pack(PACK_UINT32)
1546
+ buffer << [prefetch_count].pack(PACK_UINT16)
1547
+ bit_buffer = 0
1548
+ bit_buffer = bit_buffer | (1 << 0) if global
1549
+ buffer << [bit_buffer].pack(PACK_CHAR)
1550
+ MethodFrame.new(buffer, channel)
1551
+ end
1552
+
1553
+ end
1554
+
1555
+ class QosOk < Protocol::Method
1556
+ @name = "basic.qos-ok"
1557
+ @method_id = 11
1558
+ @index = 0x003C000B # 60, 11, 3932171
1559
+ @packed_indexes = [60, 11].pack(PACK_UINT16_X2).freeze
1560
+
1561
+ # @return
1562
+ def self.decode(data)
1563
+ offset = 0
1564
+ self.new()
1565
+ end
1566
+
1567
+ def initialize()
1568
+ end
1569
+
1570
+ def self.has_content?
1571
+ false
1572
+ end
1573
+
1574
+
1575
+ end
1576
+
1577
+ class Consume < Protocol::Method
1578
+ @name = "basic.consume"
1579
+ @method_id = 20
1580
+ @index = 0x003C0014 # 60, 20, 3932180
1581
+ @packed_indexes = [60, 20].pack(PACK_UINT16_X2).freeze
1582
+
1583
+
1584
+ def self.has_content?
1585
+ false
1586
+ end
1587
+
1588
+ # @return
1589
+ # [u'ticket = 0', u'queue = EMPTY_STRING', u'consumer_tag = EMPTY_STRING', u'no_local = false', u'no_ack = false', u'exclusive = false', u'nowait = false', u'arguments = {}']
1590
+ def self.encode(channel, queue, consumer_tag, no_local, no_ack, exclusive, nowait, arguments)
1591
+ ticket = 0
1592
+ buffer = @packed_indexes.dup
1593
+ buffer << [ticket].pack(PACK_UINT16)
1594
+ buffer << queue.to_s.bytesize.chr
1595
+ buffer << queue.to_s
1596
+ buffer << consumer_tag.to_s.bytesize.chr
1597
+ buffer << consumer_tag.to_s
1598
+ bit_buffer = 0
1599
+ bit_buffer = bit_buffer | (1 << 0) if no_local
1600
+ bit_buffer = bit_buffer | (1 << 1) if no_ack
1601
+ bit_buffer = bit_buffer | (1 << 2) if exclusive
1602
+ bit_buffer = bit_buffer | (1 << 3) if nowait
1603
+ buffer << [bit_buffer].pack(PACK_CHAR)
1604
+ buffer << GorgonAMQ::Protocol::Table.encode(arguments)
1605
+ MethodFrame.new(buffer, channel)
1606
+ end
1607
+
1608
+ end
1609
+
1610
+ class ConsumeOk < Protocol::Method
1611
+ @name = "basic.consume-ok"
1612
+ @method_id = 21
1613
+ @index = 0x003C0015 # 60, 21, 3932181
1614
+ @packed_indexes = [60, 21].pack(PACK_UINT16_X2).freeze
1615
+
1616
+ # @return
1617
+ def self.decode(data)
1618
+ offset = 0
1619
+ length = data[offset, 1].unpack(PACK_CHAR).first
1620
+ offset += 1
1621
+ consumer_tag = data[offset, length]
1622
+ offset += length
1623
+ self.new(consumer_tag)
1624
+ end
1625
+
1626
+ attr_reader :consumer_tag
1627
+ def initialize(consumer_tag)
1628
+ @consumer_tag = consumer_tag
1629
+ end
1630
+
1631
+ def self.has_content?
1632
+ false
1633
+ end
1634
+
1635
+
1636
+ end
1637
+
1638
+ class Cancel < Protocol::Method
1639
+ @name = "basic.cancel"
1640
+ @method_id = 30
1641
+ @index = 0x003C001E # 60, 30, 3932190
1642
+ @packed_indexes = [60, 30].pack(PACK_UINT16_X2).freeze
1643
+
1644
+ # @return
1645
+ def self.decode(data)
1646
+ offset = 0
1647
+ length = data[offset, 1].unpack(PACK_CHAR).first
1648
+ offset += 1
1649
+ consumer_tag = data[offset, length]
1650
+ offset += length
1651
+ bit_buffer = data[offset, 1].unpack(PACK_CHAR).first
1652
+ offset += 1
1653
+ nowait = (bit_buffer & (1 << 0)) != 0
1654
+ self.new(consumer_tag, nowait)
1655
+ end
1656
+
1657
+ attr_reader :consumer_tag, :nowait
1658
+ def initialize(consumer_tag, nowait)
1659
+ @consumer_tag = consumer_tag
1660
+ @nowait = nowait
1661
+ end
1662
+
1663
+ def self.has_content?
1664
+ false
1665
+ end
1666
+
1667
+ # @return
1668
+ # [u'consumer_tag = nil', u'nowait = false']
1669
+ def self.encode(channel, consumer_tag, nowait)
1670
+ buffer = @packed_indexes.dup
1671
+ buffer << consumer_tag.to_s.bytesize.chr
1672
+ buffer << consumer_tag.to_s
1673
+ bit_buffer = 0
1674
+ bit_buffer = bit_buffer | (1 << 0) if nowait
1675
+ buffer << [bit_buffer].pack(PACK_CHAR)
1676
+ MethodFrame.new(buffer, channel)
1677
+ end
1678
+
1679
+ end
1680
+
1681
+ class CancelOk < Protocol::Method
1682
+ @name = "basic.cancel-ok"
1683
+ @method_id = 31
1684
+ @index = 0x003C001F # 60, 31, 3932191
1685
+ @packed_indexes = [60, 31].pack(PACK_UINT16_X2).freeze
1686
+
1687
+ # @return
1688
+ def self.decode(data)
1689
+ offset = 0
1690
+ length = data[offset, 1].unpack(PACK_CHAR).first
1691
+ offset += 1
1692
+ consumer_tag = data[offset, length]
1693
+ offset += length
1694
+ self.new(consumer_tag)
1695
+ end
1696
+
1697
+ attr_reader :consumer_tag
1698
+ def initialize(consumer_tag)
1699
+ @consumer_tag = consumer_tag
1700
+ end
1701
+
1702
+ def self.has_content?
1703
+ false
1704
+ end
1705
+
1706
+
1707
+ end
1708
+
1709
+ class Publish < Protocol::Method
1710
+ @name = "basic.publish"
1711
+ @method_id = 40
1712
+ @index = 0x003C0028 # 60, 40, 3932200
1713
+ @packed_indexes = [60, 40].pack(PACK_UINT16_X2).freeze
1714
+
1715
+
1716
+ def self.has_content?
1717
+ true
1718
+ end
1719
+
1720
+ # @return
1721
+ # [u'ticket = 0', u'exchange = EMPTY_STRING', u'routing_key = EMPTY_STRING', u'mandatory = false', u'immediate = false', 'user_headers = nil', 'payload = ""', 'frame_size = nil']
1722
+ def self.encode(channel, payload, user_headers, exchange, routing_key, mandatory, immediate, frame_size)
1723
+ ticket = 0
1724
+ buffer = @packed_indexes.dup
1725
+ buffer << [ticket].pack(PACK_UINT16)
1726
+ buffer << exchange.to_s.bytesize.chr
1727
+ buffer << exchange.to_s
1728
+ buffer << routing_key.to_s.bytesize.chr
1729
+ buffer << routing_key.to_s
1730
+ bit_buffer = 0
1731
+ bit_buffer = bit_buffer | (1 << 0) if mandatory
1732
+ bit_buffer = bit_buffer | (1 << 1) if immediate
1733
+ buffer << [bit_buffer].pack(PACK_CHAR)
1734
+ frames = [MethodFrame.new(buffer, channel)]
1735
+ properties, headers = self.split_headers(user_headers)
1736
+ if properties.nil? or properties.empty?
1737
+ raise RuntimeError.new("Properties can not be empty!")
1738
+ end
1739
+ properties_payload = Basic.encode_properties(payload.bytesize, properties)
1740
+ frames << HeaderFrame.new(properties_payload, channel)
1741
+ frames += self.encode_body(payload, channel, frame_size)
1742
+ frames
1743
+ end
1744
+
1745
+ end
1746
+
1747
+ class Return < Protocol::Method
1748
+ @name = "basic.return"
1749
+ @method_id = 50
1750
+ @index = 0x003C0032 # 60, 50, 3932210
1751
+ @packed_indexes = [60, 50].pack(PACK_UINT16_X2).freeze
1752
+
1753
+ # @return
1754
+ def self.decode(data)
1755
+ offset = 0
1756
+ reply_code = data[offset, 2].unpack(PACK_UINT16).first
1757
+ offset += 2
1758
+ length = data[offset, 1].unpack(PACK_CHAR).first
1759
+ offset += 1
1760
+ reply_text = data[offset, length]
1761
+ offset += length
1762
+ length = data[offset, 1].unpack(PACK_CHAR).first
1763
+ offset += 1
1764
+ exchange = data[offset, length]
1765
+ offset += length
1766
+ length = data[offset, 1].unpack(PACK_CHAR).first
1767
+ offset += 1
1768
+ routing_key = data[offset, length]
1769
+ offset += length
1770
+ self.new(reply_code, reply_text, exchange, routing_key)
1771
+ end
1772
+
1773
+ attr_reader :reply_code, :reply_text, :exchange, :routing_key
1774
+ def initialize(reply_code, reply_text, exchange, routing_key)
1775
+ @reply_code = reply_code
1776
+ @reply_text = reply_text
1777
+ @exchange = exchange
1778
+ @routing_key = routing_key
1779
+ end
1780
+
1781
+ def self.has_content?
1782
+ true
1783
+ end
1784
+
1785
+
1786
+ end
1787
+
1788
+ class Deliver < Protocol::Method
1789
+ @name = "basic.deliver"
1790
+ @method_id = 60
1791
+ @index = 0x003C003C # 60, 60, 3932220
1792
+ @packed_indexes = [60, 60].pack(PACK_UINT16_X2).freeze
1793
+
1794
+ # @return
1795
+ def self.decode(data)
1796
+ offset = 0
1797
+ length = data[offset, 1].unpack(PACK_CHAR).first
1798
+ offset += 1
1799
+ consumer_tag = data[offset, length]
1800
+ offset += length
1801
+ delivery_tag = GorgonAMQ::Pack.unpack_uint64_big_endian(data[offset, 8]).first
1802
+ offset += 8
1803
+ bit_buffer = data[offset, 1].unpack(PACK_CHAR).first
1804
+ offset += 1
1805
+ redelivered = (bit_buffer & (1 << 0)) != 0
1806
+ length = data[offset, 1].unpack(PACK_CHAR).first
1807
+ offset += 1
1808
+ exchange = data[offset, length]
1809
+ offset += length
1810
+ length = data[offset, 1].unpack(PACK_CHAR).first
1811
+ offset += 1
1812
+ routing_key = data[offset, length]
1813
+ offset += length
1814
+ self.new(consumer_tag, delivery_tag, redelivered, exchange, routing_key)
1815
+ end
1816
+
1817
+ attr_reader :consumer_tag, :delivery_tag, :redelivered, :exchange, :routing_key
1818
+ def initialize(consumer_tag, delivery_tag, redelivered, exchange, routing_key)
1819
+ @consumer_tag = consumer_tag
1820
+ @delivery_tag = delivery_tag
1821
+ @redelivered = redelivered
1822
+ @exchange = exchange
1823
+ @routing_key = routing_key
1824
+ end
1825
+
1826
+ def self.has_content?
1827
+ true
1828
+ end
1829
+
1830
+
1831
+ end
1832
+
1833
+ class Get < Protocol::Method
1834
+ @name = "basic.get"
1835
+ @method_id = 70
1836
+ @index = 0x003C0046 # 60, 70, 3932230
1837
+ @packed_indexes = [60, 70].pack(PACK_UINT16_X2).freeze
1838
+
1839
+
1840
+ def self.has_content?
1841
+ false
1842
+ end
1843
+
1844
+ # @return
1845
+ # [u'ticket = 0', u'queue = EMPTY_STRING', u'no_ack = false']
1846
+ def self.encode(channel, queue, no_ack)
1847
+ ticket = 0
1848
+ buffer = @packed_indexes.dup
1849
+ buffer << [ticket].pack(PACK_UINT16)
1850
+ buffer << queue.to_s.bytesize.chr
1851
+ buffer << queue.to_s
1852
+ bit_buffer = 0
1853
+ bit_buffer = bit_buffer | (1 << 0) if no_ack
1854
+ buffer << [bit_buffer].pack(PACK_CHAR)
1855
+ MethodFrame.new(buffer, channel)
1856
+ end
1857
+
1858
+ end
1859
+
1860
+ class GetOk < Protocol::Method
1861
+ @name = "basic.get-ok"
1862
+ @method_id = 71
1863
+ @index = 0x003C0047 # 60, 71, 3932231
1864
+ @packed_indexes = [60, 71].pack(PACK_UINT16_X2).freeze
1865
+
1866
+ # @return
1867
+ def self.decode(data)
1868
+ offset = 0
1869
+ delivery_tag = GorgonAMQ::Pack.unpack_uint64_big_endian(data[offset, 8]).first
1870
+ offset += 8
1871
+ bit_buffer = data[offset, 1].unpack(PACK_CHAR).first
1872
+ offset += 1
1873
+ redelivered = (bit_buffer & (1 << 0)) != 0
1874
+ length = data[offset, 1].unpack(PACK_CHAR).first
1875
+ offset += 1
1876
+ exchange = data[offset, length]
1877
+ offset += length
1878
+ length = data[offset, 1].unpack(PACK_CHAR).first
1879
+ offset += 1
1880
+ routing_key = data[offset, length]
1881
+ offset += length
1882
+ message_count = data[offset, 4].unpack(PACK_UINT32).first
1883
+ offset += 4
1884
+ self.new(delivery_tag, redelivered, exchange, routing_key, message_count)
1885
+ end
1886
+
1887
+ attr_reader :delivery_tag, :redelivered, :exchange, :routing_key, :message_count
1888
+ def initialize(delivery_tag, redelivered, exchange, routing_key, message_count)
1889
+ @delivery_tag = delivery_tag
1890
+ @redelivered = redelivered
1891
+ @exchange = exchange
1892
+ @routing_key = routing_key
1893
+ @message_count = message_count
1894
+ end
1895
+
1896
+ def self.has_content?
1897
+ true
1898
+ end
1899
+
1900
+
1901
+ end
1902
+
1903
+ class GetEmpty < Protocol::Method
1904
+ @name = "basic.get-empty"
1905
+ @method_id = 72
1906
+ @index = 0x003C0048 # 60, 72, 3932232
1907
+ @packed_indexes = [60, 72].pack(PACK_UINT16_X2).freeze
1908
+
1909
+ # @return
1910
+ def self.decode(data)
1911
+ offset = 0
1912
+ length = data[offset, 1].unpack(PACK_CHAR).first
1913
+ offset += 1
1914
+ cluster_id = data[offset, length]
1915
+ offset += length
1916
+ self.new(cluster_id)
1917
+ end
1918
+
1919
+ attr_reader :cluster_id
1920
+ def initialize(cluster_id)
1921
+ @cluster_id = cluster_id
1922
+ end
1923
+
1924
+ def self.has_content?
1925
+ false
1926
+ end
1927
+
1928
+
1929
+ end
1930
+
1931
+ class Ack < Protocol::Method
1932
+ @name = "basic.ack"
1933
+ @method_id = 80
1934
+ @index = 0x003C0050 # 60, 80, 3932240
1935
+ @packed_indexes = [60, 80].pack(PACK_UINT16_X2).freeze
1936
+
1937
+ # @return
1938
+ def self.decode(data)
1939
+ offset = 0
1940
+ delivery_tag = GorgonAMQ::Pack.unpack_uint64_big_endian(data[offset, 8]).first
1941
+ offset += 8
1942
+ bit_buffer = data[offset, 1].unpack(PACK_CHAR).first
1943
+ offset += 1
1944
+ multiple = (bit_buffer & (1 << 0)) != 0
1945
+ self.new(delivery_tag, multiple)
1946
+ end
1947
+
1948
+ attr_reader :delivery_tag, :multiple
1949
+ def initialize(delivery_tag, multiple)
1950
+ @delivery_tag = delivery_tag
1951
+ @multiple = multiple
1952
+ end
1953
+
1954
+ def self.has_content?
1955
+ false
1956
+ end
1957
+
1958
+ # @return
1959
+ # [u'delivery_tag = false', u'multiple = false']
1960
+ def self.encode(channel, delivery_tag, multiple)
1961
+ buffer = @packed_indexes.dup
1962
+ buffer << GorgonAMQ::Pack.pack_uint64_big_endian(delivery_tag)
1963
+ bit_buffer = 0
1964
+ bit_buffer = bit_buffer | (1 << 0) if multiple
1965
+ buffer << [bit_buffer].pack(PACK_CHAR)
1966
+ MethodFrame.new(buffer, channel)
1967
+ end
1968
+
1969
+ end
1970
+
1971
+ class Reject < Protocol::Method
1972
+ @name = "basic.reject"
1973
+ @method_id = 90
1974
+ @index = 0x003C005A # 60, 90, 3932250
1975
+ @packed_indexes = [60, 90].pack(PACK_UINT16_X2).freeze
1976
+
1977
+
1978
+ def self.has_content?
1979
+ false
1980
+ end
1981
+
1982
+ # @return
1983
+ # [u'delivery_tag = nil', u'requeue = true']
1984
+ def self.encode(channel, delivery_tag, requeue)
1985
+ buffer = @packed_indexes.dup
1986
+ buffer << GorgonAMQ::Pack.pack_uint64_big_endian(delivery_tag)
1987
+ bit_buffer = 0
1988
+ bit_buffer = bit_buffer | (1 << 0) if requeue
1989
+ buffer << [bit_buffer].pack(PACK_CHAR)
1990
+ MethodFrame.new(buffer, channel)
1991
+ end
1992
+
1993
+ end
1994
+
1995
+ class RecoverAsync < Protocol::Method
1996
+ @name = "basic.recover-async"
1997
+ @method_id = 100
1998
+ @index = 0x003C0064 # 60, 100, 3932260
1999
+ @packed_indexes = [60, 100].pack(PACK_UINT16_X2).freeze
2000
+
2001
+
2002
+ def self.has_content?
2003
+ false
2004
+ end
2005
+
2006
+ # @return
2007
+ # [u'requeue = false']
2008
+ def self.encode(channel, requeue)
2009
+ buffer = @packed_indexes.dup
2010
+ bit_buffer = 0
2011
+ bit_buffer = bit_buffer | (1 << 0) if requeue
2012
+ buffer << [bit_buffer].pack(PACK_CHAR)
2013
+ MethodFrame.new(buffer, channel)
2014
+ end
2015
+
2016
+ end
2017
+
2018
+ class Recover < Protocol::Method
2019
+ @name = "basic.recover"
2020
+ @method_id = 110
2021
+ @index = 0x003C006E # 60, 110, 3932270
2022
+ @packed_indexes = [60, 110].pack(PACK_UINT16_X2).freeze
2023
+
2024
+
2025
+ def self.has_content?
2026
+ false
2027
+ end
2028
+
2029
+ # @return
2030
+ # [u'requeue = false']
2031
+ def self.encode(channel, requeue)
2032
+ buffer = @packed_indexes.dup
2033
+ bit_buffer = 0
2034
+ bit_buffer = bit_buffer | (1 << 0) if requeue
2035
+ buffer << [bit_buffer].pack(PACK_CHAR)
2036
+ MethodFrame.new(buffer, channel)
2037
+ end
2038
+
2039
+ end
2040
+
2041
+ class RecoverOk < Protocol::Method
2042
+ @name = "basic.recover-ok"
2043
+ @method_id = 111
2044
+ @index = 0x003C006F # 60, 111, 3932271
2045
+ @packed_indexes = [60, 111].pack(PACK_UINT16_X2).freeze
2046
+
2047
+ # @return
2048
+ def self.decode(data)
2049
+ offset = 0
2050
+ self.new()
2051
+ end
2052
+
2053
+ def initialize()
2054
+ end
2055
+
2056
+ def self.has_content?
2057
+ false
2058
+ end
2059
+
2060
+
2061
+ end
2062
+
2063
+ class Nack < Protocol::Method
2064
+ @name = "basic.nack"
2065
+ @method_id = 120
2066
+ @index = 0x003C0078 # 60, 120, 3932280
2067
+ @packed_indexes = [60, 120].pack(PACK_UINT16_X2).freeze
2068
+
2069
+ # @return
2070
+ def self.decode(data)
2071
+ offset = 0
2072
+ delivery_tag = GorgonAMQ::Pack.unpack_uint64_big_endian(data[offset, 8]).first
2073
+ offset += 8
2074
+ bit_buffer = data[offset, 1].unpack(PACK_CHAR).first
2075
+ offset += 1
2076
+ multiple = (bit_buffer & (1 << 0)) != 0
2077
+ requeue = (bit_buffer & (1 << 1)) != 0
2078
+ self.new(delivery_tag, multiple, requeue)
2079
+ end
2080
+
2081
+ attr_reader :delivery_tag, :multiple, :requeue
2082
+ def initialize(delivery_tag, multiple, requeue)
2083
+ @delivery_tag = delivery_tag
2084
+ @multiple = multiple
2085
+ @requeue = requeue
2086
+ end
2087
+
2088
+ def self.has_content?
2089
+ false
2090
+ end
2091
+
2092
+ # @return
2093
+ # [u'delivery_tag = false', u'multiple = false', u'requeue = true']
2094
+ def self.encode(channel, delivery_tag, multiple, requeue)
2095
+ buffer = @packed_indexes.dup
2096
+ buffer << GorgonAMQ::Pack.pack_uint64_big_endian(delivery_tag)
2097
+ bit_buffer = 0
2098
+ bit_buffer = bit_buffer | (1 << 0) if multiple
2099
+ bit_buffer = bit_buffer | (1 << 1) if requeue
2100
+ buffer << [bit_buffer].pack(PACK_CHAR)
2101
+ MethodFrame.new(buffer, channel)
2102
+ end
2103
+
2104
+ end
2105
+
2106
+ end
2107
+
2108
+ class Tx < Protocol::Class
2109
+ @name = "tx"
2110
+ @method_id = 90
2111
+
2112
+
2113
+
2114
+ class Select < Protocol::Method
2115
+ @name = "tx.select"
2116
+ @method_id = 10
2117
+ @index = 0x005A000A # 90, 10, 5898250
2118
+ @packed_indexes = [90, 10].pack(PACK_UINT16_X2).freeze
2119
+
2120
+
2121
+ def self.has_content?
2122
+ false
2123
+ end
2124
+
2125
+ # @return
2126
+ # []
2127
+ def self.encode(channel)
2128
+ buffer = @packed_indexes.dup
2129
+ MethodFrame.new(buffer, channel)
2130
+ end
2131
+
2132
+ end
2133
+
2134
+ class SelectOk < Protocol::Method
2135
+ @name = "tx.select-ok"
2136
+ @method_id = 11
2137
+ @index = 0x005A000B # 90, 11, 5898251
2138
+ @packed_indexes = [90, 11].pack(PACK_UINT16_X2).freeze
2139
+
2140
+ # @return
2141
+ def self.decode(data)
2142
+ offset = 0
2143
+ self.new()
2144
+ end
2145
+
2146
+ def initialize()
2147
+ end
2148
+
2149
+ def self.has_content?
2150
+ false
2151
+ end
2152
+
2153
+
2154
+ end
2155
+
2156
+ class Commit < Protocol::Method
2157
+ @name = "tx.commit"
2158
+ @method_id = 20
2159
+ @index = 0x005A0014 # 90, 20, 5898260
2160
+ @packed_indexes = [90, 20].pack(PACK_UINT16_X2).freeze
2161
+
2162
+
2163
+ def self.has_content?
2164
+ false
2165
+ end
2166
+
2167
+ # @return
2168
+ # []
2169
+ def self.encode(channel)
2170
+ buffer = @packed_indexes.dup
2171
+ MethodFrame.new(buffer, channel)
2172
+ end
2173
+
2174
+ end
2175
+
2176
+ class CommitOk < Protocol::Method
2177
+ @name = "tx.commit-ok"
2178
+ @method_id = 21
2179
+ @index = 0x005A0015 # 90, 21, 5898261
2180
+ @packed_indexes = [90, 21].pack(PACK_UINT16_X2).freeze
2181
+
2182
+ # @return
2183
+ def self.decode(data)
2184
+ offset = 0
2185
+ self.new()
2186
+ end
2187
+
2188
+ def initialize()
2189
+ end
2190
+
2191
+ def self.has_content?
2192
+ false
2193
+ end
2194
+
2195
+
2196
+ end
2197
+
2198
+ class Rollback < Protocol::Method
2199
+ @name = "tx.rollback"
2200
+ @method_id = 30
2201
+ @index = 0x005A001E # 90, 30, 5898270
2202
+ @packed_indexes = [90, 30].pack(PACK_UINT16_X2).freeze
2203
+
2204
+
2205
+ def self.has_content?
2206
+ false
2207
+ end
2208
+
2209
+ # @return
2210
+ # []
2211
+ def self.encode(channel)
2212
+ buffer = @packed_indexes.dup
2213
+ MethodFrame.new(buffer, channel)
2214
+ end
2215
+
2216
+ end
2217
+
2218
+ class RollbackOk < Protocol::Method
2219
+ @name = "tx.rollback-ok"
2220
+ @method_id = 31
2221
+ @index = 0x005A001F # 90, 31, 5898271
2222
+ @packed_indexes = [90, 31].pack(PACK_UINT16_X2).freeze
2223
+
2224
+ # @return
2225
+ def self.decode(data)
2226
+ offset = 0
2227
+ self.new()
2228
+ end
2229
+
2230
+ def initialize()
2231
+ end
2232
+
2233
+ def self.has_content?
2234
+ false
2235
+ end
2236
+
2237
+
2238
+ end
2239
+
2240
+ end
2241
+
2242
+ class Confirm < Protocol::Class
2243
+ @name = "confirm"
2244
+ @method_id = 85
2245
+
2246
+
2247
+
2248
+ class Select < Protocol::Method
2249
+ @name = "confirm.select"
2250
+ @method_id = 10
2251
+ @index = 0x0055000A # 85, 10, 5570570
2252
+ @packed_indexes = [85, 10].pack(PACK_UINT16_X2).freeze
2253
+
2254
+ # @return
2255
+ def self.decode(data)
2256
+ offset = 0
2257
+ bit_buffer = data[offset, 1].unpack(PACK_CHAR).first
2258
+ offset += 1
2259
+ nowait = (bit_buffer & (1 << 0)) != 0
2260
+ self.new(nowait)
2261
+ end
2262
+
2263
+ attr_reader :nowait
2264
+ def initialize(nowait)
2265
+ @nowait = nowait
2266
+ end
2267
+
2268
+ def self.has_content?
2269
+ false
2270
+ end
2271
+
2272
+ # @return
2273
+ # [u'nowait = false']
2274
+ def self.encode(channel, nowait)
2275
+ buffer = @packed_indexes.dup
2276
+ bit_buffer = 0
2277
+ bit_buffer = bit_buffer | (1 << 0) if nowait
2278
+ buffer << [bit_buffer].pack(PACK_CHAR)
2279
+ MethodFrame.new(buffer, channel)
2280
+ end
2281
+
2282
+ end
2283
+
2284
+ class SelectOk < Protocol::Method
2285
+ @name = "confirm.select-ok"
2286
+ @method_id = 11
2287
+ @index = 0x0055000B # 85, 11, 5570571
2288
+ @packed_indexes = [85, 11].pack(PACK_UINT16_X2).freeze
2289
+
2290
+ # @return
2291
+ def self.decode(data)
2292
+ offset = 0
2293
+ self.new()
2294
+ end
2295
+
2296
+ def initialize()
2297
+ end
2298
+
2299
+ def self.has_content?
2300
+ false
2301
+ end
2302
+
2303
+ # @return
2304
+ # []
2305
+ def self.encode(channel)
2306
+ buffer = @packed_indexes.dup
2307
+ MethodFrame.new(buffer, channel)
2308
+ end
2309
+
2310
+ end
2311
+
2312
+ end
2313
+
2314
+
2315
+ METHODS = begin
2316
+ Method.methods.inject(Hash.new) do |hash, klass|
2317
+ hash.merge!(klass.index => klass)
2318
+ end
2319
+ end
2320
+ end
2321
+ end
2322
+