我正在使用现有代码,union ibv_gid
通过 TCP 连接传递数据而不转换字节序。里面有一条评论:"The gid will be transfer byte by byte so no need to do "hton"
。代码是正确的并且有效,但我不明白为什么数据是逐字节传递的(实际上它们传递了整个结构)以及为什么不需要字节序转换。他们传递的数据类型是:
union ibv_gid {
uint8_t raw[16];
struct {
uint64_t subnet_prefix;
uint64_t interface_id;
} global;
};
** 对于其他数据类型(如 int 等),它们会在前后转换数据
//VL_sock_sync_data function synchronizes between the two sides
//by exchanging data between the two sides.
//size bytes are being copied from out_buf to the other side, and being saved in in_buf.
rc = VL_sock_sync_data(sock_p, sizeof(union ibv_gid), &local_gid, &tmp_gid);
你能解释一下为什么不需要字节序转换吗?感谢您的任何帮助