../

📡 A protocol system in C++

Table of contents

Repository

Introduction

During the realization of the Babel project, I had to work on a protocol system, to enable interactions between the client and the server.

If you want more details about the base project, feel free to click here.

Tech stack

The protocol system does not depend on anything else.

Architecture

PacketManager

PacketHandler

Fields

Here’s the base structure of a field

descriptionfield_typefield
size1 byteremaining bytes
value0x00 => 0xFF

descriptionfield_typevalue
size1 byte1 byte
value0x000x00 => 0xFF
descriptionfield_type[0][1][2][3]
size1 byte1 byte1 byte1 byte1 byte
value0x010x00 => 0xFF0x00 => 0xFF0x00 => 0xFF0x00 => 0xFF
descriptionfield_type[0][1][2][3]
size1 byte1 byte1 byte1 byte1 byte
value0x020x00 => 0xFF0x00 => 0xFF0x00 => 0xFF0x00 => 0xFF
descriptionfield_type[0][1][2][3][4][5][6][7]
size1 byte1 byte1 byte1 byte1 byte1 byte1 byte1 byte1 byte
value0x030x00 => 0xFF0x00 => 0xFF0x00 => 0xFF0x00 => 0xFF0x00 => OxFF0x00 => 0xFF0x00 => 0xFF0x00 => 0xFF
descriptionfield_typesize[0]size[1]size[2]size[3][0][n]
size1 byte1 byte1 byte1 byte1 byte1 byten-1 bytes1 byte
value0x040x00 => 0xFF0x00 => 0xFF0x00 => 0xFF0x00 => 0xFF0x00 => 0xFF0x00 => 0xFF0x00 => 0xFF

Packets

Here’s the base structure of a packet:

descriptionmagicpacket_typefields[]
size1 byte1 byteremaining bytes
value0x320x00 => 0xFF

descriptionusernamehostnameport
field_typestringstringuint
descriptionusername
field_typestring
descriptionusername
field_typestring
descriptionerror
field_typestring
descriptionusername
field_typestring
descriptionempty
field_typeempty
descriptionsenderrecipientcontenttimestamp
field_typestringstringstringuint64

Sample implementation

You can check out the GitHub wiki to have more details on an example implementation.

Future ?

If I ever get the time to work on my protocol system, I would definitely write a file parser to create packets from simple json files.

/cpp/ /server/ /communication/