Method: FTW::WebSocket::Parser#feed

Defined in:
lib/ftw/websocket/parser.rb

#feed(data) ⇒ String?

Feed data to this parser.

Currently, it will return the raw payload of websocket messages. Otherwise, it returns nil if no complete message has yet been consumed.

Parameters:

  • the (String)

    string data to feed into the parser.

Returns:

  • (String, nil)

    the websocket message payload, if any, nil otherwise.



77
78
79
80
81
82
83
84
85
# File 'lib/ftw/websocket/parser.rb', line 77

def feed(data)
  @buffer << data
  while have?(@need)
    value = send(@state)
    # Return if our state yields a value.
    yield value if !value.nil? and block_given?
  end
  return nil
end