Skip to content

Commit

Permalink
add doc_shared method
Browse files Browse the repository at this point in the history
  • Loading branch information
lichuan committed Sep 1, 2018
1 parent 6d5e1bc commit 07d10d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/fly/net/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ namespace net {
Message<Json>::Message(std::shared_ptr<Connection<Json>> connection)
{
m_connection = connection;
m_doc = std::make_shared<rapidjson::Document>();
}

rapidjson::Document& Message<Json>::doc()
{
return *m_doc;
}

std::shared_ptr<rapidjson::Document> Message<Json>::doc_shared()
{
return m_doc;
}
Expand Down Expand Up @@ -64,9 +70,15 @@ std::shared_ptr<Connection<Json>> Message<Json>::get_connection()
Message<Proto>::Message(std::shared_ptr<Connection<Proto>> connection)
{
m_connection = connection;
m_doc = std::make_shared<rapidjson::Document>();
}

rapidjson::Document& Message<Proto>::doc()
{
return *m_doc;
}

std::shared_ptr<rapidjson::Document> Message<Proto>::doc_shared()
{
return m_doc;
}
Expand Down Expand Up @@ -100,9 +112,15 @@ std::shared_ptr<Connection<Proto>> Message<Proto>::get_connection()
Message<Wsock>::Message(std::shared_ptr<Connection<Wsock>> connection)
{
m_connection = connection;
m_doc = std::make_shared<rapidjson::Document>();
}

rapidjson::Document& Message<Wsock>::doc()
{
return *m_doc;
}

std::shared_ptr<rapidjson::Document> Message<Wsock>::doc_shared()
{
return m_doc;
}
Expand Down
9 changes: 6 additions & 3 deletions src/fly/net/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ class Message<Json>
public:
Message(std::shared_ptr<Connection<Json>> connection);
rapidjson::Document& doc();
std::shared_ptr<rapidjson::Document> doc_shared();
const std::string& raw_data();
uint32 type();
uint32 cmd();
uint32 length();
std::shared_ptr<Connection<Json>> get_connection();

private:
rapidjson::Document m_doc;
std::shared_ptr<rapidjson::Document> m_doc;
std::shared_ptr<Connection<Json>> m_connection;
std::string m_raw_data;
uint32 m_length;
Expand All @@ -78,14 +79,15 @@ class Message<Proto>
public:
Message(std::shared_ptr<Connection<Proto>> connection);
rapidjson::Document& doc();
std::shared_ptr<rapidjson::Document> doc_shared();
const std::string& raw_data();
uint32 type();
uint32 cmd();
uint32 length();
std::shared_ptr<Connection<Proto>> get_connection();

private:
rapidjson::Document m_doc;
std::shared_ptr<rapidjson::Document> m_doc;
std::shared_ptr<Connection<Proto>> m_connection;
std::string m_raw_data;
uint32 m_length;
Expand All @@ -101,14 +103,15 @@ class Message<Wsock>
public:
Message(std::shared_ptr<Connection<Wsock>> connection);
rapidjson::Document& doc();
std::shared_ptr<rapidjson::Document> doc_shared();
const std::string& raw_data();
uint32 type();
uint32 cmd();
uint32 length();
std::shared_ptr<Connection<Wsock>> get_connection();

private:
rapidjson::Document m_doc;
std::shared_ptr<rapidjson::Document> m_doc;
std::shared_ptr<Connection<Wsock>> m_connection;
std::string m_raw_data;
uint32 m_length;
Expand Down

0 comments on commit 07d10d5

Please sign in to comment.