Class: GorgonAMQ::Protocol::Frame
- Inherits:
-
Object
- Object
- GorgonAMQ::Protocol::Frame
show all
- Defined in:
- lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb
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 =
"\xCE".freeze
- CLASSES =
{
Frame::TYPES[:method] => MethodFrame,
Frame::TYPES[:headers] => HeaderFrame,
Frame::TYPES[:body] => BodyFrame,
Frame::TYPES[:heartbeat] => HeartbeatFrame
}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.decode ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb', line 51
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
|
.encode(type, payload, channel) ⇒ Object
31
32
33
|
# File 'lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb', line 31
def self.encode(type, payload, channel)
encode_to_array(type, payload, channel).join
end
|
.encode_to_array(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.
21
22
23
24
25
26
27
28
29
|
# File 'lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb', line 21
def self.encode_to_array(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?
components = []
components << [find_type(type), channel, payload.bytesize].pack(PACK_CHAR_UINT16_UINT32)
components << encoded_payload(payload)
components << FINAL_OCTET
components
end
|
.encoded_payload(payload) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb', line 12
def self.encoded_payload(payload)
if payload.respond_to?(:force_encoding) && payload.encoding.name != 'BINARY'
payload = payload.dup.force_encoding('BINARY')
end
payload
end
|
.find_type(type) ⇒ Object
45
46
47
48
49
|
# File 'lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb', line 45
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
39
40
41
42
43
|
# File 'lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb', line 39
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
36
|
# File 'lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb', line 36
alias_method :__new__, :new
|
#final? ⇒ Boolean
68
69
70
|
# File 'lib/gorgon_amq-protocol/lib/gorgon_amq/protocol/frame.rb', line 68
def final?
true
end
|