Module: Terminalwire::V2::Server::Rack::Frame

Defined in:
lib/terminalwire/v2/server/rack.rb

Overview

Just the framing this needs: encode unmasked server->client binary frames; the Sec-WebSocket-Accept value lives on Rack. One WebSocket message == one MessagePack protocol frame.

Constant Summary collapse

CLOSE =
[0x88, 0].pack("C2").freeze

Class Method Summary collapse

Class Method Details

.binary(payload) ⇒ Object



165
166
167
168
169
170
171
172
173
174
# File 'lib/terminalwire/v2/server/rack.rb', line 165

def binary(payload)
  body = payload.b
  n = body.bytesize
  head =
    if    n < 126    then [0x82, n].pack("C2")
    elsif n < 65_536 then [0x82, 126, n].pack("C2n")
    else                  [0x82, 127, n].pack("C2Q>")
    end
  head + body
end

.pong(payload) ⇒ Object



176
# File 'lib/terminalwire/v2/server/rack.rb', line 176

def pong(payload) = [0x8A, payload.bytesize].pack("C2") + payload.b