diff --git a/CSharp/Libraries/UniversalEditor.Core/IO/Writer.cs b/CSharp/Libraries/UniversalEditor.Core/IO/Writer.cs
index 2c6291fc..13e2f5e0 100644
--- a/CSharp/Libraries/UniversalEditor.Core/IO/Writer.cs
+++ b/CSharp/Libraries/UniversalEditor.Core/IO/Writer.cs
@@ -242,6 +242,31 @@ namespace UniversalEditor.IO
WriteInt16(values[i]);
}
}
+
+ ///
+ /// Writes a variable-length unsigned integer to the current stream and advances the stream position by the number of bytes written.
+ ///
+ /// The value to write.
+ /// a representing the number of bytes written to the stream for the given
+ /// This code is taken from the answer on StackOverflow https://stackoverflow.com/q/3564685
+ public int WriteVariableLengthInt32(int value)
+ {
+ // thx stackoverflow :) https://stackoverflow.com/q/3564685
+ int count = 0;
+ bool first = true;
+ while (first || value > 0)
+ {
+ first = false;
+ byte lower7bits = (byte)(value & 0x7f);
+ value >>= 7;
+ if (value > 0)
+ lower7bits |= 128;
+ WriteByte(lower7bits);
+ count++;
+ }
+ return count;
+ }
+
///
/// Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes.
///