|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Provides WebSocket frame encoding and decoding functionality. More...
#include <websocket_frame.h>

Static Public Member Functions | |
| static auto | encode_frame (ws_opcode opcode, std::vector< uint8_t > &&payload, bool fin=true, bool mask=false) -> std::vector< uint8_t > |
| Encodes data into a WebSocket frame. | |
| static auto | decode_header (const std::vector< uint8_t > &data) -> std::optional< ws_frame_header > |
| Decodes a WebSocket frame header from raw data. | |
| static auto | decode_payload (const ws_frame_header &header, const std::vector< uint8_t > &data) -> std::vector< uint8_t > |
| Decodes the payload from a WebSocket frame. | |
| static auto | apply_mask (std::vector< uint8_t > &data, const std::array< uint8_t, 4 > &mask) -> void |
| Applies or removes XOR masking on data. | |
| static auto | generate_mask () -> std::array< uint8_t, 4 > |
| Generates a random 4-byte masking key. | |
| static auto | calculate_header_size (uint64_t payload_len, bool mask) -> size_t |
| Calculates the size of the frame header. | |
Provides WebSocket frame encoding and decoding functionality.
This class implements RFC 6455 compliant frame encoding and decoding, including support for masking, fragmentation, and all frame types.
Definition at line 57 of file websocket_frame.h.
|
static |
Applies or removes XOR masking on data.
WebSocket masking is symmetric (XOR operation), so this function can be used both to apply and remove masking.
| data | The data to mask/unmask (modified in place) |
| mask | The 4-byte masking key |
Definition at line 249 of file websocket_frame.cpp.
|
static |
Calculates the size of the frame header.
Determines how many bytes the header will occupy based on payload length and masking flag.
| payload_len | The length of the payload |
| mask | Whether the frame will be masked |
Definition at line 78 of file websocket_frame.cpp.
Referenced by kcenon::network::internal::websocket_protocol::process_frames().

|
static |
Decodes a WebSocket frame header from raw data.
Parses the first bytes of a WebSocket frame to extract header information. Does not validate or extract the payload.
| data | The raw frame data |
Definition at line 164 of file websocket_frame.cpp.
Referenced by kcenon::network::internal::websocket_protocol::process_frames().

|
static |
Decodes the payload from a WebSocket frame.
Extracts and unmasks (if necessary) the payload data from a frame using the provided header information.
| header | The decoded frame header |
| data | The complete frame data |
Definition at line 226 of file websocket_frame.cpp.
Referenced by kcenon::network::internal::websocket_protocol::process_frames().

|
static |
Encodes data into a WebSocket frame.
Creates a properly formatted WebSocket frame with the specified opcode and payload. Uses move semantics for zero-copy operation.
| opcode | The operation code for this frame |
| payload | The payload data (will be moved) |
| fin | Final fragment flag (default: true) |
| mask | Whether to mask the payload (default: false) |
Definition at line 99 of file websocket_frame.cpp.
Referenced by kcenon::network::internal::websocket_protocol::create_binary_message(), kcenon::network::internal::websocket_protocol::create_close(), kcenon::network::internal::websocket_protocol::create_ping(), kcenon::network::internal::websocket_protocol::create_pong(), and kcenon::network::internal::websocket_protocol::create_text_message().

|
static |
Generates a random 4-byte masking key.
Creates a cryptographically random masking key as required by RFC 6455 for client-to-server frames.
Definition at line 258 of file websocket_frame.cpp.