From 89fd1cb8d7dd78e79bbe8b539c9006235e3e135e Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 1 Apr 2020 11:27:06 -0400 Subject: [PATCH] didn't know this hadn't been implemented yet --- Libraries/UniversalEditor.Core/IO/Writer.cs | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Libraries/UniversalEditor.Core/IO/Writer.cs b/Libraries/UniversalEditor.Core/IO/Writer.cs index 3919d1dd..65fdbd8b 100644 --- a/Libraries/UniversalEditor.Core/IO/Writer.cs +++ b/Libraries/UniversalEditor.Core/IO/Writer.cs @@ -174,7 +174,32 @@ namespace UniversalEditor.IO } public void WriteLengthPrefixedString(string value, Encoding encoding) { - throw new NotImplementedException(); + Write7BitEncodedInt32(value.Length); + WriteFixedLengthString(value); + } + + public void Write7BitEncodedInt32(int value) + { + // TODO: verify this actually works + uint v = (uint)value; + while (v >= 0x80) + { + WriteByte((byte)(v | 0x80)); + v >>= 7; + } + WriteByte((byte)v); + } + public int Calculate7BitEncodedInt32Size(int value) + { + // TODO: verify this actually works + int size = 1; + uint v = (uint)value; + while (v >= 0x80) + { + size++; + v >>= 7; + } + return size; } public void WriteNullTerminatedString(string sz)