gpt4 book ai didi

string - str::as_bytes 和 CString::as_bytes_with_nul 之间有区别吗?

转载 作者:行者123 更新时间:2023-11-29 08:10:45 25 4
gpt4 key购买 nike

这样做有什么区别吗:

name.as_bytes()

还有这个:

CString::new(name)?.as_bytes_with_nul()

我想从 name(即 String)获取字节,以便我可以轻松地通过网络发送它们,但我不确定是否 CString 在这里甚至是必要的。

最佳答案

as_bytes_with_nul 的文档开始于:

Equivalent to the as_bytes function except that the returned slice includes the trailing nul terminator.

同时 as_bytes是:

The returned slice does not contain the trailing nul terminator

(原文中强调)

是否需要传输 nul 字节取决于您,这取决于您如何通过网络发送数据(TCP/UDP?通过 TCP 的原始二进制数据?如果是这样,您打算如何分离消息? JSON?等等)。

关于string - str::as_bytes 和 CString::as_bytes_with_nul 之间有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54608972/

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