13 #include <restinio/utils/impl/bitops.hpp> 24 #define RESTINIO_WEBSOCKET_OPCODES_MAP( RESTINIO_GEN ) 25 RESTINIO_GEN( continuation_frame, 0x00
) 26 RESTINIO_GEN( text_frame, 0x01
) 27 RESTINIO_GEN( binary_frame, 0x02
) 28 RESTINIO_GEN( connection_close_frame, 0x08
) 29 RESTINIO_GEN( ping_frame, 0x09
) 30 RESTINIO_GEN( pong_frame, 0x0A
) 38 #define RESTINIO_WEBSOCKET_OPCODES_GEN( name, code ) name = code, 40 #undef RESTINIO_WEBSOCKET_OPCODES_GEN 48 const char * result =
"unknown_frame";
51 #define RESTINIO_WEBSOCKET_OPCODES_GEN( name, code ) 52 case opcode_t::name: result = #name; break; 55 #undef RESTINIO_WEBSOCKET_OPCODES_GEN 69 #define RESTINIO_WEBSOCKET_OPCODES_GEN( name, code ) 70 case opcode_t::name: break; 73 #undef RESTINIO_WEBSOCKET_OPCODES_GEN 75 default: result =
false;
103 using namespace ::restinio::utils::impl::bitops;
106 n_bits_from<
char, 8>(
static_cast<std::uint16_t>(code) ),
107 n_bits_from<
char, 0>(
static_cast<std::uint16_t>(code) )
114 using namespace ::restinio::utils::impl::bitops;
116 std::uint16_t result{ 0 };
117 if( 2 <= data.size() )
119 result |=
static_cast< std::uint8_t >( data[ 0 ] );
121 result |=
static_cast< std::uint8_t >( data[ 1 ] );
125 return static_cast<status_code_t>(result);
143 class message_t
final 144 :
public std::enable_shared_from_this< message_t >
160 std::string payload )
212 m_payload = std::move( str );
constexpr final_frame_flag_t final_frame
#define RESTINIO_WEBSOCKET_OPCODES_MAP(RESTINIO_GEN)
std::string & payload() noexcept
status_code_t status_code_from_bin(string_view_t data)
final_frame_flag_t final_flag() const noexcept
Get final flag.
void set_payload(std::string str)
message_t(final_frame_flag_t final_flag, opcode_t opcode, std::string payload)
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
message_t(final_frame_flag_t final_flag, opcode_t opcode)
final_frame_flag_t
WS frame (message) "final"/"not final" flag.
bool is_final() const noexcept
std::string status_code_to_bin(status_code_t code)
const char * opcode_to_string(opcode_t opcode)
Helper sunction to get method string name.
std::string m_payload
Websocket message payload.
final_frame_flag_t m_final_flag
Final flag.
const std::string & payload() const noexcept
constexpr final_frame_flag_t not_final_frame
bool is_valid_opcode(opcode_t opcode)
void set_opcode(opcode_t opcode) noexcept
void set_final_flag(final_frame_flag_t final_flag) noexcept
opcode_t opcode() const noexcept