AppChat  0.5.0
TCP client-server caht application with boost::asio library.
response.h
1 #ifndef IRESPONSE_H
2 #define IRESPONSE_H
3 
4 #include "protocol/command_table.h"
5 
6 class Response: public IPacket
7 {
8 public:
9  virtual ~Response() {}
10 
11  Response() {
12  std::memcpy(header, &PROTOCOL_VERS, Block::VersionProtocol);
13 
14  DateTime datetime(boost::posix_time::second_clock::universal_time());
15 
16  std::memcpy(header + Block::VersionProtocol + Block::Command, &datetime, Block::Datetime);
17  }
18 
19  virtual const void* get_header() const override { return header; }
20  virtual void* get_header() override { return header; }
21  virtual const void* get_data() const override { return nullptr; }
22  virtual void* get_data() override { return nullptr; }
23 
24  virtual uint16_t get_protocol_version() const override { return *(uint16_t*)header; }
25 
26  virtual TypeCommand get_type() const override { return TypeCommand::Unknown; }
27  virtual TypeCommand get_type_data() const override { return (TypeCommand) *(header + Block::VersionProtocol); }
28 
29  virtual DateTime get_datetime() const override
30  {
31  DateTime dt;
32  std::memcpy(&dt, header + Block::VersionProtocol + Block::Command, Block::Datetime);
33  return dt;
34  }
35 
36  virtual uint32_t get_length_data() const override { return 0; }
37 
38 protected:
39  char header[Block::Header];
40 };
41 
42 using response_ptr = std::shared_ptr<Response>;
43 
44 #endif // IRESPONSE_H
Definition: response.h:6
Definition: datetime.h:6
Definition: command_table.h:73