gpt4 book ai didi

bond - C# 债券 : string to wstring

转载 作者:行者123 更新时间:2023-12-05 06:32:27 25 4
gpt4 key购买 nike

Bond C# manual ,它注意到以下内容:

These following changes will break wire compatibility and are not recommended:

  • Adding or removing required fields
  • Incompatible change of field types (any type change not covered above); e.g.: int32 to string, string to wstring
  • ...

但它并没有解释为什么。这里的用例是我正在使用将 C# 应用程序与 C++ 后端连接起来的 Bond。该字段当前是一个字符串。我想将它更改为 wstring。手册指出 C# 字符串可以处理 C++ 字符串和 C++ wstrings。因此,为什么我不能将字段类型从字符串更改为 wstring?为什么这个断线兼容?

最佳答案

在 Bond 的二进制格式中,字符串是 UTF8 编码的(无 BOM)而 wstrings 是 UTF16-LE 编码的。如果您要将字段从字符串切换为 wstring,读取端会尝试将 UTF8 数据解释为 UTF16-LE 数据。这两种编码彼此不兼容,因此将字段类型从字符串更改为 wstring 是一个重大更改。

请注意,手册中说“例如 C# string 可以表示 Bond type stringwstring。 “它没有说明任何有关 C++ 类型的信息。当跨 C# 和 C++ 使用 Bond 时,有 三种 类型系统:Bond、C# 和 C++。

如果在 C++ 方面,您想使用类似于 std::wstring 的东西将字段存储在内存中,请看一下使用 Custom type mappingstring concept .

关于bond - C# 债券 : string to wstring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51314707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com