将 python 包转换为 php 包

发布于 2024-09-15 09:17:27 字数 1044 浏览 7 评论 0原文

我有这个 python 脚本

b_string = pack('>hqh2sh13sh5sh3sBiiihiiiiii',
                21, 0,
                len(country), country,
                len(device), device,
                len('1.3.1'), "1.3.1",
                len('Web'), "Web",
                27, 0, 0,
                3, 0, cid, lac,
                0, 0, 0, 0)

,我想将其转换为 php,这就是我到目前为止所使用的

$body= pack('nln2c*n13c*n5c*n3c*Ciiiniiiiii',
                    21, 0,
                    strlen($this->_mccToCountry[$this->_mcc]), $this->_mccToCountry[$this->_mcc],
                    strlen($this->_device), $this->_device,
                    strlen('1.3.1'), "1.3.1",
                    strlen('Web'), "Web",
                    27, 0, 0,
                    3, 0, $this->_cellId, $this->_lac,
                    0, 0, 0, 0);

变量与 python 脚本中的变量相同,但我收到此错误

PHP 警告:pack(): 输入 n: .../application/extensions/Zend-extensions/NMS/Bts.php:150 中的参数太少

非常感谢您的帮助。

I have this python script

b_string = pack('>hqh2sh13sh5sh3sBiiihiiiiii',
                21, 0,
                len(country), country,
                len(device), device,
                len('1.3.1'), "1.3.1",
                len('Web'), "Web",
                27, 0, 0,
                3, 0, cid, lac,
                0, 0, 0, 0)

and I want to convert it to php, this is what I came with so far

$body= pack('nln2c*n13c*n5c*n3c*Ciiiniiiiii',
                    21, 0,
                    strlen($this->_mccToCountry[$this->_mcc]), $this->_mccToCountry[$this->_mcc],
                    strlen($this->_device), $this->_device,
                    strlen('1.3.1'), "1.3.1",
                    strlen('Web'), "Web",
                    27, 0, 0,
                    3, 0, $this->_cellId, $this->_lac,
                    0, 0, 0, 0);

The variables are same as those in python script, but i got this error

PHP Warning: pack(): Type n: too few arguments in .../application/extensions/Zend-extensions/NMS/Bts.php:150

The help will be very appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒解孤独 2024-09-22 09:17:27

你的参数字符串都搞砸了。您在一些地方表明您将通过 2、5、3 和 13 条短裤,但每次只提供一条。您表明您将提供一系列字符,但随后您提供了一个以 NUL 结尾的字符串。您表明您将提供一个无符号字符,但没有提供。请尝试使用此格式字符串:

'nlna*na*na*na*i3ni6'

另一种选择是使用 serializedeserialize 代替。不确定数据打包成字节还是序列化成字符串对您是否重要。

Your parameter string is all screwed up. You indicate in places that you are going to pass 2, 5, 3 and 13 shorts, but only provide one each time. You indicate that you are going to provide a series of characters but then you provide a NUL terminated string. You indicate that you will be providing an unsigned char but don't provide one. Try this format string instead:

'nlna*na*na*na*i3ni6'

Another option is to use serialize and deserialize instead. Not sure if it matters to you that the data is packed into bytes or serialized into strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文