python 结构体、网络应用程序的字节顺序和对齐方式以及 unsigned int 和 unsigned long 之间的区别
我在 python 文档中有两个关于 struct 的问题:
字节顺序、大小和对齐方式:对于网络通信,我应该使用 !
而不是 =
吗?
例如: struct.pack("!BBH", 1, 12, 512) 或 struct.pack("=BBH", 1, 12, 512) ?
格式字符 :unsigned int (I) 之间有什么区别和 unsigned long (L),因为两者都是 4 个字节?
感谢您的宝贵时间,如果这是一个愚蠢的问题,请原谅我:-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望代码无论在何处运行都产生相同的输出,为什么要曾经使用
=
?当然,是的,您应该使用对每个人都具有相同含义的代码。标准是!
,因此请使用!
。阅读格式代码表上方的标题:
因此,如果您使用
@
格式代码或省略格式代码,理论上I
的大小和L
的大小可能会不同,取决于您的平台。If you want your code to produce the same output wherever it is run, why would you ever use
=
? So of course, yes, you should use a code that means the same thing to everyone. The standard is!
so use!
.Read the header above the format code table:
So, if you use the
@
format code or omit the format code, the size ofI
and the size ofL
could theoretically be different, depending on your platform.