Skip to content

Instantly share code, notes, and snippets.

@nboutin
Created February 17, 2023 09:12
Show Gist options
  • Save nboutin/1778e540c182f259c4c973a74d4a80c9 to your computer and use it in GitHub Desktop.
Save nboutin/1778e540c182f259c4c973a74d4a80c9 to your computer and use it in GitHub Desktop.
Handling system for stream packet
enum class MessageType : char {
Add = 'A',
Modify = 'M',
Delete = 'D',
};
void on_message(const MessageHeader& hdr, const void* payload)
{
switch(hdr.type)
{
case MessageType.Add:
return handleAdd(payload);
case MessageType.Modify:
return handleModify(payload);
// no-default here to catch by at compile time new value in MessageType enumeration.
}
}
void handleAdd(const void* payload);
void handleModify(const void* payload);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment