如何将 AS3 ByteArray 转换为 wchar_t const* 文件名? (土坯炼金术)
如何将 AS3 ByteArray
转换为 wchar_t const* filename
?
因此,在我的 C 代码中,我有一个函数等待带有 void fun (wchar_t const* filename)
的文件,如何将我的 ByteArray
发送到该函数? (或者,我应该如何重写我的函数?)
How to convert AS3 ByteArray
into wchar_t const* filename
?
So in my C code I have a function waiting for a file with void fun (wchar_t const* filename)
how to send to that function my ByteArray
? (Or, how should I re-write my function?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
四个月前的问题。迟到总比不到好?
在 AS3 中要将 ByteArray 转换为 String,有两种方法,具体取决于 String 的存储方式。首先,如果您使用
writeUTF
,它会先写入一个表示字符串长度的unsigned Short
,然后写出字符串数据。这种方式最容易恢复字符串。下面是 AS3 中的实现方式:另外,
toString
在这种情况下也适用。第二种存储方式是使用 writeUTFBytes。这不会将长度写入开头,因此您需要以某种方式独立跟踪它。听起来您希望整个 ByteArray 成为单个字符串,因此您可以使用 ByteArray 的length
。由于您想使用 Alchemy 执行此操作,因此只需转换上面的代码即可。这是第二个示例的转换:
当然,这有大量的内存泄漏,因为我没有在任何地方调用
AS3_Release
。为了保持理智,我在自己的代码中使用了AS3_Val
的 RAII 包装器。你也应该如此。无论如何,我的函数返回的
std::string
将是 UTF-8 多字节。任何用于转换为宽字符的标准 C++ 技术都应该从这里开始工作。 (在网站上搜索无尽的转发)不过,我建议保持原样。我想不出在这个平台上使用宽字符有什么好处。A four month old question. Better late than never?
To convert a ByteArray to a String in AS3, there are two ways depending on how the String was stored. Firstly, if you use
writeUTF
it will write anunsigned short
representing the String's length first, then write out the string data. The string is easiest to recover this way. Here's how it's done in AS3:Alternatively,
toString
also works in this case. The second way to store is withwriteUTFBytes
. This won't write the length to the beginning, so you'll need to track it independantly somehow. It sounds like you want the entire ByteArray to be a single String, so you can use the ByteArray'slength
.Since you want to do this with Alchemy, you just need to convert the above code. Here's a conversion of the second example:
This has a ridiculous amount of memory leaks, of course, since I'm not calling
AS3_Release
anywhere. I use a RAII wrapper forAS3_Val
in my own code... for the sake of my sanity. As should you.Anyway, the
std::string
my function returns will be UTF-8 multibyte. Any standard C++ technique for converting to wide characters should work from here. (search the site for endless reposts) I suggest leaving it is as it, though. I can't think of any advantage to using wide characters on this platform.