将 python 包转换为 php 包
我有这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的参数字符串都搞砸了。您在一些地方表明您将通过 2、5、3 和 13 条短裤,但每次只提供一条。您表明您将提供一系列字符,但随后您提供了一个以
NUL
结尾的字符串。您表明您将提供一个无符号字符,但没有提供。请尝试使用此格式字符串:另一种选择是使用
serialize
和deserialize
代替。不确定数据打包成字节还是序列化成字符串对您是否重要。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:Another option is to use
serialize
anddeserialize
instead. Not sure if it matters to you that the data is packed into bytes or serialized into strings.