From d9aa9d1832248891a618a108351dbad09539d97a Mon Sep 17 00:00:00 2001 From: Damian Korczowski Date: Mon, 21 Jun 2021 21:34:21 +0200 Subject: [PATCH] Remove UTF8 and UTF32 in favor of UTF16 strings to be consistent with C++ API --- Source/Engine/Networking/NetworkMessage.cs | 34 +++++----------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/Source/Engine/Networking/NetworkMessage.cs b/Source/Engine/Networking/NetworkMessage.cs index 647c13ff5..b721ae7fa 100644 --- a/Source/Engine/Networking/NetworkMessage.cs +++ b/Source/Engine/Networking/NetworkMessage.cs @@ -250,8 +250,10 @@ namespace FlaxEngine.Networking /// public void WriteString(string value) { - var data = Encoding.UTF8.GetBytes(value); - WriteUInt16((ushort)data.Length); + // Note: Make sure that this is consistent with the C++ message API! + + var data = Encoding.Unicode.GetBytes(value); + WriteUInt16((ushort)data.Length); // TODO: Use 1-byte length when possible WriteBytes(data, data.Length); } @@ -260,37 +262,15 @@ namespace FlaxEngine.Networking /// public string ReadString() { + // Note: Make sure that this is consistent with the C++ message API! + var stringLength = ReadUInt16(); var bytes = new byte[stringLength]; fixed (byte* bytesPtr = bytes) { ReadBytes(bytesPtr, stringLength); } - return Encoding.UTF8.GetString(bytes); - } - - /// - /// Writes data of type into the message. UTF-32 encoded. - /// - public void WriteString32(string value) - { - var data = Encoding.UTF32.GetBytes(value); - WriteUInt16((ushort)data.Length); - WriteBytes(data, data.Length); - } - - /// - /// Reads and returns data of type from the message. UTF-32 encoded. - /// - public string ReadString32() - { - var stringLength = ReadUInt16(); - var bytes = new byte[stringLength]; - fixed (byte* bytesPtr = bytes) - { - ReadBytes(bytesPtr, stringLength); - } - return Encoding.UTF32.GetString(bytes); + return Encoding.Unicode.GetString(bytes); } ///