Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented #320. #337

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions example/no_tls_both.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void client_proc(
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::cout << "[client] publish received. "
<< "dup: " << std::boolalpha << mqtt::publish::is_dup(header)
<< " pos: " << mqtt::qos::to_str(mqtt::publish::get_qos(header))
Expand Down Expand Up @@ -195,15 +195,15 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
// set MQTT level handlers
ep.set_connect_handler(
[&]
(mqtt::string_view client_id,
mqtt::optional<mqtt::string_view> username,
mqtt::optional<mqtt::string_view> password,
(mqtt::buffer client_id,
mqtt::optional<mqtt::buffer> username,
mqtt::optional<mqtt::buffer> password,
mqtt::optional<mqtt::will>,
bool clean_session,
std::uint16_t keep_alive) {
std::cout << "[server] client_id : " << client_id << std::endl;
std::cout << "[server] username : " << (username ? username.value() : "none") << std::endl;
std::cout << "[server] password : " << (password ? password.value() : "none") << std::endl;
std::cout << "[server] username : " << (username ? username.value() : mqtt::buffer("none")) << std::endl;
std::cout << "[server] password : " << (password ? password.value() : mqtt::buffer("none")) << std::endl;
std::cout << "[server] clean_session: " << std::boolalpha << clean_session << std::endl;
std::cout << "[server] keep_alive : " << keep_alive << std::endl;
connections.insert(ep.shared_from_this());
Expand Down Expand Up @@ -245,8 +245,8 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::uint8_t qos = mqtt::publish::get_qos(header);
bool retain = mqtt::publish::is_retain(header);
std::cout << "[server] publish received."
Expand All @@ -272,12 +272,12 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
ep.set_subscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<std::tuple<mqtt::string_view, std::uint8_t>> entries) {
std::vector<std::tuple<mqtt::buffer, std::uint8_t>> entries) {
std::cout << "[server]subscribe received. packet_id: " << packet_id << std::endl;
std::vector<std::uint8_t> res;
res.reserve(entries.size());
for (auto const& e : entries) {
mqtt::string_view topic = std::get<0>(e);
mqtt::buffer topic = std::get<0>(e);
std::uint8_t qos = std::get<1>(e);
std::cout << "[server] topic: " << topic << " qos: " << static_cast<int>(qos) << std::endl;
res.emplace_back(qos);
Expand All @@ -290,7 +290,7 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
ep.set_unsubscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<mqtt::string_view> topics) {
std::vector<mqtt::buffer> topics) {
std::cout << "[server]unsubscribe received. packet_id: " << packet_id << std::endl;
for (auto const& topic : topics) {
subs.erase(std::string(topic)); // TODO: Fix need to construct string
Expand Down
20 changes: 10 additions & 10 deletions example/no_tls_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ int main(int argc, char** argv) {
// set MQTT level handlers
ep.set_connect_handler(
[&]
(mqtt::string_view client_id,
mqtt::optional<mqtt::string_view> username,
mqtt::optional<mqtt::string_view> password,
(mqtt::buffer client_id,
mqtt::optional<mqtt::buffer> username,
mqtt::optional<mqtt::buffer> password,
mqtt::optional<mqtt::will>,
bool clean_session,
std::uint16_t keep_alive) {
std::cout << "client_id : " << client_id << std::endl;
std::cout << "username : " << (username ? username.value() : "none") << std::endl;
std::cout << "password : " << (password ? password.value() : "none") << std::endl;
std::cout << "username : " << (username ? username.value() : mqtt::buffer("none")) << std::endl;
std::cout << "password : " << (password ? password.value() : mqtt::buffer("none")) << std::endl;
std::cout << "clean_session: " << std::boolalpha << clean_session << std::endl;
std::cout << "keep_alive : " << keep_alive << std::endl;
connections.insert(ep.shared_from_this());
Expand Down Expand Up @@ -157,8 +157,8 @@ int main(int argc, char** argv) {
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::uint8_t qos = mqtt::publish::get_qos(header);
bool retain = mqtt::publish::is_retain(header);
std::cout << "publish received."
Expand All @@ -184,12 +184,12 @@ int main(int argc, char** argv) {
ep.set_subscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<std::tuple<mqtt::string_view, std::uint8_t>> entries) {
std::vector<std::tuple<mqtt::buffer, std::uint8_t>> entries) {
std::cout << "subscribe received. packet_id: " << packet_id << std::endl;
std::vector<std::uint8_t> res;
res.reserve(entries.size());
for (auto const& e : entries) {
mqtt::string_view topic = std::get<0>(e);
mqtt::buffer topic = std::get<0>(e);
std::uint8_t qos = std::get<1>(e);
std::cout << "topic: " << topic << " qos: " << static_cast<int>(qos) << std::endl;
res.emplace_back(qos);
Expand All @@ -202,7 +202,7 @@ int main(int argc, char** argv) {
ep.set_unsubscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<mqtt::string_view> topics) {
std::vector<mqtt::buffer> topics) {
std::cout << "unsubscribe received. packet_id: " << packet_id << std::endl;
for (auto const& topic : topics) {
subs.erase(std::string(topic)); // TODO Fix need to construct string.
Expand Down
24 changes: 12 additions & 12 deletions example/no_tls_ws_both.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void client_proc(
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::cout << "[client] publish received. "
<< "dup: " << std::boolalpha << mqtt::publish::is_dup(header)
<< " pos: " << mqtt::qos::to_str(mqtt::publish::get_qos(header))
Expand Down Expand Up @@ -195,15 +195,15 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
// set MQTT level handlers
ep.set_connect_handler(
[&]
(mqtt::string_view client_id,
mqtt::optional<mqtt::string_view> username,
mqtt::optional<mqtt::string_view> password,
(mqtt::buffer client_id,
mqtt::optional<mqtt::buffer> username,
mqtt::optional<mqtt::buffer> password,
mqtt::optional<mqtt::will>,
bool clean_session,
std::uint16_t keep_alive) {
std::cout << "[server] client_id : " << client_id << std::endl;
std::cout << "[server] username : " << (username ? username.value() : "none") << std::endl;
std::cout << "[server] password : " << (password ? password.value() : "none") << std::endl;
std::cout << "[server] username : " << (username ? username.value() : mqtt::buffer("none")) << std::endl;
std::cout << "[server] password : " << (password ? password.value() : mqtt::buffer("none")) << std::endl;
std::cout << "[server] clean_session: " << std::boolalpha << clean_session << std::endl;
std::cout << "[server] keep_alive : " << keep_alive << std::endl;
connections.insert(ep.shared_from_this());
Expand Down Expand Up @@ -245,8 +245,8 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::uint8_t qos = mqtt::publish::get_qos(header);
bool retain = mqtt::publish::is_retain(header);
std::cout << "[server] publish received."
Expand All @@ -272,12 +272,12 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
ep.set_subscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<std::tuple<mqtt::string_view, std::uint8_t>> entries) {
std::vector<std::tuple<mqtt::buffer, std::uint8_t>> entries) {
std::cout << "[server]subscribe received. packet_id: " << packet_id << std::endl;
std::vector<std::uint8_t> res;
res.reserve(entries.size());
for (auto const& e : entries) {
mqtt::string_view topic = std::get<0>(e);
mqtt::buffer topic = std::get<0>(e);
std::uint8_t qos = std::get<1>(e);
std::cout << "[server] topic: " << topic << " qos: " << static_cast<int>(qos) << std::endl;
res.emplace_back(qos);
Expand All @@ -290,7 +290,7 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
ep.set_unsubscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<mqtt::string_view> topics) {
std::vector<mqtt::buffer> topics) {
std::cout << "[server]unsubscribe received. packet_id: " << packet_id << std::endl;
for (auto const& topic : topics) {
subs.erase(std::string(topic));
Expand Down
4 changes: 2 additions & 2 deletions example/no_tls_ws_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ int main(int argc, char** argv) {
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::cout << "publish received. "
<< "dup: " << std::boolalpha << mqtt::publish::is_dup(header)
<< " pos: " << mqtt::qos::to_str(mqtt::publish::get_qos(header))
Expand Down
20 changes: 10 additions & 10 deletions example/no_tls_ws_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ int main(int argc, char** argv) {
// set MQTT level handlers
ep.set_connect_handler(
[&]
(mqtt::string_view client_id,
mqtt::optional<mqtt::string_view> username,
mqtt::optional<mqtt::string_view> password,
(mqtt::buffer client_id,
mqtt::optional<mqtt::buffer> username,
mqtt::optional<mqtt::buffer> password,
mqtt::optional<mqtt::will>,
bool clean_session,
std::uint16_t keep_alive) {
std::cout << "client_id : " << client_id << std::endl;
std::cout << "username : " << (username ? username.value() : "none") << std::endl;
std::cout << "password : " << (password ? password.value() : "none") << std::endl;
std::cout << "username : " << (username ? username.value() : mqtt::buffer("none")) << std::endl;
std::cout << "password : " << (password ? password.value() : mqtt::buffer("none")) << std::endl;
std::cout << "clean_session: " << std::boolalpha << clean_session << std::endl;
std::cout << "keep_alive : " << keep_alive << std::endl;
connections.insert(ep.shared_from_this());
Expand Down Expand Up @@ -157,8 +157,8 @@ int main(int argc, char** argv) {
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::uint8_t qos = mqtt::publish::get_qos(header);
bool retain = mqtt::publish::is_retain(header);
std::cout << "publish received."
Expand All @@ -184,12 +184,12 @@ int main(int argc, char** argv) {
ep.set_subscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<std::tuple<mqtt::string_view, std::uint8_t>> entries) {
std::vector<std::tuple<mqtt::buffer, std::uint8_t>> entries) {
std::cout << "subscribe received. packet_id: " << packet_id << std::endl;
std::vector<std::uint8_t> res;
res.reserve(entries.size());
for (auto const& e : entries) {
mqtt::string_view topic = std::get<0>(e);
mqtt::buffer topic = std::get<0>(e);
std::uint8_t qos = std::get<1>(e);
std::cout << "topic: " << topic << " qos: " << static_cast<int>(qos) << std::endl;
res.emplace_back(qos);
Expand All @@ -202,7 +202,7 @@ int main(int argc, char** argv) {
ep.set_unsubscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<mqtt::string_view> topics) {
std::vector<mqtt::buffer> topics) {
std::cout << "unsubscribe received. packet_id: " << packet_id << std::endl;
for (auto const& topic : topics) {
subs.erase(std::string(topic));
Expand Down
24 changes: 12 additions & 12 deletions example/tls_both.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ void client_proc(
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::cout << "[client] publish received. "
<< "dup: " << std::boolalpha << mqtt::publish::is_dup(header)
<< " pos: " << mqtt::qos::to_str(mqtt::publish::get_qos(header))
Expand Down Expand Up @@ -197,15 +197,15 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
// set MQTT level handlers
ep.set_connect_handler(
[&]
(mqtt::string_view client_id,
mqtt::optional<mqtt::string_view> username,
mqtt::optional<mqtt::string_view> password,
(mqtt::buffer client_id,
mqtt::optional<mqtt::buffer> username,
mqtt::optional<mqtt::buffer> password,
mqtt::optional<mqtt::will>,
bool clean_session,
std::uint16_t keep_alive) {
std::cout << "[server]client_id : " << client_id << std::endl;
std::cout << "[server]username : " << (username ? username.value() : "none") << std::endl;
std::cout << "[server]password : " << (password ? password.value() : "none") << std::endl;
std::cout << "[server]username : " << (username ? username.value() : mqtt::buffer("none")) << std::endl;
std::cout << "[server]password : " << (password ? password.value() : mqtt::buffer("none")) << std::endl;
std::cout << "[server]clean_session: " << std::boolalpha << clean_session << std::endl;
std::cout << "[server]keep_alive : " << keep_alive << std::endl;
connections.insert(ep.shared_from_this());
Expand Down Expand Up @@ -247,8 +247,8 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
[&]
(std::uint8_t header,
mqtt::optional<packet_id_t> packet_id,
mqtt::string_view topic_name,
mqtt::string_view contents){
mqtt::buffer topic_name,
mqtt::buffer contents){
std::uint8_t qos = mqtt::publish::get_qos(header);
bool retain = mqtt::publish::is_retain(header);
std::cout << "[server]publish received."
Expand All @@ -274,12 +274,12 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
ep.set_subscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<std::tuple<mqtt::string_view, std::uint8_t>> entries) {
std::vector<std::tuple<mqtt::buffer, std::uint8_t>> entries) {
std::cout << "[server]subscribe received. packet_id: " << packet_id << std::endl;
std::vector<std::uint8_t> res;
res.reserve(entries.size());
for (auto const& e : entries) {
mqtt::string_view topic = std::get<0>(e);
mqtt::buffer topic = std::get<0>(e);
std::uint8_t qos = std::get<1>(e);
std::cout << "[server]topic: " << topic << " qos: " << static_cast<int>(qos) << std::endl;
res.emplace_back(qos);
Expand All @@ -292,7 +292,7 @@ void server_proc(Server& s, std::set<con_sp_t>& connections, mi_sub_con& subs) {
ep.set_unsubscribe_handler(
[&]
(packet_id_t packet_id,
std::vector<mqtt::string_view> topics) {
std::vector<mqtt::buffer> topics) {
std::cout << "[server]unsubscribe received. packet_id: " << packet_id << std::endl;
for (auto const& topic : topics) {
subs.erase(std::string(topic));
Expand Down
Loading