Skip to content

Commit

Permalink
Added functions for calculating and fixing message sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
aquaratixc committed Apr 16, 2022
1 parent 5aebf8a commit 955efd2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions source/styx2000/extrautil/styxmessage.d
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,31 @@ auto createRmsgWalk(ushort tag = STYX_NOTAG, Qid[] nwqid = [])
new Nwqid(nwqid)
];
}

/// Calculate real (!) message size
auto calculateMessageSize(StyxMessage msg)
{
ulong realSize = 0;

foreach (e; msg)
{
realSize += e.pack.length;
}

return realSize;
}


/// Fix incorrect size in some messages which generated by helpers (fix zero sizes)
auto fixMessageSize(StyxMessage msg)
{
StyxMessage newMsg = msg[1..$];
uint realSize = 4; // Size field has length = 4 bytes

foreach (e; newMsg)
{
realSize += e.pack.length;
}

return cast(StyxMessage) [new Size(realSize)] ~ newMsg;
}

0 comments on commit 955efd2

Please sign in to comment.