Class: Qrack::Protocol09::Header
- Inherits:
-
Object
- Object
- Qrack::Protocol09::Header
- Defined in:
- lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#size ⇒ Object
Returns the value of attribute size.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #==(header) ⇒ Object
-
#initialize(*args) ⇒ Header
constructor
A new instance of Header.
- #method_missing(meth, *args, &blk) ⇒ Object
- #to_binary ⇒ Object
- #to_frame(channel = 0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Header
Returns a new instance of Header.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 64 def initialize *args opts = args.pop if args.last.is_a? Hash opts ||= {} first = args.shift if first.is_a? ::Class and first.ancestors.include? Protocol09::Class @klass = first @size = args.shift || 0 @weight = args.shift || 0 @properties = opts elsif first.is_a? Transport09::Buffer or first.is_a? String buf = first buf = Transport09::Buffer.new(buf) unless buf.is_a? Transport09::Buffer @klass = Protocol09.classes[buf.read(:short)] @weight = buf.read(:short) @size = buf.read(:longlong) props = buf.read(:properties, *klass.properties.map{|type,_| type }) @properties = Hash[*klass.properties.map{|_,name| name }.zip(props).reject{|k,v| v.nil? }.flatten] else raise ArgumentError, 'Invalid argument' end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
120 121 122 123 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 120 def method_missing meth, *args, &blk @properties.has_key?(meth) || @klass.properties.find{|_,name| name == meth } ? @properties[meth] : super end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
92 93 94 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 92 def klass @klass end |
#properties ⇒ Object
Returns the value of attribute properties.
92 93 94 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 92 def properties @properties end |
#size ⇒ Object
Returns the value of attribute size.
92 93 94 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 92 def size @size end |
#weight ⇒ Object
Returns the value of attribute weight.
92 93 94 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 92 def weight @weight end |
Instance Method Details
#==(header) ⇒ Object
114 115 116 117 118 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 114 def == header [ :klass, :size, :weight, :properties ].inject(true) do |eql, field| eql and __send__(field) == header.__send__(field) end end |
#to_binary ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 94 def to_binary buf = Transport09::Buffer.new buf.write :short, klass.id buf.write :short, weight # XXX rabbitmq only supports weight == 0 buf.write :longlong, size buf.write :properties, (klass.properties.map do |type, name| [ type, properties[name] || properties[name.to_s] ] end) buf.rewind buf end |
#to_frame(channel = 0) ⇒ Object
110 111 112 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 110 def to_frame channel = 0 Transport09::Header.new(self, channel) end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb', line 106 def to_s to_binary.to_s end |