Improve Write/ReadString implementation and comments

This commit is contained in:
Damian Korczowski
2021-06-27 12:25:45 +02:00
parent a6ccbe3876
commit 95c86efd31
2 changed files with 17 additions and 13 deletions

View File

@@ -171,18 +171,24 @@ public:
}
public:
FORCE_INLINE void WriteQuaternion(const String& value)
/// <summary>
/// Writes data of type String into the message. UTF-16 encoded.
/// </summary>
FORCE_INLINE void WriteString(const String& value)
{
WriteUInt16(value.Length()); // TODO: Use 1-byte length when possible
WriteBytes((uint8*)value.Get(), value.Length() * 2);
WriteBytes((uint8*)value.Get(), value.Length() * sizeof(wchar_t));
}
/// <summary>
/// Reads and returns data of type String from the message. UTF-16 encoded.
/// </summary>
FORCE_INLINE String ReadString()
{
uint16 length = ReadUInt16();
String value;
value.Resize(length);
ReadBytes((uint8*)value.Get(), value.Length() * 2);
ReadBytes((uint8*)value.Get(), length * sizeof(wchar_t));
return value;
}