Eile Mit Weile
Loading...
Searching...
No Matches
ServerResponse.hpp
Go to the documentation of this file.
1#ifndef EILE_MIT_WEILE_SERVERRESPONSE_HPP
2#define EILE_MIT_WEILE_SERVERRESPONSE_HPP
3
4#include <string>
5#include <unordered_map>
6
7#include "common/serialization/serializable.hpp"
18 req_response,
19 state_diff_msg,
20 full_state_msg
21};
22
34private:
35
36 // for deserialization
37 static const std::unordered_map<std::string, ResponseType> _string_to_response_type;
38 // for serialization
39 static const std::unordered_map<ResponseType, std::string> _response_type_to_string;
41protected:
42 std::string _game_id;
49 std::string game_id;
50 ResponseType type;
51 };
52
54 static BaseClassProperties CreateBaseClassProperties(ResponseType type, const std::string& game_id);
55 static BaseClassProperties ExtractBaseClassProperties(const rapidjson::Value& json);
57public:
58 [[nodiscard]] ResponseType GetType() const;
59 [[nodiscard]] std::string GetGameId() const;
61 static ServerResponse* FromJson(const rapidjson::Value& json);
69 void WriteIntoJson(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override;
71 virtual void Process() const {};
75};
76
77
78#endif //EILE_MIT_WEILE_SERVERRESPONSE_HPP
ResponseType
Identifier for the different server responses.
Definition ServerResponse.hpp:17
Abstract Base Class for a serializable object.
Definition serializable.hpp:17
Base class for all messages sent from the server to the client.
Definition ServerResponse.hpp:33
static const std::unordered_map< ResponseType, std::string > _response_type_to_string
Definition ServerResponse.hpp:14
std::string _game_id
Definition ServerResponse.hpp:42
ResponseType _type
Definition ServerResponse.hpp:43
static BaseClassProperties ExtractBaseClassProperties(const rapidjson::Value &json)
Definition ServerResponse.cpp:42
static BaseClassProperties CreateBaseClassProperties(ResponseType type, const std::string &game_id)
Definition ServerResponse.cpp:35
ServerResponse(const BaseClassProperties &)
Definition ServerResponse.cpp:20
std::string GetGameId() const
Definition ServerResponse.cpp:29
ResponseType GetType() const
Definition ServerResponse.cpp:25
static ServerResponse * FromJson(const rapidjson::Value &json)
Definition ServerResponse.cpp:57
static const std::unordered_map< std::string, ResponseType > _string_to_response_type
Definition ServerResponse.hpp:8
void WriteIntoJson(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
Definition ServerResponse.cpp:75
Contains the properties that are common to all ServerResponses.
Definition ServerResponse.hpp:48