Fix null String serialization over network via C# API

This commit is contained in:
Wojciech Figat
2022-11-02 16:44:31 +01:00
parent 70cfbada04
commit 957a34866b

View File

@@ -237,10 +237,14 @@ namespace FlaxEngine.Networking
{
// Note: Make sure that this is consistent with the C++ message API!
if (value == null)
{
WriteUInt16(0);
return;
}
var data = Encoding.Unicode.GetBytes(value);
var dataLength = data.Length;
var stringLength = value.Length;
WriteUInt16((ushort)stringLength); // TODO: Use 1-byte length when possible
WriteBytes(data, dataLength);
}
@@ -253,6 +257,8 @@ namespace FlaxEngine.Networking
// Note: Make sure that this is consistent with the C++ message API!
var stringLength = ReadUInt16(); // In chars
if (stringLength == 0)
return string.Empty;
var dataLength = stringLength * sizeof(char); // In bytes
var bytes = stackalloc char[stringLength];