Class: Protocol::WebSocket::Framer
- Inherits:
-
Object
- Object
- Protocol::WebSocket::Framer
- Defined in:
- lib/protocol/websocket/framer.rb
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(stream, frames = FRAMES) ⇒ Framer
constructor
A new instance of Framer.
- #read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) ⇒ Object
- #read_header ⇒ Object
- #write_frame(frame) ⇒ Object
Constructor Details
Instance Method Details
#close ⇒ Object
50 51 52 |
# File 'lib/protocol/websocket/framer.rb', line 50 def close @stream.close end |
#flush ⇒ Object
54 55 56 |
# File 'lib/protocol/websocket/framer.rb', line 54 def flush @stream.flush end |
#read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/protocol/websocket/framer.rb', line 58 def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE) # Read the header: finished, opcode = read_header # Read the frame: klass = @frames[opcode] || Frame frame = klass.read(finished, opcode, @stream, maximum_frame_size) return frame end |
#read_header ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/protocol/websocket/framer.rb', line 73 def read_header if buffer = @stream.read(1) return Frame.parse_header(buffer) end raise EOFError, "Could not read frame header!" end |
#write_frame(frame) ⇒ Object
69 70 71 |
# File 'lib/protocol/websocket/framer.rb', line 69 def write_frame(frame) frame.write(@stream) end |