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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化