class WebSocket::Driver::Hybi

def send_frame(frame)

def send_frame(frame)
  length = frame.length
  values = []
  format = 'C2'
  masked = frame.masked ? MASK : 0
  values[0] = (frame.final ? FIN : 0) |
              (frame.rsv1 ? RSV1 : 0) |
              (frame.rsv2 ? RSV2 : 0) |
              (frame.rsv3 ? RSV3 : 0) |
              frame.opcode
  if length <= 125
    values[1] = masked | length
  elsif length <= 65535
    values[1] = masked | 126
    values[2] = length
    format << 'S>'
  else
    values[1] = masked | 127
    values[2] = length
    format << 'Q>'
  end
  if frame.masked
    values << frame.masking_key
    values << Mask.mask(frame.payload, frame.masking_key)
    format << 'a4a*'
  else
    values << frame.payload
    format << 'a*'
  end
  @socket.write(values.pack(format))
end