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

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

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算