Class: AMQ::Protocol::Frame
- Inherits:
-
Object
- Object
- AMQ::Protocol::Frame
- Defined in:
- lib/amq/protocol/frame.rb
Direct Known Subclasses
Constant Summary collapse
- TYPES =
{:method => 1, :headers => 2, :body => 3, :heartbeat => 8}.freeze
- TYPES_REVERSE =
TYPES.invert.freeze
- TYPES_OPTIONS =
TYPES.keys.freeze
- CHANNEL_RANGE =
(0..65535).freeze
- FINAL_OCTET =
206
"\xCE".freeze
- CLASSES =
{ Frame::TYPES[:method] => MethodFrame, Frame::TYPES[:headers] => HeaderFrame, Frame::TYPES[:body] => BodyFrame, Frame::TYPES[:heartbeat] => HeartbeatFrame }
Class Method Summary collapse
- .decode ⇒ Object
- .decode_header(header) ⇒ Object
-
.encode(type, payload, channel) ⇒ Object
The channel number is 0 for all frames which are global to the connection and 1-65535 for frames that refer to specific channels.
- .find_type(type) ⇒ Object
- .new(original_type, *args) ⇒ Object
Instance Method Summary collapse
-
#__new__ ⇒ Object
because of reloading.
- #final? ⇒ Boolean
Class Method Details
.decode ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/amq/protocol/frame.rb', line 36 def self.decode(*) raise NotImplementedError.new <<-EOF You are supposed to redefine this method, because it's dependent on used IO adapter. This functionality is part of the https://github.com/ruby-amqp/amq-client library. EOF end |
.decode_header(header) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/amq/protocol/frame.rb', line 44 def self.decode_header(header) raise EmptyResponseError if header == nil || header.empty? type_id, channel, size = header.unpack(PACK_CHAR_UINT16_UINT32) type = TYPES_REVERSE[type_id] raise FrameTypeError.new(TYPES_OPTIONS) unless type [type, channel, size] end |
.encode(type, payload, channel) ⇒ Object
The channel number is 0 for all frames which are global to the connection and 1-65535 for frames that refer to specific channels.
14 15 16 17 18 |
# File 'lib/amq/protocol/frame.rb', line 14 def self.encode(type, payload, channel) raise RuntimeError.new("Channel has to be 0 or an integer in range 1..65535 but was #{channel.inspect}") unless CHANNEL_RANGE.include?(channel) raise RuntimeError.new("Payload can't be nil") if payload.nil? [find_type(type), channel, payload.bytesize].pack(PACK_CHAR_UINT16_UINT32) + payload.bytes.to_a.pack(SIMPLE_BYTE_PACK) + FINAL_OCTET end |
.find_type(type) ⇒ Object
30 31 32 33 34 |
# File 'lib/amq/protocol/frame.rb', line 30 def self.find_type(type) type_id = if Symbol === type then TYPES[type] else type end raise FrameTypeError.new(TYPES_OPTIONS) if type == nil || !TYPES_REVERSE.has_key?(type_id) type_id end |
.new(original_type, *args) ⇒ Object
24 25 26 27 28 |
# File 'lib/amq/protocol/frame.rb', line 24 def self.new(original_type, *args) type_id = find_type(original_type) klass = CLASSES[type_id] klass.new(*args) end |
Instance Method Details
#__new__ ⇒ Object
because of reloading
21 |
# File 'lib/amq/protocol/frame.rb', line 21 alias_method :__new__, :new |
#final? ⇒ Boolean
53 54 55 |
# File 'lib/amq/protocol/frame.rb', line 53 def final? true end |