AppChat  0.5.0
TCP client-server caht application with boost::asio library.
input_response.h
1 #ifndef CONTROLRESPONSE_H
2 #define CONTROLRESPONSE_H
3 
4 #include "response.h"
5 
6 class InputResponse : public Response {
7 public:
8  InputResponse() {
9  std::memcpy(__data, &PROTOCOL_VERS, Block::VersionProtocol);
10  std::memcpy(__data+Block::VersionProtocol, &type_response, Block::Command);
11  }
12 
13  virtual const void* get_data() const override { return __data; }
14  virtual void* get_data() override { return __data; }
15 
16  virtual identifier_t get_loginid() const {
17  return *(identifier_t *)(__data);
18  }
19  virtual uint32_t get_length_data() const override { return LengthResponse;}
20  virtual void set_loginid(identifier_t id = 0) {
21  std::memcpy(__data, &id, Block::LoginId);
22  }
23 protected:
24  const TypeCommand type_response = TypeCommand::Unknown;
25  static constexpr auto LengthResponse = Block::LoginId;
26  char __data[LengthResponse];
27 };
28 
29 // *************************************************************************************************
35 public:
37  std::memcpy(header, &PROTOCOL_VERS, Block::VersionProtocol);
38  std::memcpy(header+Block::VersionProtocol, &type_response, Block::Command);
39  }
40  RegistrationResponse(identifier_t id) {
41  std::memcpy(header, &PROTOCOL_VERS, Block::VersionProtocol);
42  std::memcpy(header+Block::VersionProtocol, &type_response, Block::Command);
43  std::memcpy(__data, &id, Block::LoginId);
44  }
45 
46 private:
47  const TypeCommand type_response = TypeCommand::RegistrationResponse;
48 };
49 
55 public:
57  std::memcpy(header, &PROTOCOL_VERS, Block::VersionProtocol);
58  std::memcpy(header+Block::VersionProtocol, &type_response, Block::Command);
59  }
60  AutorisationResponse(identifier_t id) {
61  std::memcpy(header, &PROTOCOL_VERS, Block::VersionProtocol);
62  std::memcpy(header+Block::VersionProtocol, &type_response, Block::Command);
63  std::memcpy(__data, &id, Block::LoginId);
64  }
65  AutorisationResponse(const Response& packet) {
66  std::memcpy(header, packet.get_data(), Block::Header);
67  }
68  AutorisationResponse(response_ptr packet) {
69  std::memcpy(header, packet->get_data(), Block::Header);
70  }
71 private:
72  const TypeCommand type_response = TypeCommand::AutorisationResponse;
73 };
74 
75 using response_ptr = std::shared_ptr<Response>;
76 using input_res_ptr = std::shared_ptr<InputResponse>;
77 using registr_response_ptr = std::shared_ptr<RegistrationResponse>;
78 using autor_response_ptr = std::shared_ptr<AutorisationResponse>;
79 
80 #endif // CONTROLRESPONSE_H
Definition: response.h:6
The RegistrationResponse class.
Definition: input_response.h:34
Definition: input_response.h:6
The AutorisationResponse class.
Definition: input_response.h:54