Separate length and preamble variables

This commit is contained in:
Yoshi Askharoun
2024-11-19 16:52:41 -06:00
parent b41e796c46
commit c0026cb01a
2 changed files with 9 additions and 8 deletions
+6 -5
View File
@@ -251,19 +251,20 @@ namespace Microsoft.Iris.Markup
public unsafe string ReadString()
{
uint stringLength = ReadUInt16();
if (stringLength == ushort.MaxValue)
uint preamble = ReadUInt16();
if (preamble == ushort.MaxValue)
return null;
var isUtf16Encoded = ((int)stringLength & (1 << 15)) == 0;
uint byteCount;
var isUtf16Encoded = ((int)preamble & (1 << 15)) == 0;
uint byteCount, stringLength;
if (isUtf16Encoded)
{
stringLength = preamble;
byteCount = stringLength * 2U;
}
else
{
stringLength &= (uint)short.MaxValue;
stringLength = preamble & (uint)short.MaxValue;
byteCount = stringLength;
}
+3 -3
View File
@@ -137,11 +137,11 @@ namespace Microsoft.Iris.Markup
}
}
uint length = (uint)value.Length;
uint preamble = (uint)value.Length;
if (!useUtf16)
length |= 1 << 15;
preamble |= 1 << 15;
WriteUInt16((ushort)length);
WriteUInt16((ushort)preamble);
foreach (char ch in value)
{