你能告诉我如何通过 Qt lib 将 C# 中的这些函数重写为 C++ 吗?
private MemoryStream _memoryStream= new MemoryStream();
//WriteUTFBytes
public void WriteUTFBytes(string value)
{
//Length - max 65536.
UTF8Encoding utf8Encoding = new UTF8Encoding();
byte[] buffer = utf8Encoding.GetBytes(value);
if (buffer.Length > 0)
WriteBytes(buffer);
}
//WriteBytes
public void WriteBytes(byte[] buffer)
{
for (int i = 0; buffer != null && i < buffer.Length; i++)
_memoryStream.WriteByte(buffer[i]);
}
//WriteByte
public void WriteByte(int value)
{
_memoryStream.WriteByte((byte)value);
}
//WriteShort
public void WriteShort(int value)
{
byte[] bytes = BitConverter.GetBytes((ushort)value);
WriteBigEndian(bytes);
}
//WriteBigEndian
private void WriteBigEndian(byte[] bytes)
{
if (bytes == null)
return;
for (int i = bytes.Length - 1; i >= 0; i--)
{
_memoryStream.WriteByte(bytes[i]);
}
}