# File lib/amqp/protocol.rb, line 8 def initialize *args opts = args.pop if args.last.is_a? Hash opts ||= {} @debug = 1 # XXX hack, p(obj) == '' if no instance vars are set if args.size == 1 and args.first.is_a? Buffer buf = args.shift else buf = nil end self.class.arguments.each do |type, name| val = buf ? buf.read(type) : args.shift || opts[name] || opts[name.to_s] instance_variable_set("@#{name}", val) end end
# File lib/amqp/protocol.rb, line 27 def arguments self.class.arguments.inject({}) do |hash, (type, name)| hash.update name => instance_variable_get("@#{name}") end end
# File lib/amqp/protocol.rb, line 33 def to_binary buf = Buffer.new buf.write :short, self.class.section.id buf.write :short, self.class.id bits = [] self.class.arguments.each do |type, name| val = instance_variable_get("@#{name}") if type == :bit bits << (val || false) else unless bits.empty? buf.write :bit, bits bits = [] end buf.write type, val end end buf.write :bit, bits unless bits.empty? buf.rewind buf end
Generated with the Darkfish Rdoc Generator 2.