Skip to content

Commit

Permalink
Add optional includeLength to AddBytes overload
Browse files Browse the repository at this point in the history
Closes #128
  • Loading branch information
xzippyzachx committed Jan 28, 2024
1 parent f26788a commit 51193b4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions RiptideNetworking/RiptideNetworking/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,16 +672,18 @@ public Message AddBytes(byte[] array, bool includeLength = true)
/// <param name="array">The array to add.</param>
/// <param name="startIndex">The position at which to start adding from the array.</param>
/// <param name="amount">The amount of bytes to add from the startIndex of the array.</param>
/// <param name="includeLength">Whether or not to include the length of the array in the message.</param>
/// <returns>The message that the array was added to.</returns>
public Message AddBytes(byte[] array, int startIndex, int amount)
public Message AddBytes(byte[] array, int startIndex, int amount, bool includeLength = true)
{
if (startIndex < 0 || startIndex >= array.Length)
throw new ArgumentOutOfRangeException(nameof(startIndex));

if (startIndex + amount > array.Length)
throw new ArgumentException(nameof(amount), ArrayNotLongEnoughError(amount, array.Length, startIndex, ByteName));

AddVarULong((uint)amount);
if (includeLength)
AddVarULong((uint)amount);

int writeAmount = amount * BitsPerByte;
if (UnwrittenBits < writeAmount)
Expand Down

0 comments on commit 51193b4

Please sign in to comment.