mirror of https://github.com/SeanOMik/libki.git
net: Session::send_packet was unnecessarily templated
This commit is contained in:
parent
599afed56f
commit
c4630ae970
|
@ -31,23 +31,10 @@ namespace net
|
||||||
uint16_t get_latency() const;
|
uint16_t get_latency() const;
|
||||||
|
|
||||||
bool is_alive() const;
|
bool is_alive() const;
|
||||||
|
|
||||||
|
void send_packet(bool is_control, control::Opcode opcode,
|
||||||
|
const util::Serializable &data);
|
||||||
protected:
|
protected:
|
||||||
template <typename DataT>
|
|
||||||
void send_packet(const bool is_control, const control::Opcode opcode,
|
|
||||||
const DataT &data)
|
|
||||||
{
|
|
||||||
static_assert(std::is_base_of<util::Serializable, DataT>::value,
|
|
||||||
"DataT must inherit Serializable.");
|
|
||||||
|
|
||||||
std::ostringstream ss;
|
|
||||||
PacketHeader header(is_control, (uint8_t)opcode);
|
|
||||||
header.write_to(ss);
|
|
||||||
data.write_to(ss);
|
|
||||||
|
|
||||||
const auto buffer = ss.str();
|
|
||||||
send_data(buffer.c_str(), buffer.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DataT>
|
template <typename DataT>
|
||||||
DataT read_data()
|
DataT read_data()
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,6 +60,18 @@ namespace net
|
||||||
).count() <= 10;
|
).count() <= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::send_packet(const bool is_control, const control::Opcode opcode,
|
||||||
|
const util::Serializable& data)
|
||||||
|
{
|
||||||
|
std::ostringstream ss;
|
||||||
|
PacketHeader header(is_control, (uint8_t)opcode);
|
||||||
|
header.write_to(ss);
|
||||||
|
data.write_to(ss);
|
||||||
|
|
||||||
|
const auto buffer = ss.str();
|
||||||
|
send_data(buffer.c_str(), buffer.length());
|
||||||
|
}
|
||||||
|
|
||||||
void Session::on_connected()
|
void Session::on_connected()
|
||||||
{
|
{
|
||||||
// If this is the server-side of a Session
|
// If this is the server-side of a Session
|
||||||
|
|
Loading…
Reference in New Issue