Class: EventMachine::Protocols::Stomp::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/em/protocols/stomp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



68
69
70
71
72
# File 'lib/em/protocols/stomp.rb', line 68

def initialize
  @header = {}
  @state = :precommand
  @content_length = nil
end

Instance Attribute Details

#bodyObject

Body of the message



65
66
67
# File 'lib/em/protocols/stomp.rb', line 65

def body
  @body
end

#commandObject

The command associated with the message, usually ‘CONNECTED’ or ‘MESSAGE’



60
61
62
# File 'lib/em/protocols/stomp.rb', line 60

def command
  @command
end

#headerObject Also known as: headers

Hash containing headers such as destination and message-id



62
63
64
# File 'lib/em/protocols/stomp.rb', line 62

def header
  @header
end

Instance Method Details

#consume_line(line) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/em/protocols/stomp.rb', line 74

def consume_line line
  if @state == :precommand
    unless line =~ /\A\s*\Z/
      @command = line
      @state = :headers
    end
  elsif @state == :headers
    if line == ""
      if @content_length
        yield( [:sized_text, @content_length+1] )
      else
        @state = :body
        yield( [:unsized_text] )
      end
    elsif line =~ /\A([^:]+):(.+)\Z/
      k = $1.dup.strip
      v = $2.dup.strip
      @header[k] = v
      if k == "content-length"
        @content_length = v.to_i
      end
    else
      # This is a protocol error. How to signal it?
    end
  elsif @state == :body
    @body = line
    yield( [:dispatch] )
  end
end