Skip to content

Commit

Permalink
misc fixes for message->json
Browse files Browse the repository at this point in the history
  • Loading branch information
getnamo committed Sep 24, 2016
1 parent 30448cc commit 15ae81d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
19 changes: 10 additions & 9 deletions Source/SocketIOClient/Private/SocketIOClientComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ void USocketIOClientComponent::Bind(FString Name)

sio::message::ptr USocketIOClientComponent::getMessage(const std::string& json)
{
std::lock_guard< std::mutex > guard(packetLock);
//std::lock_guard< std::mutex > guard(packetLock);
sio::message::ptr message;
manager.set_decode_callback([&](sio::packet const& p)
/*manager.set_decode_callback([&](sio::packet const& p)
{
message = p.get_message();
});
Expand All @@ -65,16 +65,17 @@ sio::message::ptr USocketIOClientComponent::getMessage(const std::string& json)
std::string payload = std::string("42") + json;
manager.put_payload(payload);
manager.reset();
manager.reset();*/
return message;
}

std::string USocketIOClientComponent::getJson(sio::message::ptr msg)
{
std::lock_guard< std::mutex > guard(packetLock);
std::stringstream ss;
sio::packet packet("/", msg);
manager.encode(packet, [&](bool isBinary, std::shared_ptr<const std::string> const& json)
std::string result;// = ss.str();
//std::lock_guard< std::mutex > guard(packetLock);
//std::stringstream ss;
//sio::packet packet("/", msg);
/*manager.encode(packet, [&](bool isBinary, std::shared_ptr<const std::string> const& json)
{
ss << *json;
assert(!isBinary);
Expand All @@ -96,6 +97,6 @@ std::string USocketIOClientComponent::getJson(sio::message::ptr msg)
if (index == std::string::npos) {
std::cerr << "Error decoding json object" << std::endl << " Body: " << result << std::endl;
return "";
}
return result.substr(index);
}*/
return result;//.substr(index);
}
5 changes: 3 additions & 2 deletions Source/SocketIOClient/Public/SocketIOClientComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent
sio::client PrivateClient;

private:
sio::packet_manager manager;
std::mutex packetLock;

//sio::packet_manager manager;
//std::mutex packetLock;
sio::message::ptr getMessage(const std::string& json);
std::string getJson(sio::message::ptr msg);
};

0 comments on commit 15ae81d

Please sign in to comment.