如何在 64 位 Perl 中解压(64 位)unsigned long? [英] How to unpack (64-bit) unsigned long in 64-bit Perl?

查看:27
本文介绍了如何在 64 位 Perl 中解压(64 位)unsigned long?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解压缩从 C 程序通过 SysV::IPC 传递到 Perl 脚本的无符号长值.

I'm trying to unpack an unsigned long value that is passed from a C program to a Perl script via SysV::IPC.

已知该值是正确的(我做了一个测试,将相同的值发送到两个队列中,一个由 Perl 读取,第二个由 C 应用程序读取),并且所有前面的值都被正确读取(使用 q 而不是 i! 来处理 64 位整数).

It is known that the value is correct (I made a test which sends the same value into two queues, one read by Perl and the second by the C application), and all predecessing values are read correctly (used q instead of i! to work with 64-bit integers).

众所周知,PHP 有类似的东西(搜索对于64 位机器上的 unsigned long")(似乎类似:在 64 位架构上打包/解包 64 位 int在 PHP 中)

It is also known that PHP had something similar in bugs (search for "unsigned long on 64 bit machines") (seems to be similar: Pack / unpack a 64-bit int on 64-bit architecture in PHP)

到目前为止测试的参数:

Arguments tested so far:

  • ...Q(=某个值大于预期)
  • ..L ( = 0)
  • ..L!( = 大值)
  • ..l (=0)
  • ..l!( = 大值)
  • ..ln!( = 0)
  • ..N,..N!( = 0)

使用 bigint;使用 bignum; -- 没有效果.

详情:

  • sizeof(unsigned long) = 8;
  • Data::Dumper->new([$thatstring])->Useqq(1)->Dump(); 一些有意义的空字节..莉>
  • byteorder='12345678';
  • sizeof(unsigned long) = 8;
  • Data::Dumper->new([$thatstring])->Useqq(1)->Dump(); a lot of null bytes along some meaningful..
  • byteorder='12345678';

解决办法:- x4Q 填充四个字节.

Solution: - x4Q with padding four bytes.

推荐答案

解决方案很简单:添加 x4Q 以跳过实际值前的四个字节;需要更直观地考虑填充/对齐..

The solution was simple: added x4Q to skip four bytes before actual value; need to more visually think of padding/alignment..

这篇关于如何在 64 位 Perl 中解压(64 位)unsigned long?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆