Fixed string serialization issues
This commit is contained in:
parent
722da92e93
commit
8992305d94
1 changed files with 11 additions and 3 deletions
|
|
@ -41,9 +41,17 @@ namespace LightReflectiveMirror
|
|||
|
||||
public static void WriteString(this byte[] data, ref int position, string value)
|
||||
{
|
||||
data.WriteInt(ref position, value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
data.WriteChar(ref position, value[i]);
|
||||
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);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
data.WriteChar(ref position, value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadString(this byte[] data, ref int position)
|
||||
|
|
|
|||
Loading…
Reference in a new issue