duanhe1976 2015-04-15 13:23
浏览 66
已采纳

如何在PHP中解压缩来自Qt结构/字符串的bool

I have to unpack a struct in PHP which where written into a fifo. The struct orginal was created by a Qt application and looks like following:

    typedef struct {
       float32_t fNumberOne;
       uint16_t uIntOne; //maybe padding for alignment?
       bool_t myOneBitBool;
       float32_t fNumberTwo;
    } mystruct;

Now, the struct was serialized to write it into a fifo / named-pipe, so that 'the PHP' can read the fifo and unpack() the struct. If you read the fifo, you will get a string. This string you can substr() to get the (in this example) 4byte for the first float fNumberOne. And if you get your substring you can unpack() this with parameters like "f" for float. This works fine for me.

But, as you can see here there are 1 32bit float, 1 16bit int, our 1 bool that only needs 1bit and another 32bit float.

So my question is, if I get my first float and the first 16bit int correctly (byte 1-4 and 5-6) and, how do I get my bool bit out of this struct string (inside position 7?)? And what does the compiler do with the other 15 bits between the bool and the second float(byte rest of 7 and 8)? Are the next following bits are the second float or are they unused? Or does there help any padding to tell the compiler that he have to use another 32bit container?

Or better, how does the struct-string looks on binary level?

For further information, the compiler is not configured at this settings. It is all at standart settings.

many thanks in advance

  • 写回答

1条回答 默认 最新

  • doujia7094 2015-04-15 15:05
    关注

    If you're using C++11, alignas() might be what you're looking for

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 修改光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据
  • ¥15 为什么openeluer里面按不了python3呢?
  • ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
  • ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!
  • ¥15 关于#嵌入式硬件#的问题:树莓派第一天重装配置python和opencv后第二天打开就成这样,瞎捣鼓搞出来文件夹还是没把原来的界面调回来
  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥20 Arduino 循迹小车程序电路出错故障求解