Class: Lich::Common::WebSocket::Frame::Reader
- Inherits:
-
Object
- Object
- Lich::Common::WebSocket::Frame::Reader
- Defined in:
- documented/common/websocket/frame.rb
Overview
Incremental frame decoder. Feed it raw bytes as they arrive off the socket; it returns whatever complete, reassembled messages became available, and holds on to any trailing partial frame until the next call.
Defined Under Namespace
Classes: RawFrame
Instance Method Summary collapse
-
#feed(bytes) ⇒ Array<Message>
Zero or more complete messages.
-
#initialize ⇒ void
constructor
Initializes the frame reader with an empty buffer and no fragment in progress.
Constructor Details
#initialize ⇒ void
Initializes the frame reader with an empty buffer and no fragment in progress.
141 142 143 144 |
# File 'documented/common/websocket/frame.rb', line 141 def initialize @buffer = +"".b @fragment = nil # [opcode, +payload] end |
Instance Method Details
#feed(bytes) ⇒ Array<Message>
Returns zero or more complete messages.
149 150 151 152 153 154 155 156 157 158 159 |
# File 'documented/common/websocket/frame.rb', line 149 def feed(bytes) @buffer << bytes = [] while (frame = take_frame!) .concat(handle_frame(frame)) end rescue ProtocolError => e e. = raise end |