WS_FRAME Class
Represents a single WebSocket frame with encoding/decoding capabilities.
Creation Procedures
make_text (a_text: STRING; a_is_fin: BOOLEAN)
Create a text frame with UTF-8 payload.
Contracts
make_binary (a_data: ARRAY [NATURAL_8]; a_is_fin: BOOLEAN)
Create a binary frame with raw byte payload.
Contracts
make_close (a_code: INTEGER; a_reason: STRING)
Create a close frame with status code and reason.
Contracts
make_ping / make_pong
Create ping/pong control frames for heartbeat.
Contracts
Status Queries
| Feature | Type | Description |
|---|---|---|
is_fin |
BOOLEAN | Is this the final fragment? |
is_text |
BOOLEAN | Is this a text frame? |
is_binary |
BOOLEAN | Is this a binary frame? |
is_close |
BOOLEAN | Is this a close frame? |
is_ping |
BOOLEAN | Is this a ping frame? |
is_pong |
BOOLEAN | Is this a pong frame? |
is_control |
BOOLEAN | Is this a control frame? |
opcode |
INTEGER | Frame opcode (0-15) |
payload_length |
INTEGER | Payload byte count |
Payload Access
text_payload: STRING
Get payload as UTF-8 string (for text frames).
close_code: INTEGER
Get close status code (for close frames).
close_reason: STRING
Get close reason text (for close frames).
Operations
set_mask (a_key: ARRAY [NATURAL_8])
Set 4-byte mask key for client-to-server frames.
Contracts
to_bytes: ARRAY [NATURAL_8]
Encode frame to wire format bytes.
Contracts
Constants
| Constant | Value | Description |
|---|---|---|
Opcode_continuation |
0 | Continuation frame |
Opcode_text |
1 | Text frame |
Opcode_binary |
2 | Binary frame |
Opcode_close |
8 | Close frame |
Opcode_ping |
9 | Ping frame |
Opcode_pong |
10 | Pong frame |
WS_FRAME_PARSER Class
Streaming parser for reading frames from byte streams.
make
Initialize parser with empty buffer.
add_bytes (a_bytes: ARRAY [NATURAL_8])
Add bytes to parse buffer.
Contracts
parse: BOOLEAN
Attempt to parse a frame. Returns True if successful.
Contracts
has_frame: BOOLEAN
Is a complete frame available?
last_frame: detachable WS_FRAME
Get the last parsed frame.
reset
Clear parser state and buffer.
WS_HANDSHAKE Class
WebSocket opening handshake for client and server.
Client Features
create_client_request (a_host, a_path: STRING): STRING
Generate HTTP upgrade request for client.
Contracts
validate_server_response (a_response: STRING): BOOLEAN
Validate server's handshake response.
Server Features
parse_client_request (a_request: STRING): BOOLEAN
Parse incoming client handshake request.
Contracts
create_server_response: STRING
Generate HTTP 101 response for server.
Contracts
Status
| Feature | Type | Description |
|---|---|---|
is_valid |
BOOLEAN | Was handshake successful? |
last_error |
STRING | Error message if failed |
sec_websocket_key |
detachable STRING | The Sec-WebSocket-Key value |
requested_path |
detachable STRING | Requested URI path |
WS_MESSAGE Class
High-level message abstraction with fragmentation support.
make_text (a_text: STRING)
Create a text message.
make_binary (a_data: ARRAY [NATURAL_8])
Create a binary message.
to_frame: WS_FRAME
Convert to a single frame (for small messages).
to_frames (a_max_size: INTEGER): ARRAYED_LIST [WS_FRAME]
Split into multiple frames with maximum payload size.