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

@ -41,9 +41,17 @@ 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)
{ {
data.WriteInt(ref position, value.Length); if (string.IsNullOrWhiteSpace(value))
for (int i = 0; i < value.Length; i++) {
data.WriteChar(ref position, value[i]); // Incase string is null or empty, just write nothing.
data.WriteInt(ref position, 0);
}
else
{
data.WriteInt(ref position, value.Length);
for (int i = 0; i < value.Length; 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)