NAME

Hypersonic::Protocol::WebSocket::Frame - WebSocket frame encoding/decoding

SYNOPSIS

use Hypersonic::Protocol::WebSocket::Frame;

# Generate C code for JIT
my $code = Hypersonic::Protocol::WebSocket::Frame->generate_c_code($builder);

# Perl-side frame creation (for testing)
my $frame = Hypersonic::Protocol::WebSocket::Frame->encode_frame(
    opcode => 0x1,  # text
    fin    => 1,
    data   => 'Hello',
    mask   => [0x12, 0x34, 0x56, 0x78],  # client must mask
);

DESCRIPTION

Implements RFC 6455 Section 5 binary frame protocol for WebSocket. All C code is generated at compile time for JIT compilation.

FRAME FORMAT

 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-------+-+-------------+-------------------------------+
|F|R|R|R| opcode|M| Payload len |    Extended payload length    |
|I|S|S|S|  (4)  |A|     (7)     |             (16/64)           |
|N|V|V|V|       |S|             |                               |
| |1|2|3|       |K|             |                               |
+-+-+-+-+-------+-+-------------+-------------------------------+

OPCODES

0x0 - Continuation
0x1 - Text
0x2 - Binary
0x8 - Close
0x9 - Ping
0xA - Pong