restinio::websocket::basic::impl::ws_parser_t Class Reference

Websocket parser. More...

`#include <ws_parser.hpp>`

## Public Member Functions

size_t | parser_execute (const char *data, size_t size)
| Parse piece of data from buffer. More...
bool | header_parsed () const
| Check header of current websocket message is parsed. More...
void | reset ()
| Reset internal state. More...
const message_details_t & | current_message () const
| Get current mesasge details. More...

## Private Types

enum class | state_t { waiting_for_first_2_bytes , waiting_for_ext_len , waiting_for_mask_key , header_parsed }
| Internal state. More...

## Private Member Functions

void | process_byte (byte_t byte)
| Process one byte of incoming buffer. More...
void | process_first_2_bytes ()
| Process first two bytes of message. More...
void | process_extended_length ()
| Process extended length. More...
void | process_masking_key ()
| Process extended length. More...
void | parse_first_2_bytes (const raw_data_t &data)
| Parse first two bytes of message from buffer. More...
void | parse_ext_payload_len (std::uint8_t payload_len, const raw_data_t &data)
| Parse extended length from buffer. More...
void | parse_masking_key (bool mask_flag, const raw_data_t &data)
| Parse masking key from buffer. More...

## Private Attributes

expected_data_t | m_expected_data { websocket_first_two_bytes_size }
| Buffer for parts of websocket message with known size. More...
message_details_t | m_current_msg
| Current websocket message details. More...
state_t | m_current_state = state_t::waiting_for_first_2_bytes
| Current state. More...

## Detailed Description

Websocket parser.

This class can parse message from binary buffer.

It is not necessary to have all buffer before parsing. Parser can process pieces of data and save intermediate state.

Definition at line 259 of file ws_parser.hpp.

## Member Enumeration Documentation

## state_t

enum class restinio::websocket::basic::impl::ws_parser_t::state_t

strong private

Internal state.

Enumerator
waiting_for_first_2_bytes |
waiting_for_ext_len |
waiting_for_mask_key |
header_parsed |

Definition at line 320 of file ws_parser.hpp.

## Member Function Documentation

## current_message()

const message_details_t & restinio::websocket::basic::impl::ws_parser_t::current_message | ( |  | ) | const

inline

Get current mesasge details.

Definition at line 303 of file ws_parser.hpp.

## header_parsed()

bool restinio::websocket::basic::impl::ws_parser_t::header_parsed | ( |  | ) | const

inline

Check header of current websocket message is parsed.

Definition at line 284 of file ws_parser.hpp.

## parse_ext_payload_len()

void restinio::websocket::basic::impl::ws_parser_t::parse_ext_payload_len | ( | std::uint8_t | payload_len,
|  | const raw_data_t & | data
| ) |  |

inline private

Parse extended length from buffer.

Definition at line 456 of file ws_parser.hpp.

## parse_first_2_bytes()

void restinio::websocket::basic::impl::ws_parser_t::parse_first_2_bytes | ( | const raw_data_t & | data | ) |

inline private

Parse first two bytes of message from buffer.

Definition at line 440 of file ws_parser.hpp.

## parse_masking_key()

void restinio::websocket::basic::impl::ws_parser_t::parse_masking_key | ( | bool | mask_flag,
|  | const raw_data_t & | data
| ) |  |

inline private

Parse masking key from buffer.

Definition at line 474 of file ws_parser.hpp.

## parser_execute()

size_t restinio::websocket::basic::impl::ws_parser_t::parser_execute | ( | const char * | data,
|  | size_t | size
| ) |  |

inline

Parse piece of data from buffer.

Definition at line 265 of file ws_parser.hpp.

## process_byte()

void restinio::websocket::basic::impl::ws_parser_t::process_byte | ( | byte_t | byte | ) |

inline private

Process one byte of incoming buffer.

Definition at line 333 of file ws_parser.hpp.

## process_extended_length()

void restinio::websocket::basic::impl::ws_parser_t::process_extended_length | ( |  | ) |

inline private

Process extended length.

Parse extended length and set new state.

Definition at line 405 of file ws_parser.hpp.

## process_first_2_bytes()

void restinio::websocket::basic::impl::ws_parser_t::process_first_2_bytes | ( |  | ) |

inline private

Process first two bytes of message.

Parse flags, opcode, payload length and set new state.

Definition at line 367 of file ws_parser.hpp.

## process_masking_key()

void restinio::websocket::basic::impl::ws_parser_t::process_masking_key | ( |  | ) |

inline private

Process extended length.

Parse masking key and set new state.

Definition at line 429 of file ws_parser.hpp.

## reset()

void restinio::websocket::basic::impl::ws_parser_t::reset | ( |  | ) |

inline

Reset internal state.

Need to call this function before processing next message.

Definition at line 294 of file ws_parser.hpp.

## Member Data Documentation

## m_current_msg

message_details_t restinio::websocket::basic::impl::ws_parser_t::m_current_msg

private

Current websocket message details.

Definition at line 317 of file ws_parser.hpp.

## m_current_state

state_t restinio::websocket::basic::impl::ws_parser_t::m_current_state = state_t::waiting_for_first_2_bytes

private

Current state.

Definition at line 329 of file ws_parser.hpp.

## m_expected_data

expected_data_t restinio::websocket::basic::impl::ws_parser_t::m_expected_data { websocket_first_two_bytes_size }

private

Buffer for parts of websocket message with known size.

Default value is first 2 bytes for flags and opcode.

Definition at line 314 of file ws_parser.hpp.

The documentation for this class was generated from the following file:

- restinio/websocket/impl/ws_parser.hpp