Commit 22805a1c by amir

add binary serializer and IConnection

ver 1.1.0
parent b7df6507
...@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.12) ...@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)
project(Microservice) project(Microservice)
# version stuff # version stuff
set (Microservice_VERSION_MAJOR 1) set (Microservice_VERSION_MAJOR 1)
set (Microservice_VERSION_MINOR 0) set (Microservice_VERSION_MINOR 1)
set (Microservice_VERSION_PATCH 0) set (Microservice_VERSION_PATCH 0)
set(Microservice_VERSION_STRING ${Microservice_VERSION_MAJOR}.${Microservice_VERSION_MINOR}.${Microservice_VERSION_PATCH}) set(Microservice_VERSION_STRING ${Microservice_VERSION_MAJOR}.${Microservice_VERSION_MINOR}.${Microservice_VERSION_PATCH})
...@@ -92,6 +92,9 @@ install(FILES ${INSTALL_FILES} DESTINATION include/microservice/impl/servers) ...@@ -92,6 +92,9 @@ install(FILES ${INSTALL_FILES} DESTINATION include/microservice/impl/servers)
# src/handlers # src/handlers
file (GLOB INSTALL_FILES "src/handlers/*.h") file (GLOB INSTALL_FILES "src/handlers/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/handlers) install(FILES ${INSTALL_FILES} DESTINATION include/microservice/handlers)
# src/utils
file (GLOB INSTALL_FILES "src/utils/*.h")
install(FILES ${INSTALL_FILES} DESTINATION include/microservice/utils)
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
using namespace nsMicroservice_Iface; using namespace nsMicroservice_Iface;
typedef std::shared_ptr<cMicroservice_BaseRestResponse> BaseResponsePtr; typedef std::shared_ptr<cMicroservice_BaseRestResponse> BaseResponsePtr;
typedef std::shared_ptr<MSCommandParams> MSCommandParamsPtr; typedef std::shared_ptr<MSCommandParams> MSCommandParamsPtr;
typedef std::shared_ptr<IResponse> IResponsePtr; typedef std::shared_ptr<IResponse> IResponsePtr;
...@@ -72,6 +71,7 @@ struct ClientAsyncTaskParams ...@@ -72,6 +71,7 @@ struct ClientAsyncTaskParams
typedef std::shared_ptr<ClientAsyncTaskParams> ClientAsyncTaskParamsPtr; typedef std::shared_ptr<ClientAsyncTaskParams> ClientAsyncTaskParamsPtr;
static const char *const NOT_MSGQ_CLIENT = "Not a MsgQueue Client"; static const char *const NOT_MSGQ_CLIENT = "Not a MsgQueue Client";
static const char *const NOT_PUBSUB_CLIENT = "Not a PubSub Client"; static const char *const NOT_PUBSUB_CLIENT = "Not a PubSub Client";
......
...@@ -394,6 +394,20 @@ namespace nsMicroservice_Iface ...@@ -394,6 +394,20 @@ namespace nsMicroservice_Iface
virtual MSRetStat Send(Microservice_MsgQContext* p_msgCtx) = 0; virtual MSRetStat Send(Microservice_MsgQContext* p_msgCtx) = 0;
}; };
/**
* Channel used for full-duplex like web-socket
*/
struct IChannelClient : public IClient
{
using OnMessageCallback = std::function<void(const char* p_msg, int len)>;
using OnErrorCallback = std::function<void(std::string&, std::string&)>;
static constexpr const char* TYPE = "Channel";
virtual const char* getType() final { return TYPE; }
virtual MSRetStat InitRecv(OnMessageCallback msgCllback, OnErrorCallback errorCallback) = 0;
virtual MSRetStat Send(const char* p_msg) = 0;
};
struct IContext struct IContext
{ {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define MICROSERVICE_MICRISERVICE_IMSGARCHIVERCEREALIMPLSL_H #define MICROSERVICE_MICRISERVICE_IMSGARCHIVERCEREALIMPLSL_H
#include <common/Microservice_Iface.h> #include <common/Microservice_Iface.h>
#include <cereal/archives/binary.hpp>
template <typename Msg> template <typename Msg>
class Microservice_IMsgArchiverCerealJson : public nsMicroservice_Iface::IMsgArchiver<Msg> class Microservice_IMsgArchiverCerealJson : public nsMicroservice_Iface::IMsgArchiver<Msg>
...@@ -45,4 +46,42 @@ public: ...@@ -45,4 +46,42 @@ public:
} }
}; };
template <typename Msg>
class Microservice_IMsgArchiverCerealBin : public nsMicroservice_Iface::IMsgArchiver<Msg>
{
public:
virtual MSRetStat parse(std::string &inStr, Msg &outMsg) override {
MSRetStat retStat;
try {
std::stringstream ss;
ss << inStr;
{
cereal::BinaryInputArchive binInputArchive(ss);
binInputArchive(outMsg);
}
}
catch (std::exception exp){
retStat.SetError(exp.what());
}
return retStat;
}
virtual MSRetStat build(Msg &inMsg, std::string &outStr) override {
MSRetStat retStat;
try {
std::stringstream ss;
{
cereal::BinaryOutputArchive jsonOutputArchive(ss);
jsonOutputArchive(inMsg);
}
// I like to move it move it....
outStr = std::move(ss.str());
}
catch (std::exception exp){
retStat.SetError(exp.what());
}
return retStat;
}
};
#endif //MICROSERVICE_MICRISERVICE_IMSGARCHIVERCEREALIMPLSL_H #endif //MICROSERVICE_MICRISERVICE_IMSGARCHIVERCEREALIMPLSL_H
...@@ -50,7 +50,7 @@ bool MSICommandClientHttpImpl::BuildUrl(MSCommandParams* p_cmd_params, std::stri ...@@ -50,7 +50,7 @@ bool MSICommandClientHttpImpl::BuildUrl(MSCommandParams* p_cmd_params, std::stri
auto entity = p_cmd_params->GetEntity().c_str(); auto entity = p_cmd_params->GetEntity().c_str();
if(strncmp(entity,HTTP_SCHEME,HTTP_SCHEME_LEN) != 0) if(strncmp(entity,HTTP_SCHEME,HTTP_SCHEME_LEN) != 0)
unencoded_url.append(HTTP_SCHEME).append(entity); unencoded_url.append(HTTP_SCHEME);//.append(entity);
unencoded_url.append(entity); unencoded_url.append(entity);
// params // params
if(!p_cmd_params->GetParams().empty()) if(!p_cmd_params->GetParams().empty())
......
...@@ -84,8 +84,8 @@ bool cMicroservice_IRestServerMongooseImpl::build(std::string& appName, ...@@ -84,8 +84,8 @@ bool cMicroservice_IRestServerMongooseImpl::build(std::string& appName,
if(mpc_Param->getHost().compare(nsMicroservice_Constants::LOCALHOST) != 0) if(mpc_Param->getHost().compare(nsMicroservice_Constants::LOCALHOST) != 0)
{ {
str_hostport.assign(mpc_Param->getHost()); str_hostport.assign(mpc_Param->getHost());
str_hostport.append(":");
} }
str_hostport.append(":");
str_hostport.append(portStr.str()); str_hostport.append(portStr.str());
/* /*
* creating the server manager object * creating the server manager object
......
...@@ -146,7 +146,7 @@ int main(int argc, char *argv[]) { ...@@ -146,7 +146,7 @@ int main(int argc, char *argv[]) {
//test_pubsub(context); //test_pubsub(context);
//test_Cereal(); //test_Cereal();
// test_msgQ(); test_msgQ(context);
getchar(); getchar();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment