r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
rnp::Serializer Class Reference

Binary serializer for RNP protocol packets. More...

#include <Serializer.hpp>

+ Collaboration diagram for rnp::Serializer:

Public Member Functions

 Serializer ()
 Constructor.
 
 Serializer (std::size_t capacity)
 Constructor with initial capacity.
 
 Serializer (const std::vector< std::uint8_t > &data)
 Constructor from existing data.
 
void reset ()
 Reset the serializer for reuse.
 
const std::vector< std::uint8_t > & getData () const
 Get the serialized data.
 
std::size_t getSize () const
 Get the current size of serialized data.
 
void writeBytes (const void *data, std::size_t size)
 Write raw bytes.
 
void writeByte (std::uint8_t value)
 Write a single byte.
 
void writeUInt16 (std::uint16_t value)
 Write a 16-bit integer (network byte order)
 
void writeUInt32 (std::uint32_t value)
 Write a 32-bit integer (network byte order)
 
void writeFloat (float value)
 Write a float (network byte order)
 
void writeString (const std::string &str, std::size_t maxLength)
 Write a string with length prefix.
 
void readBytes (void *data, std::size_t size)
 Read raw bytes.
 
std::uint8_t readByte ()
 Read a single byte.
 
std::uint16_t readUInt16 ()
 Read a 16-bit integer (network byte order)
 
std::uint32_t readUInt32 ()
 Read a 32-bit integer (network byte order)
 
float readFloat ()
 Read a float (network byte order)
 
std::string readString (std::size_t maxLength)
 Read a string with length prefix.
 
void serializeHeader (const PacketHeader &header)
 Serialize packet header.
 
PacketHeader deserializeHeader ()
 Deserialize packet header.
 
void serializeConnect (const PacketConnect &packet)
 Serialize CONNECT packet.
 
PacketConnect deserializeConnect ()
 Deserialize CONNECT packet.
 
void serializeConnectAccept (const PacketConnectAccept &packet)
 Serialize CONNECT_ACCEPT packet.
 
PacketConnectAccept deserializeConnectAccept ()
 Deserialize CONNECT_ACCEPT packet.
 
void serializeDisconnect (const PacketDisconnect &packet)
 Serialize DISCONNECT packet.
 
PacketDisconnect deserializeDisconnect ()
 Deserialize DISCONNECT packet.
 
void serializeEntityState (const EntityState &entity)
 Serialize EntityState.
 
EntityState deserializeEntityState ()
 Deserialize EntityState.
 
void serializeWorldState (const PacketWorldState &packet)
 Serialize WORLD_STATE packet.
 
PacketWorldState deserializeWorldState ()
 Deserialize WORLD_STATE packet.
 
void serializePingPong (const PacketPingPong &packet)
 Serialize PING/PONG packet.
 
PacketPingPong deserializePingPong ()
 Deserialize PING/PONG packet.
 
void serializeError (const PacketError &packet)
 Serialize ERROR packet.
 
PacketError deserializeError ()
 Deserialize ERROR packet.
 
void serializeEventRecord (const EventRecord &event)
 Serialize EventRecord for ENTITY_EVENT packets.
 
EventRecord deserializeEventRecord ()
 Deserialize EventRecord from ENTITY_EVENT packets.
 
void serializeEntityEvents (const std::vector< EventRecord > &events)
 Serialize multiple EventRecords for ENTITY_EVENT packet.
 
std::vector< EventRecorddeserializeEntityEvents (std::size_t payloadSize)
 Deserialize multiple EventRecords from ENTITY_EVENT packet.
 
void serializeInputData (std::uint8_t keys, float mouseX, float mouseY, std::uint8_t mouseButtons, std::uint32_t timestamp)
 Serialize input data for INPUT events.
 
void deserializeInputData (std::uint8_t &keys, float &mouseX, float &mouseY, std::uint8_t &mouseButtons, std::uint32_t &timestamp)
 Deserialize input data from INPUT events.
 
EventRecord createDespawnEvent (std::uint32_t entityId)
 Create an EventRecord for despawn event.
 
void serializeLobbyInfo (const LobbyInfo &lobbyInfo)
 Serialize LobbyInfo structure.
 
LobbyInfo deserializeLobbyInfo ()
 Deserialize LobbyInfo structure.
 
void serializeLobbyListResponse (const PacketLobbyListResponse &packet)
 Serialize LOBBY_LIST_RESPONSE packet.
 
PacketLobbyListResponse deserializeLobbyListResponse ()
 Deserialize LOBBY_LIST_RESPONSE packet.
 
void serializeLobbyCreate (const PacketLobbyCreate &packet)
 Serialize LOBBY_CREATE packet.
 
PacketLobbyCreate deserializeLobbyCreate ()
 Deserialize LOBBY_CREATE packet.
 
void serializeLobbyCreateResponse (const PacketLobbyCreateResponse &packet)
 Serialize LOBBY_CREATE_RESPONSE packet.
 
PacketLobbyCreateResponse deserializeLobbyCreateResponse ()
 Deserialize LOBBY_CREATE_RESPONSE packet.
 
void serializeLobbyJoin (const PacketLobbyJoin &packet)
 Serialize LOBBY_JOIN packet.
 
PacketLobbyJoin deserializeLobbyJoin ()
 Deserialize LOBBY_JOIN packet.
 
void serializeLobbyJoinResponse (const PacketLobbyJoinResponse &packet)
 Serialize LOBBY_JOIN_RESPONSE packet.
 
PacketLobbyJoinResponse deserializeLobbyJoinResponse ()
 Deserialize LOBBY_JOIN_RESPONSE packet.
 
void serializeLobbyUpdate (const PacketLobbyUpdate &packet)
 Serialize LOBBY_UPDATE packet.
 
PacketLobbyUpdate deserializeLobbyUpdate ()
 Deserialize LOBBY_UPDATE packet.
 
void serializeGameStart (const PacketGameStart &packet)
 Serialize GAME_START packet.
 
PacketGameStart deserializeGameStart ()
 Deserialize GAME_START packet.
 
void serializeStartGameRequest (const PacketStartGameRequest &packet)
 Serialize START_GAME_REQUEST packet.
 
PacketStartGameRequest deserializeStartGameRequest ()
 Deserialize START_GAME_REQUEST packet.
 

Static Public Member Functions

static EventRecord createInputEvent (std::uint32_t entityId, std::uint8_t keys, float mouseX, float mouseY, std::uint8_t mouseButtons, std::uint32_t timestamp)
 Create an EventRecord for input data.
 
static EventRecord createSpawnEvent (std::uint32_t entityId, EntityType entityType, float x, float y)
 Create an EventRecord for spawn event.
 
static EventRecord createDamageEvent (std::uint32_t entityId, std::uint32_t damage, std::uint32_t sourceId=0)
 Create an EventRecord for damage event.
 
static EventRecord createScoreEvent (std::uint32_t entityId, std::uint32_t score)
 Create an EventRecord for score event.
 

Private Attributes

std::vector< std::uint8_t > buffer_
 
std::size_t writePos_
 
std::size_t readPos_
 

Detailed Description

Binary serializer for RNP protocol packets.

Definition at line 64 of file Serializer.hpp.

Constructor & Destructor Documentation

◆ Serializer() [1/3]

rnp::Serializer::Serializer ( )
inline

Constructor.

Definition at line 75 of file Serializer.hpp.

References buffer_, and rnp::MAX_PAYLOAD.

◆ Serializer() [2/3]

rnp::Serializer::Serializer ( std::size_t capacity)
inlineexplicit

Constructor with initial capacity.

Parameters
capacityInitial buffer capacity

Definition at line 86 of file Serializer.hpp.

References buffer_.

◆ Serializer() [3/3]

rnp::Serializer::Serializer ( const std::vector< std::uint8_t > & data)
inlineexplicit

Constructor from existing data.

Parameters
dataExisting data to deserialize

Definition at line 92 of file Serializer.hpp.

Member Function Documentation

◆ createDamageEvent()

static EventRecord rnp::Serializer::createDamageEvent ( std::uint32_t entityId,
std::uint32_t damage,
std::uint32_t sourceId = 0 )
inlinestatic

Create an EventRecord for damage event.

Parameters
entityIdEntity taking damage
damageAmount of damage
sourceIdSource entity causing damage
Returns
EventRecord for damage

Definition at line 653 of file Serializer.hpp.

References rnp::DAMAGE, getData(), rnp::EventRecord::type, and writeUInt32().

+ Here is the call graph for this function:

◆ createDespawnEvent()

EventRecord rnp::Serializer::createDespawnEvent ( std::uint32_t entityId)
inline

Create an EventRecord for despawn event.

Parameters
entityIdEntity to despawn
Returns
EventRecord for despawn

Definition at line 692 of file Serializer.hpp.

References rnp::DESPAWN, and rnp::EventRecord::type.

◆ createInputEvent()

static EventRecord rnp::Serializer::createInputEvent ( std::uint32_t entityId,
std::uint8_t keys,
float mouseX,
float mouseY,
std::uint8_t mouseButtons,
std::uint32_t timestamp )
inlinestatic

Create an EventRecord for input data.

Parameters
entityIdPlayer entity ID
keysKeyboard input
mouseXMouse X
mouseYMouse Y
mouseButtonsMouse buttons
timestampTimestamp
Returns
EventRecord ready to send

Definition at line 609 of file Serializer.hpp.

References getData(), rnp::INPUT, serializeInputData(), and rnp::EventRecord::type.

+ Here is the call graph for this function:

◆ createScoreEvent()

static EventRecord rnp::Serializer::createScoreEvent ( std::uint32_t entityId,
std::uint32_t score )
inlinestatic

Create an EventRecord for score event.

Parameters
entityIdEntity gaining score
scoreScore amount
Returns
EventRecord for score

Definition at line 674 of file Serializer.hpp.

References getData(), rnp::SCORE, rnp::EventRecord::type, and writeUInt32().

+ Here is the call graph for this function:

◆ createSpawnEvent()

static EventRecord rnp::Serializer::createSpawnEvent ( std::uint32_t entityId,
EntityType entityType,
float x,
float y )
inlinestatic

Create an EventRecord for spawn event.

Parameters
entityIdEntity ID to spawn
entityTypeType of entity
xX position
yY position
Returns
EventRecord for spawn

Definition at line 631 of file Serializer.hpp.

References getData(), rnp::SPAWN, rnp::EventRecord::type, writeFloat(), and writeUInt16().

+ Here is the call graph for this function:

◆ deserializeConnect()

PacketConnect rnp::Serializer::deserializeConnect ( )
inline

Deserialize CONNECT packet.

Returns
Deserialized CONNECT packet

Definition at line 315 of file Serializer.hpp.

References rnp::PacketConnect::clientCaps, rnp::PacketConnect::nameLen, rnp::PacketConnect::playerName, readByte(), readBytes(), and readUInt32().

Referenced by rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeConnectAccept()

PacketConnectAccept rnp::Serializer::deserializeConnectAccept ( )
inline

Deserialize CONNECT_ACCEPT packet.

Returns
Deserialized CONNECT_ACCEPT packet

Definition at line 340 of file Serializer.hpp.

References rnp::PacketConnectAccept::mtuPayloadBytes, readUInt16(), readUInt32(), rnp::PacketConnectAccept::serverCaps, rnp::PacketConnectAccept::sessionId, and rnp::PacketConnectAccept::tickRateHz.

Referenced by rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeDisconnect()

PacketDisconnect rnp::Serializer::deserializeDisconnect ( )
inline

Deserialize DISCONNECT packet.

Returns
Deserialized DISCONNECT packet

Definition at line 360 of file Serializer.hpp.

References readUInt16(), and rnp::PacketDisconnect::reasonCode.

Referenced by rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeEntityEvents()

std::vector< EventRecord > rnp::Serializer::deserializeEntityEvents ( std::size_t payloadSize)
inline

Deserialize multiple EventRecords from ENTITY_EVENT packet.

Parameters
payloadSizeTotal size of the payload to deserialize
Returns
Vector of deserialized event records

Definition at line 547 of file Serializer.hpp.

References buffer_, deserializeEventRecord(), and readPos_.

+ Here is the call graph for this function:

◆ deserializeEntityState()

EntityState rnp::Serializer::deserializeEntityState ( )
inline

Deserialize EntityState.

Returns
Deserialized entity state

Definition at line 389 of file Serializer.hpp.

References rnp::EntityState::healthPercent, rnp::EntityState::id, readByte(), readFloat(), readUInt16(), readUInt32(), rnp::EntityState::score, rnp::EntityState::stateFlags, rnp::EntityState::subtype, rnp::EntityState::type, rnp::EntityState::vx, rnp::EntityState::vy, rnp::EntityState::x, and rnp::EntityState::y.

Referenced by deserializeWorldState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeError()

PacketError rnp::Serializer::deserializeError ( )
inline

Deserialize ERROR packet.

Returns
Deserialized ERROR packet

Definition at line 479 of file Serializer.hpp.

References rnp::PacketError::description, rnp::PacketError::errorCode, rnp::PacketError::msgLen, readBytes(), and readUInt16().

Referenced by rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeEventRecord()

EventRecord rnp::Serializer::deserializeEventRecord ( )
inline

Deserialize EventRecord from ENTITY_EVENT packets.

Returns
Deserialized event record

Definition at line 514 of file Serializer.hpp.

References rnp::EventRecord::data, readByte(), readBytes(), readUInt16(), readUInt32(), and rnp::EventRecord::type.

Referenced by deserializeEntityEvents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeGameStart()

PacketGameStart rnp::Serializer::deserializeGameStart ( )
inline

Deserialize GAME_START packet.

Returns
Deserialized packet

Definition at line 903 of file Serializer.hpp.

References rnp::PacketGameStart::lobbyId, and readUInt32().

Referenced by gme::WaitingRoomScene::handleGameStart(), and rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeHeader()

PacketHeader rnp::Serializer::deserializeHeader ( )
inline

Deserialize packet header.

Returns
Deserialized header

Definition at line 291 of file Serializer.hpp.

References rnp::PacketHeader::length, readByte(), readUInt16(), readUInt32(), rnp::PacketHeader::sessionId, and rnp::PacketHeader::type.

Referenced by eng::AsioClient::handleReceive(), srv::AsioServer::handleReceive(), and rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeInputData()

void rnp::Serializer::deserializeInputData ( std::uint8_t & keys,
float & mouseX,
float & mouseY,
std::uint8_t & mouseButtons,
std::uint32_t & timestamp )
inline

Deserialize input data from INPUT events.

Parameters
keysOutput keyboard input bitmask
mouseXOutput mouse X position
mouseYOutput mouse Y position
mouseButtonsOutput mouse button bitmask
timestampOutput input timestamp

Definition at line 589 of file Serializer.hpp.

References readByte(), readFloat(), and readUInt32().

+ Here is the call graph for this function:

◆ deserializeLobbyCreate()

PacketLobbyCreate rnp::Serializer::deserializeLobbyCreate ( )
inline

Deserialize LOBBY_CREATE packet.

Returns
Deserialized packet

Definition at line 793 of file Serializer.hpp.

References rnp::PacketLobbyCreate::gameMode, rnp::PacketLobbyCreate::lobbyName, rnp::PacketLobbyCreate::maxPlayers, rnp::PacketLobbyCreate::nameLen, readByte(), and readBytes().

Referenced by eng::AsioClient::processBusEvent(), and rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeLobbyCreateResponse()

PacketLobbyCreateResponse rnp::Serializer::deserializeLobbyCreateResponse ( )
inline

Deserialize LOBBY_CREATE_RESPONSE packet.

Returns
Deserialized packet

Definition at line 818 of file Serializer.hpp.

References rnp::PacketLobbyCreateResponse::errorCode, rnp::PacketLobbyCreateResponse::lobbyId, readByte(), readUInt16(), readUInt32(), and rnp::PacketLobbyCreateResponse::success.

Referenced by gme::CreateRoomScene::processEventBus(), and rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeLobbyInfo()

LobbyInfo rnp::Serializer::deserializeLobbyInfo ( )
inline

Deserialize LobbyInfo structure.

Returns
Deserialized lobby info

Definition at line 726 of file Serializer.hpp.

References rnp::LobbyInfo::currentPlayers, rnp::LobbyInfo::gameMode, rnp::LobbyInfo::hostSessionId, rnp::LobbyInfo::lobbyId, rnp::LobbyInfo::lobbyName, rnp::LobbyInfo::maxPlayers, rnp::LobbyInfo::playerNames, readByte(), readBytes(), readUInt32(), and rnp::LobbyInfo::status.

Referenced by deserializeLobbyJoinResponse(), deserializeLobbyListResponse(), and deserializeLobbyUpdate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeLobbyJoin()

PacketLobbyJoin rnp::Serializer::deserializeLobbyJoin ( )
inline

Deserialize LOBBY_JOIN packet.

Returns
Deserialized packet

Definition at line 837 of file Serializer.hpp.

References rnp::PacketLobbyJoin::lobbyId, and readUInt32().

Referenced by rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeLobbyJoinResponse()

PacketLobbyJoinResponse rnp::Serializer::deserializeLobbyJoinResponse ( )
inline

Deserialize LOBBY_JOIN_RESPONSE packet.

Returns
Deserialized packet

Definition at line 863 of file Serializer.hpp.

References deserializeLobbyInfo(), rnp::PacketLobbyJoinResponse::errorCode, rnp::PacketLobbyJoinResponse::lobbyId, rnp::PacketLobbyJoinResponse::lobbyInfo, readByte(), readUInt16(), readUInt32(), and rnp::PacketLobbyJoinResponse::success.

Referenced by gme::JoinRoomScene::handleLobbyJoinResponse(), and rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeLobbyListResponse()

PacketLobbyListResponse rnp::Serializer::deserializeLobbyListResponse ( )
inline

Deserialize LOBBY_LIST_RESPONSE packet.

Returns
Deserialized packet

Definition at line 763 of file Serializer.hpp.

References deserializeLobbyInfo(), rnp::PacketLobbyListResponse::lobbies, rnp::PacketLobbyListResponse::lobbyCount, and readUInt16().

Referenced by gme::JoinRoomScene::handleLobbyListResponse(), and rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeLobbyUpdate()

PacketLobbyUpdate rnp::Serializer::deserializeLobbyUpdate ( )
inline

Deserialize LOBBY_UPDATE packet.

Returns
Deserialized packet

Definition at line 886 of file Serializer.hpp.

References deserializeLobbyInfo(), and rnp::PacketLobbyUpdate::lobbyInfo.

Referenced by gme::WaitingRoomScene::handleLobbyUpdate(), and rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializePingPong()

PacketPingPong rnp::Serializer::deserializePingPong ( )
inline

Deserialize PING/PONG packet.

Returns
Deserialized PING/PONG packet

Definition at line 453 of file Serializer.hpp.

References rnp::PacketPingPong::nonce, readUInt32(), and rnp::PacketPingPong::sendTimeMs.

Referenced by rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeStartGameRequest()

PacketStartGameRequest rnp::Serializer::deserializeStartGameRequest ( )
inline

Deserialize START_GAME_REQUEST packet.

Returns
Deserialized packet

Definition at line 920 of file Serializer.hpp.

References rnp::PacketStartGameRequest::lobbyId, and readUInt32().

Referenced by rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializeWorldState()

PacketWorldState rnp::Serializer::deserializeWorldState ( )
inline

Deserialize WORLD_STATE packet.

Returns
Deserialized WORLD_STATE packet

Definition at line 424 of file Serializer.hpp.

References deserializeEntityState(), rnp::PacketWorldState::entities, rnp::PacketWorldState::entityCount, readUInt16(), readUInt32(), and rnp::PacketWorldState::serverTick.

Referenced by gme::GameMulti::handleWorldStateUpdate(), and rnp::HandlerPacket::processPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getData()

◆ getSize()

std::size_t rnp::Serializer::getSize ( ) const
inline

Get the current size of serialized data.

Returns
Size in bytes

Definition at line 117 of file Serializer.hpp.

References writePos_.

Referenced by eng::AsioClient::createLobby(), and eng::AsioClient::requestLobbyList().

+ Here is the caller graph for this function:

◆ readByte()

std::uint8_t rnp::Serializer::readByte ( )
inline

Read a single byte.

Returns
Byte value

Definition at line 213 of file Serializer.hpp.

References readBytes().

Referenced by deserializeConnect(), deserializeEntityState(), deserializeEventRecord(), deserializeHeader(), deserializeInputData(), deserializeLobbyCreate(), deserializeLobbyCreateResponse(), deserializeLobbyInfo(), deserializeLobbyJoinResponse(), rnp::HandlerPacket::parseEntityEvents(), and readString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readBytes()

void rnp::Serializer::readBytes ( void * data,
std::size_t size )
inline

Read raw bytes.

Parameters
dataPointer to destination buffer
sizeNumber of bytes to read

Definition at line 198 of file Serializer.hpp.

References buffer_, and readPos_.

Referenced by deserializeConnect(), deserializeError(), deserializeEventRecord(), deserializeLobbyCreate(), deserializeLobbyInfo(), rnp::HandlerPacket::parseEntityEvents(), readByte(), readFloat(), readString(), readUInt16(), and readUInt32().

+ Here is the caller graph for this function:

◆ readFloat()

float rnp::Serializer::readFloat ( )
inline

Read a float (network byte order)

Returns
Float in host byte order

Definition at line 246 of file Serializer.hpp.

References rnp::EndianUtils::networkToHostFloat(), and readBytes().

Referenced by deserializeEntityState(), and deserializeInputData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readString()

std::string rnp::Serializer::readString ( std::size_t maxLength)
inline

Read a string with length prefix.

Parameters
maxLengthMaximum expected length
Returns
The read string

Definition at line 258 of file Serializer.hpp.

References readByte(), and readBytes().

Referenced by eng::AsioClient::processBusEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readUInt16()

std::uint16_t rnp::Serializer::readUInt16 ( )
inline

Read a 16-bit integer (network byte order)

Returns
16-bit integer in host byte order

Definition at line 224 of file Serializer.hpp.

References rnp::EndianUtils::networkToHost16(), and readBytes().

Referenced by deserializeConnectAccept(), deserializeDisconnect(), deserializeEntityState(), deserializeError(), deserializeEventRecord(), deserializeHeader(), deserializeLobbyCreateResponse(), deserializeLobbyJoinResponse(), deserializeLobbyListResponse(), deserializeWorldState(), and rnp::HandlerPacket::parseEntityEvents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readUInt32()

std::uint32_t rnp::Serializer::readUInt32 ( )
inline

◆ reset()

void rnp::Serializer::reset ( )
inline

Reset the serializer for reuse.

Definition at line 100 of file Serializer.hpp.

References buffer_, readPos_, and writePos_.

◆ serializeConnect()

void rnp::Serializer::serializeConnect ( const PacketConnect & packet)
inline

Serialize CONNECT packet.

Parameters
packetCONNECT packet to serialize

Definition at line 304 of file Serializer.hpp.

References rnp::PacketConnect::clientCaps, rnp::PacketConnect::nameLen, rnp::PacketConnect::playerName, writeByte(), writeBytes(), and writeUInt32().

Referenced by eng::AsioClient::sendConnect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeConnectAccept()

void rnp::Serializer::serializeConnectAccept ( const PacketConnectAccept & packet)
inline

Serialize CONNECT_ACCEPT packet.

Parameters
packetCONNECT_ACCEPT packet to serialize

Definition at line 328 of file Serializer.hpp.

References rnp::PacketConnectAccept::mtuPayloadBytes, rnp::PacketConnectAccept::serverCaps, rnp::PacketConnectAccept::sessionId, rnp::PacketConnectAccept::tickRateHz, writeUInt16(), and writeUInt32().

Referenced by srv::AsioServer::sendConnectAccept().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeDisconnect()

void rnp::Serializer::serializeDisconnect ( const PacketDisconnect & packet)
inline

Serialize DISCONNECT packet.

Parameters
packetDISCONNECT packet to serialize

Definition at line 354 of file Serializer.hpp.

References rnp::PacketDisconnect::reasonCode, and writeUInt16().

Referenced by srv::AsioServer::disconnectClient(), eng::AsioClient::sendDisconnect(), and srv::AsioServer::stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeEntityEvents()

void rnp::Serializer::serializeEntityEvents ( const std::vector< EventRecord > & events)
inline

Serialize multiple EventRecords for ENTITY_EVENT packet.

Parameters
eventsVector of event records to serialize

Definition at line 534 of file Serializer.hpp.

References serializeEventRecord().

Referenced by utl::EventBus::publish(), and gme::PlayerControllerMulti::sendInputToServer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeEntityState()

void rnp::Serializer::serializeEntityState ( const EntityState & entity)
inline

Serialize EntityState.

Parameters
entityEntity state to serialize

Definition at line 371 of file Serializer.hpp.

References rnp::EntityState::healthPercent, rnp::EntityState::id, rnp::EntityState::score, rnp::EntityState::stateFlags, rnp::EntityState::subtype, rnp::EntityState::type, rnp::EntityState::vx, rnp::EntityState::vy, writeByte(), writeFloat(), writeUInt16(), writeUInt32(), rnp::EntityState::x, and rnp::EntityState::y.

Referenced by serializeWorldState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeError()

void rnp::Serializer::serializeError ( const PacketError & packet)
inline

Serialize ERROR packet.

Parameters
packetERROR packet to serialize

Definition at line 465 of file Serializer.hpp.

References rnp::PacketError::description, rnp::PacketError::errorCode, rnp::PacketError::msgLen, writeBytes(), and writeUInt16().

Referenced by srv::AsioServer::sendError().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeEventRecord()

void rnp::Serializer::serializeEventRecord ( const EventRecord & event)
inline

Serialize EventRecord for ENTITY_EVENT packets.

Parameters
eventEvent record to serialize

Definition at line 498 of file Serializer.hpp.

References rnp::EventRecord::data, rnp::EventRecord::entityId, rnp::EventRecord::type, writeByte(), writeBytes(), writeUInt16(), and writeUInt32().

Referenced by serializeEntityEvents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeGameStart()

void rnp::Serializer::serializeGameStart ( const PacketGameStart & packet)
inline

Serialize GAME_START packet.

Parameters
packetThe packet to serialize

Definition at line 897 of file Serializer.hpp.

References rnp::PacketGameStart::lobbyId, and writeUInt32().

Referenced by srv::AsioServer::broadcastGameStart(), and utl::EventBus::publish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeHeader()

◆ serializeInputData()

void rnp::Serializer::serializeInputData ( std::uint8_t keys,
float mouseX,
float mouseY,
std::uint8_t mouseButtons,
std::uint32_t timestamp )
inline

Serialize input data for INPUT events.

Parameters
keysKeyboard input bitmask
mouseXMouse X position
mouseYMouse Y position
mouseButtonsMouse button bitmask
timestampInput timestamp

Definition at line 571 of file Serializer.hpp.

References writeByte(), writeFloat(), and writeUInt32().

Referenced by createInputEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeLobbyCreate()

void rnp::Serializer::serializeLobbyCreate ( const PacketLobbyCreate & packet)
inline

Serialize LOBBY_CREATE packet.

Parameters
packetThe packet to serialize

Definition at line 781 of file Serializer.hpp.

References rnp::PacketLobbyCreate::gameMode, rnp::PacketLobbyCreate::lobbyName, rnp::PacketLobbyCreate::maxPlayers, rnp::PacketLobbyCreate::nameLen, writeByte(), and writeBytes().

Referenced by eng::AsioClient::createLobby(), and utl::EventBus::publish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeLobbyCreateResponse()

void rnp::Serializer::serializeLobbyCreateResponse ( const PacketLobbyCreateResponse & packet)
inline

Serialize LOBBY_CREATE_RESPONSE packet.

Parameters
packetThe packet to serialize

Definition at line 807 of file Serializer.hpp.

References rnp::PacketLobbyCreateResponse::errorCode, rnp::PacketLobbyCreateResponse::lobbyId, rnp::PacketLobbyCreateResponse::success, writeByte(), writeUInt16(), and writeUInt32().

Referenced by utl::EventBus::publish(), and srv::AsioServer::sendLobbyCreateResponse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeLobbyInfo()

void rnp::Serializer::serializeLobbyInfo ( const LobbyInfo & lobbyInfo)
inline

Serialize LobbyInfo structure.

Parameters
lobbyInfoThe lobby info to serialize

Definition at line 704 of file Serializer.hpp.

References rnp::LobbyInfo::currentPlayers, rnp::LobbyInfo::gameMode, rnp::LobbyInfo::hostSessionId, rnp::LobbyInfo::lobbyId, rnp::LobbyInfo::lobbyName, rnp::LobbyInfo::maxPlayers, rnp::LobbyInfo::playerNames, rnp::LobbyInfo::status, writeByte(), writeBytes(), and writeUInt32().

Referenced by serializeLobbyJoinResponse(), serializeLobbyListResponse(), and serializeLobbyUpdate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeLobbyJoin()

void rnp::Serializer::serializeLobbyJoin ( const PacketLobbyJoin & packet)
inline

Serialize LOBBY_JOIN packet.

Parameters
packetThe packet to serialize

Definition at line 831 of file Serializer.hpp.

References rnp::PacketLobbyJoin::lobbyId, and writeUInt32().

Referenced by eng::AsioClient::joinLobby(), and utl::EventBus::publish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeLobbyJoinResponse()

void rnp::Serializer::serializeLobbyJoinResponse ( const PacketLobbyJoinResponse & packet)
inline

Serialize LOBBY_JOIN_RESPONSE packet.

Parameters
packetThe packet to serialize

Definition at line 848 of file Serializer.hpp.

References rnp::PacketLobbyJoinResponse::errorCode, rnp::PacketLobbyJoinResponse::lobbyId, rnp::PacketLobbyJoinResponse::lobbyInfo, serializeLobbyInfo(), rnp::PacketLobbyJoinResponse::success, writeByte(), writeUInt16(), and writeUInt32().

Referenced by utl::EventBus::publish(), and srv::AsioServer::sendLobbyJoinResponse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeLobbyListResponse()

void rnp::Serializer::serializeLobbyListResponse ( const PacketLobbyListResponse & packet)
inline

Serialize LOBBY_LIST_RESPONSE packet.

Parameters
packetThe packet to serialize

Definition at line 750 of file Serializer.hpp.

References rnp::PacketLobbyListResponse::lobbies, rnp::PacketLobbyListResponse::lobbyCount, serializeLobbyInfo(), and writeUInt16().

Referenced by utl::EventBus::publish(), and srv::AsioServer::sendLobbyList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeLobbyUpdate()

void rnp::Serializer::serializeLobbyUpdate ( const PacketLobbyUpdate & packet)
inline

Serialize LOBBY_UPDATE packet.

Parameters
packetThe packet to serialize

Definition at line 880 of file Serializer.hpp.

References rnp::PacketLobbyUpdate::lobbyInfo, and serializeLobbyInfo().

Referenced by srv::AsioServer::broadcastLobbyUpdate(), and utl::EventBus::publish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializePingPong()

void rnp::Serializer::serializePingPong ( const PacketPingPong & packet)
inline

Serialize PING/PONG packet.

Parameters
packetPING/PONG packet to serialize

Definition at line 443 of file Serializer.hpp.

References rnp::PacketPingPong::nonce, rnp::PacketPingPong::sendTimeMs, and writeUInt32().

Referenced by eng::AsioClient::sendPing(), eng::AsioClient::sendPong(), srv::AsioServer::sendPong(), and srv::AsioServer::updateClientManagement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeStartGameRequest()

void rnp::Serializer::serializeStartGameRequest ( const PacketStartGameRequest & packet)
inline

Serialize START_GAME_REQUEST packet.

Parameters
packetThe packet to serialize

Definition at line 914 of file Serializer.hpp.

References rnp::PacketStartGameRequest::lobbyId, and writeUInt32().

Referenced by eng::AsioClient::requestStartGame().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serializeWorldState()

void rnp::Serializer::serializeWorldState ( const PacketWorldState & packet)
inline

Serialize WORLD_STATE packet.

Parameters
packetWORLD_STATE packet to serialize

Definition at line 409 of file Serializer.hpp.

References rnp::PacketWorldState::entities, rnp::PacketWorldState::entityCount, serializeEntityState(), rnp::PacketWorldState::serverTick, writeUInt16(), and writeUInt32().

Referenced by gme::RTypeServer::broadcastWorldState(), and utl::EventBus::publish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeByte()

void rnp::Serializer::writeByte ( std::uint8_t value)
inline

Write a single byte.

Parameters
valueByte value to write

Definition at line 142 of file Serializer.hpp.

References writeBytes().

Referenced by utl::EventBus::publish(), serializeConnect(), serializeEntityState(), serializeEventRecord(), serializeHeader(), serializeInputData(), serializeLobbyCreate(), serializeLobbyCreateResponse(), serializeLobbyInfo(), serializeLobbyJoinResponse(), and writeString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeBytes()

void rnp::Serializer::writeBytes ( const void * data,
std::size_t size )
inline

Write raw bytes.

Parameters
dataPointer to data
sizeNumber of bytes to write

Definition at line 124 of file Serializer.hpp.

References buffer_, rnp::MAX_PAYLOAD, and writePos_.

Referenced by eng::AsioClient::processBusEvent(), serializeConnect(), serializeError(), serializeEventRecord(), serializeLobbyCreate(), serializeLobbyInfo(), writeByte(), writeFloat(), writeString(), writeUInt16(), and writeUInt32().

+ Here is the caller graph for this function:

◆ writeFloat()

void rnp::Serializer::writeFloat ( float value)
inline

Write a float (network byte order)

Parameters
valueFloat to write

Definition at line 168 of file Serializer.hpp.

References rnp::EndianUtils::hostToNetworkFloat(), and writeBytes().

Referenced by createSpawnEvent(), utl::EventBus::publish(), serializeEntityState(), and serializeInputData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeString()

void rnp::Serializer::writeString ( const std::string & str,
std::size_t maxLength )
inline

Write a string with length prefix.

Parameters
strString to write
maxLengthMaximum allowed length

Definition at line 179 of file Serializer.hpp.

References writeByte(), and writeBytes().

Referenced by gme::ServerScene::connectServer(), and utl::EventBus::publish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeUInt16()

void rnp::Serializer::writeUInt16 ( std::uint16_t value)
inline

Write a 16-bit integer (network byte order)

Parameters
value16-bit integer to write

Definition at line 148 of file Serializer.hpp.

References rnp::EndianUtils::hostToNetwork16(), and writeBytes().

Referenced by createSpawnEvent(), utl::EventBus::publish(), serializeConnectAccept(), serializeDisconnect(), serializeEntityState(), serializeError(), serializeEventRecord(), serializeHeader(), serializeLobbyCreateResponse(), serializeLobbyJoinResponse(), serializeLobbyListResponse(), and serializeWorldState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeUInt32()

void rnp::Serializer::writeUInt32 ( std::uint32_t value)
inline

Member Data Documentation

◆ buffer_

std::vector<std::uint8_t> rnp::Serializer::buffer_
private

◆ readPos_

std::size_t rnp::Serializer::readPos_
private

Definition at line 69 of file Serializer.hpp.

Referenced by deserializeEntityEvents(), readBytes(), and reset().

◆ writePos_

std::size_t rnp::Serializer::writePos_
private

Definition at line 68 of file Serializer.hpp.

Referenced by getSize(), reset(), and writeBytes().


The documentation for this class was generated from the following file: