|
Eile Mit Weile
|
Base class for all messages sent from the server to the client. More...
#include <ServerResponse.hpp>
Classes | |
| struct | BaseClassProperties |
| Contains the properties that are common to all ServerResponses. More... | |
Public Member Functions | |
| ResponseType | GetType () const |
| std::string | GetGameId () const |
| void | WriteIntoJson (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override |
| virtual void | Process () const |
Public Member Functions inherited from Serializable | |
| virtual rapidjson::Document * | ToJson () const |
Static Public Member Functions | |
| static ServerResponse * | FromJson (const rapidjson::Value &json) |
Protected Member Functions | |
| ServerResponse (const BaseClassProperties &) | |
Static Protected Member Functions | |
| static BaseClassProperties | CreateBaseClassProperties (ResponseType type, const std::string &game_id) |
| static BaseClassProperties | ExtractBaseClassProperties (const rapidjson::Value &json) |
Protected Attributes | |
| std::string | _game_id |
| ResponseType | _type |
Static Private Attributes | |
| static const std::unordered_map< std::string, ResponseType > | _string_to_response_type |
| static const std::unordered_map< ResponseType, std::string > | _response_type_to_string |
Base class for all messages sent from the server to the client.
It offers a function to deserialize a ServerResponse subclass from a valid json. Note: This class design is taken from https://gitlab.ethz.ch/hraymond/cse-lama-example-project. RequestResponse and FullStateResponse are derivatives of ServerResponse. Due to static allocation, this base class can call its derivatives' FromJson methods. We think this is very bad design, but changing it would require a lot of refactoring so we decided to leave it as it is.
|
protected |
Constructor that assigns BaseClassProperties.
|
staticprotected |
Creates a BaseClassProperties object with the given parameters.
|
staticprotected |
Extracts the BaseClassProperties from the given json.
|
static |
Tries to create the specific server_response from the provided json (see RequestResponse::FromJson and FullStateResponse::FromJson). Note**: RequestResponse and FullStateResponse are derivatives of ServerResponse. Due to static allocation, this base class can call its derivatives' FromJson methods. We think this is very bad design, but changing it would require a lot of refactoring so we decided to leave it as it is.
Throws exception if parsing fails.
| std::string ServerResponse::GetGameId | ( | ) | const |
Returns the id of the game this ServerResponse is related to. See GameInstance::id.
| ResponseType ServerResponse::GetType | ( | ) | const |
Returns the ResponseType of this ServerResponse.
|
overridevirtual |
Serializes the ServerResponse into a json object that can be sent over the network.
Implements Serializable.
|
protected |
The id of the game this ServerResponse is related to. See GameInstance::id.
|
staticprivate |
Maps a ResponseType to a string. Used for serialization.
|
staticprivate |
Maps a string to a ResponseType. Used for deserialization.
|
protected |
The type of this ServerResponse. See ResponseType.