简体   繁体   English

在 P/Invoke 中编组字符串时 Mono 使用什么编码?

[英]What encoding does Mono use when marshalling strings in P/Invoke?

I'm reading Mono's marshalling guide , for the purpose of marshalling strings between Objective-C++ and Unity (for iOS games), and I'm somewhat confused about string marshalling encodings in Mono.我正在阅读Mono 的编组指南,目的是在 Objective-C++ 和 Unity 之间编组字符串(用于 iOS 游戏),我对 Mono 中的字符串编组编码有些困惑。

I understand that string encodings for marshalling are specified by the CharSet enum, but it allows only Ansi and Unicode (=UTF-16) (and Auto, but that just makes the runtime choose between the first two).我知道用于编组的字符串编码由 CharSet 枚举指定,但它只允许 Ansi 和 Unicode (=UTF-16)(和 Auto,但这只会让运行时在前两个之间进行选择)。

But the guide also keeps saying that Mono marshals strings in UTF-8.但该指南还一直说 Mono 以 UTF-8 格式编组字符串。 How is that possible?这怎么可能? Is this magic that happens if no CharSet is specified?如果没有指定 CharSet 会发生这种魔法吗? Does this mean that I can safely pass -[NSString UTF8String] from Objective-C++ to C#, if I don't specify a CharSet?这是否意味着如果我不指定 CharSet,我可以安全地将 -[NSString UTF8String] 从 Objective-C++ 传递到 C#? And does this imply an incompatibility with Microsoft's runtime?这是否意味着与 Microsoft 的运行时不兼容?

The Ansi charset value is meaningless on non-Windows operating systems, so in that case utf-8 is used, like is your case with iOS. Ansi 字符集值在非 Windows 操作系统上没有意义,因此在这种情况下使用 utf-8,就像您在 iOS 上的情况一样。

This is an incompatibility with the MS runtime, but the much bigger incompatibility in this case is that the MS runtime doesn't run at all on iOS:).这是与 MS 运行时的不兼容,但在这种情况下更大的不兼容是 MS 运行时根本不在 iOS 上运行:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM