protocol: Remove the Packet class

It doesn't need to exist
This commit is contained in:
Joshua Scott 2018-04-09 21:49:11 +01:00
parent 2f51a53cb3
commit 611943e3ad
6 changed files with 27 additions and 71 deletions

View File

@ -1,7 +1,5 @@
#pragma once
#include "../../util/Serializable.h"
#include "../Packet.h"
#include "Opcode.h"
#include <iostream>
#include <cstdint>
@ -15,14 +13,14 @@ namespace control
{
public:
ClientHello(uint16_t session_id = 0,
uint32_t timestamp = 0, uint32_t milliseconds = 0);
int32_t timestamp = 0, uint32_t milliseconds = 0);
virtual ~ClientHello() = default;
uint16_t get_session_id() const;
void set_session_id(uint16_t session_id);
uint32_t get_timestamp() const;
void set_timestamp(uint32_t timestamp);
int32_t get_timestamp() const;
void set_timestamp(int32_t timestamp);
uint32_t get_milliseconds() const;
void set_milliseconds(uint32_t milliseconds);
@ -30,12 +28,9 @@ namespace control
void write_to(std::ostream &ostream) const override final;
void read_from(std::istream &istream) override final;
size_t get_size() const override final;
static Packet *create_packet(uint16_t session_id = 0,
uint32_t timestamp = 0, uint32_t milliseconds = 0);
private:
uint16_t m_session_id;
uint32_t m_timestamp;
int32_t m_timestamp;
uint32_t m_milliseconds;
};
}

View File

@ -1,7 +1,5 @@
#pragma once
#include "../../util/Serializable.h"
#include "../Packet.h"
#include "Opcode.h"
#include <cstdint>
namespace ki
@ -29,10 +27,6 @@ namespace control
void write_to(std::ostream &ostream) const override final;
void read_from(std::istream &istream) override final;
size_t get_size() const override final;
static Packet *create_packet(uint16_t session_id = 0,
uint16_t milliseconds = 0, uint8_t minutes = 0,
bool response = false);
private:
uint16_t m_session_id;
uint16_t m_milliseconds;

View File

@ -1,7 +1,5 @@
#pragma once
#include "../../util/Serializable.h"
#include "../Packet.h"
#include "Opcode.h"
#include <iostream>
#include <cstdint>
@ -15,14 +13,14 @@ namespace control
{
public:
ServerHello(uint16_t session_id = 0,
uint32_t timestamp = 0, uint32_t milliseconds = 0);
int32_t timestamp = 0, uint32_t milliseconds = 0);
virtual ~ServerHello() = default;
uint16_t get_session_id() const;
void set_session_id(uint16_t session_id);
uint32_t get_timestamp() const;
void set_timestamp(uint32_t timestamp);
int32_t get_timestamp() const;
void set_timestamp(int32_t timestamp);
uint32_t get_milliseconds() const;
void set_milliseconds(uint32_t milliseconds);
@ -30,12 +28,9 @@ namespace control
void write_to(std::ostream &ostream) const override final;
void read_from(std::istream &istream) override final;
size_t get_size() const override final;
static Packet *create_packet(uint16_t session_id = 0,
uint32_t timestamp = 0, uint32_t milliseconds = 0);
private:
uint16_t m_session_id;
uint32_t m_timestamp;
int32_t m_timestamp;
uint32_t m_milliseconds;
};
}

View File

@ -7,8 +7,8 @@ namespace protocol
{
namespace control
{
ClientHello::ClientHello(uint16_t session_id,
uint32_t timestamp, uint32_t milliseconds)
ClientHello::ClientHello(const uint16_t session_id,
const int32_t timestamp, const uint32_t milliseconds)
{
m_session_id = session_id;
m_timestamp = timestamp;
@ -20,17 +20,17 @@ namespace control
return m_session_id;
}
void ClientHello::set_session_id(uint16_t session_id)
void ClientHello::set_session_id(const uint16_t session_id)
{
m_session_id = session_id;
}
uint32_t ClientHello::get_timestamp() const
int32_t ClientHello::get_timestamp() const
{
return m_timestamp;
}
void ClientHello::set_timestamp(uint32_t timestamp)
void ClientHello::set_timestamp(const int32_t timestamp)
{
m_timestamp = timestamp;
}
@ -40,7 +40,7 @@ namespace control
return m_milliseconds;
}
void ClientHello::set_milliseconds(uint32_t milliseconds)
void ClientHello::set_milliseconds(const uint32_t milliseconds)
{
m_milliseconds = milliseconds;
}
@ -50,7 +50,7 @@ namespace control
dml::Record record;
record.add_field<dml::USHRT>("unknown");
record.add_field<dml::UINT>("unknown2");
record.add_field<dml::UINT>("m_timestamp")->set_value(m_timestamp);
record.add_field<dml::INT>("m_timestamp")->set_value(m_timestamp);
record.add_field<dml::UINT>("m_milliseconds")->set_value(m_milliseconds);
record.add_field<dml::USHRT>("m_session_id")->set_value(m_session_id);
record.write_to(ostream);
@ -61,7 +61,7 @@ namespace control
dml::Record record;
record.add_field<dml::USHRT>("unknown");
record.add_field<dml::UINT>("unknown2");
auto *timestamp = record.add_field<dml::UINT>("m_timestamp");
auto *timestamp = record.add_field<dml::INT>("m_timestamp");
auto *milliseconds = record.add_field<dml::UINT>("m_milliseconds");
auto *session_id = record.add_field<dml::USHRT>("m_session_id");
record.read_from(istream);
@ -74,18 +74,9 @@ namespace control
size_t ClientHello::get_size() const
{
return sizeof(dml::USHRT) + sizeof(dml::UINT) +
sizeof(dml::UINT) + sizeof(dml::UINT) +
sizeof(dml::INT) + sizeof(dml::UINT) +
sizeof(dml::USHRT);
}
Packet *ClientHello::create_packet(uint16_t session_id,
uint32_t timestamp, uint32_t milliseconds)
{
const ClientHello data(session_id, timestamp, milliseconds);
auto *packet = new Packet(true, (uint8_t)Opcode::CLIENT_HELLO);
packet->set_payload_data(data);
return packet;
}
}
}
}

View File

@ -71,16 +71,6 @@ namespace control
return sizeof(dml::USHRT) + sizeof(dml::USHRT) +
sizeof(dml::UBYT);
}
Packet* Ping::create_packet(uint16_t session_id,
uint16_t milliseconds, uint8_t minutes, bool response)
{
const Ping data(session_id, milliseconds, minutes);
auto *packet = new Packet(true,
(uint8_t)(response ? Opcode::PING_RSP : Opcode::PING));
packet->set_payload_data(data);
return packet;
}
}
}
}

View File

@ -7,8 +7,8 @@ namespace protocol
{
namespace control
{
ServerHello::ServerHello(uint16_t session_id,
uint32_t timestamp, uint32_t milliseconds)
ServerHello::ServerHello(const uint16_t session_id,
const int32_t timestamp, const uint32_t milliseconds)
{
m_session_id = session_id;
m_timestamp = timestamp;
@ -20,17 +20,17 @@ namespace control
return m_session_id;
}
void ServerHello::set_session_id(uint16_t session_id)
void ServerHello::set_session_id(const uint16_t session_id)
{
m_session_id = session_id;
}
uint32_t ServerHello::get_timestamp() const
int32_t ServerHello::get_timestamp() const
{
return m_timestamp;
}
void ServerHello::set_timestamp(uint32_t timestamp)
void ServerHello::set_timestamp(const int32_t timestamp)
{
m_timestamp = timestamp;
}
@ -40,7 +40,7 @@ namespace control
return m_milliseconds;
}
void ServerHello::set_milliseconds(uint32_t milliseconds)
void ServerHello::set_milliseconds(const uint32_t milliseconds)
{
m_milliseconds = milliseconds;
}
@ -50,7 +50,7 @@ namespace control
dml::Record record;
record.add_field<dml::USHRT>("m_session_id")->set_value(m_session_id);
record.add_field<dml::UINT>("unknown");
record.add_field<dml::UINT>("m_timestamp")->set_value(m_timestamp);
record.add_field<dml::INT>("m_timestamp")->set_value(m_timestamp);
record.add_field<dml::UINT>("m_milliseconds")->set_value(m_milliseconds);
record.write_to(ostream);
}
@ -60,7 +60,7 @@ namespace control
dml::Record record;
auto *session_id = record.add_field<dml::USHRT>("m_session_id");
record.add_field<dml::UINT>("unknown");
auto *timestamp = record.add_field<dml::UINT>("m_timestamp");
auto *timestamp = record.add_field<dml::INT>("m_timestamp");
auto *milliseconds = record.add_field<dml::UINT>("m_milliseconds");
record.read_from(istream);
@ -71,17 +71,8 @@ namespace control
size_t ServerHello::get_size() const
{
return sizeof(dml::USHRT) + sizeof(dml::GID) +
sizeof(dml::UINT);
}
Packet *ServerHello::create_packet(uint16_t session_id,
uint32_t timestamp, uint32_t milliseconds)
{
const ServerHello data(session_id, timestamp, milliseconds);
auto *packet = new Packet(true, (uint8_t)Opcode::SERVER_HELLO);
packet->set_payload_data(data);
return packet;
return sizeof(dml::USHRT) + sizeof(dml::UINT) +
sizeof(dml::INT) + sizeof(dml::UINT);
}
}
}