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

Added convenience method for sending DTO's via WebSocket. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion src/oatpp-websocket/WebSocket.cpp
Original file line number Diff line number Diff line change
@@ -388,5 +388,10 @@ void WebSocket::sendOneFrameBinary(const oatpp::String& message) const {
throw std::runtime_error("[oatpp::web::protocol::websocket::WebSocket::sendOneFrameBinary()]: Unknown error while writing to socket.");
}
}


void WebSocket::sendOneFrameDto(const Void &dto,
const std::shared_ptr<oatpp::data::mapping::ObjectMapper> &objectMapper) const {
sendOneFrameText(objectMapper->writeToString(dto));
}

}}
9 changes: 9 additions & 0 deletions src/oatpp-websocket/WebSocket.hpp
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@

#include "oatpp/core/data/stream/BufferStream.hpp"
#include "oatpp/core/provider/Provider.hpp"
#include "oatpp/core/data/mapping/ObjectMapper.hpp"
#include "oatpp/core/macro/component.hpp"

namespace oatpp { namespace websocket {

@@ -271,6 +273,13 @@ class WebSocket : public oatpp::base::Countable {
* @throws - `runtime_error`.
*/
void sendOneFrameBinary(const oatpp::String& message) const;

/**
* Send one-frame dto message.
* @param message - message dto. &id:oatpp::data::mapping::type::Void;.
* @throws - `runtime_error`.
*/
void sendOneFrameDto(const oatpp::data::mapping::type::Void& dto, const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper = OATPP_GET_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>)) const;

};