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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



39
40
41
42
43
# File 'lib/protocols/stomp.rb', line 39

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

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



38
39
40
# File 'lib/protocols/stomp.rb', line 38

def body
  @body
end

#commandObject

Returns the value of attribute command.



38
39
40
# File 'lib/protocols/stomp.rb', line 38

def command
  @command
end

#headerObject

Returns the value of attribute header.



38
39
40
# File 'lib/protocols/stomp.rb', line 38

def header
  @header
end

Instance Method Details

#consume_line(line) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/protocols/stomp.rb', line 44

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