Fixed string serialization issues

This commit is contained in:
Derek S 2021-04-08 21:11:40 -05:00
parent 722da92e93
commit 8992305d94

View file

@ -40,11 +40,19 @@ namespace LightReflectiveMirror
} }
public static void WriteString(this byte[] data, ref int position, string value) public static void WriteString(this byte[] data, ref int position, string value)
{
if (string.IsNullOrWhiteSpace(value))
{
// Incase string is null or empty, just write nothing.
data.WriteInt(ref position, 0);
}
else
{ {
data.WriteInt(ref position, value.Length); data.WriteInt(ref position, value.Length);
for (int i = 0; i < value.Length; i++) for (int i = 0; i < value.Length; i++)
data.WriteChar(ref position, value[i]); data.WriteChar(ref position, value[i]);
} }
}
public static string ReadString(this byte[] data, ref int position) public static string ReadString(this byte[] data, ref int position)
{ {