29#ifndef HORIZON_BASE_NETWORKPACKET_HPP
30#define HORIZON_BASE_NETWORKPACKET_HPP
41template <
class SessionType>
45 explicit NetworkPacket(uint16_t packet_id, std::shared_ptr<SessionType> s)
93template <
class SessionType>
96 transmit(this->_buffer.active_length());
105template <
class SessionType>
108 std::shared_ptr<SessionType> s = this->get_session();
110 HLog(debug) <<
"NetworkPacket::transmit: Session was null.";
114 if (this->_buffer.is_empty()) {
115 HLog(debug) <<
"Attempted to transmit empty buffer.";
119 s->transmit_buffer(std::move(this->_buffer), size);
#define HLog(type)
Definition: Logger.hpp:122
Definition: ByteBuffer.hpp:78
Definition: NetworkPacket.hpp:43
ByteBuffer _buffer
Buffer storage facility for the packet stream.
Definition: NetworkPacket.hpp:86
void transmit(std::size_t size)
Send an Asynchronous packet by queueing a buffer of a particular size to the connected session.
Definition: NetworkPacket.hpp:106
void transmit()
Send an Asynchronous packet by queueing a buffer of a particular size to the connected session.
Definition: NetworkPacket.hpp:94
std::weak_ptr< SessionType > _session
Pointer to the instantiated session object.
Definition: NetworkPacket.hpp:90
uint16_t _packet_id
ID of the network packet.
Definition: NetworkPacket.hpp:87
virtual void deserialize(ByteBuffer &buf)
Definition: NetworkPacket.hpp:68
std::shared_ptr< SessionType > get_session()
Retrieves the session from this handler instance.
Definition: NetworkPacket.hpp:65
NetworkPacket(uint16_t packet_id, std::shared_ptr< SessionType > s)
Definition: NetworkPacket.hpp:45
virtual void handle(ByteBuffer &&buf)
Definition: NetworkPacket.hpp:67
uint16_t get_packet_id()
Definition: NetworkPacket.hpp:57
void set_packet_id(uint16_t id)
Definition: NetworkPacket.hpp:56
virtual ~NetworkPacket()
Definition: NetworkPacket.hpp:51
ByteBuffer & buf()
Definition: NetworkPacket.hpp:59
Definition: Element.hpp:7