duanhe1976 2015-04-15 05: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 07:05
    关注

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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部