From e9d2b3fb3dbfa326bc4569f03254d5d68853e3c8 Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Mon, 13 Jan 2020 15:43:45 +0100
Subject: [PATCH] Add conditional serialization information

---
 .../serialization/primitive_objects.md        | 42 ++++++++++++++-----
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/docs/protocol/serialization/primitive_objects.md b/docs/protocol/serialization/primitive_objects.md
index 2800a74..3d21fb6 100644
--- a/docs/protocol/serialization/primitive_objects.md
+++ b/docs/protocol/serialization/primitive_objects.md
@@ -18,7 +18,7 @@ type whose network representation they borrow here:
 |BufferId       | `Int`                  |
 |IdentityId     | `Int`                  |
 |NetworkId      | `Int`                  |
-|MsgId          | `Long`                 |
+|MsgId          | `Int`                  |
 |PeerPtr        | `Long`                 |
 |IrcUser        | `QVariantMap`          |
 |IrcChannel     | `QVariantMap`          |
@@ -26,6 +26,10 @@ type whose network representation they borrow here:
 |NetworkInfo    | `QVariantMap`          |
 |Network::Server| `QVariantMap`          |
 
+MsgId’s serialization changes depending on which features are available on both
+client and server. Specifically, if "LongMessageId" is available, it is
+serialized as long, and its values can go above INT_MAX.
+
 ## String
 
 Strings are serialized as a signed int of the length in bytes plus their content
@@ -112,15 +116,33 @@ for each key a `QString` for the key and a `Variant` for each element.
 
 ## Message
 
-|Type        |Field    |Description                                                                                 |
-|------------|---------|--------------------------------------------------------------------------------------------|
-|`Int`       |messageId|The unique, sequential id for the message                                                   |
-|`Int`       |timestamp|The timestamp of the message in UNIX time (32-bit, seconds)                                 |
-|`Int`       |type     |See below                                                                                   |
-|`UChar`     |flags    |See below                                                                                   |
-|`BufferInfo`|buffer   |The buffer the message belongs to, usually everything but BufferId is set to `NULL`         |
-|`QByteArray`|sender   |(UTF-8) The sender as `nick!ident@host`                                                             |
-|`QByteArray`|content  |(UTF-8) The message content, already stripped from CTCP formatting, but containing mIRC format codes|
+|Type        |Field         |Description                                                                                         |
+|------------|--------------|----------------------------------------------------------------------------------------------------|
+|`MsgId`     |messageId     |The unique, sequential id for the message                                                           |
+|`Int`       |timestamp     |The timestamp of the message in UNIX time (32-bit, seconds)                                         |
+|`Long`      |              |**CONDITIONAL**: Different Type (Long) if LongTime feature is enabled                               |
+|`Int`       |type          |See below                                                                                           |
+|`UChar`     |flags         |See below                                                                                           |
+|`BufferInfo`|buffer        |The buffer the message belongs to, usually everything but BufferId is set to `NULL`                 |
+|`QByteArray`|sender        |(UTF-8) The sender as `nick!ident@host`                                                             |
+|`QByteArray`|senderPrefixes|(UTF-8) The prefix modes of the sender                                                              |
+|            |              |**CONDITIONAL**: Only serialized if SenderPrefixes feature is enabled                               |
+|`QByteArray`|realName      |(UTF-8) The realName of the sender                                                                  |
+|            |              |**CONDITIONAL**: Only serialized if RichMessages feature is enabled                                 |
+|`QByteArray`|avatarUrl     |(UTF-8) The avatarUrl of the sender, if available                                                   |
+|            |              |**CONDITIONAL**: Only serialized if RichMessages feature is enabled                                 |
+|`QByteArray`|content       |(UTF-8) The message content, already stripped from CTCP formatting, but containing mIRC format codes|
+
+This type's serialization format depends heavily on the available features — if
+both client and server support a certain feature, additional fields are added or
+changed.
+
+|Field         |Feature       |Effect                                                                 |
+|--------------|--------------|-----------------------------------------------------------------------|
+|timestamp     |LongTime      |Type is Long instead of Int, content is milliseconds instead of seconds|
+|senderPrefixes|SenderPrefixes|Field is serialized only with feature present                          |
+|realName      |RichMessages  |Field is serialized only with feature present                          |
+|avatarUrl     |RichMessages  |Field is serialized only with feature present                          |
 
 ### Type
 
-- 
GitLab