|
TT Client Library 1.0.0
C++ library for Tandem Tales clients.
|
A helper class for deserializing messages.
More...
#include <tt/io/MessageFactory.h>
Public Types | |
| using | Creator = std::function<std::unique_ptr<tt::Message>(const nlohmann::json&)> |
| Type alias to simplify code. | |
Public Member Functions | |
| void | registerType (const std::string &type, Creator creator) |
| Register a type with the message factory. | |
| std::unique_ptr< tt::Message > | create (const std::string &type, const nlohmann::json &j) const |
| Looks up the creator of the desired type to deserialize json. | |
Static Public Member Functions | |
| static MessageFactory & | instance () |
| MessageFactory singleton. | |
A helper class for deserializing messages.
This class helps the client create an object of the correct Message type for incoming JSON.
Custom clients should not need to use this class or any of its member functions, as message receiving is already built into the Client class.
|
inline |
Looks up the creator of the desired type to deserialize json.
Uses the createFromJson functions generated for each type.
| type | the name of the type |
| j | json serialization of the message |
|
inline |
Register a type with the message factory.
This is called when the first tt::Client is created.
| type | the name of the type |
| creator | a function to create an object of that type |