Array alignment while marshalling data

marcin at saepia.net marcin at saepia.net
Wed May 25 08:05:17 UTC 2016


Thank you,

m.

2016-05-23 21:03 GMT+02:00 Simon McVittie <simon.mcvittie at collabora.co.uk>:

> On 23/05/16 19:46, marcin at saepia.net wrote:
> > the array length is not aligned to 8 bytes, but to 4 bytes. But type of
> > this array is struct, which according to the specification should always
> > align to 8 bytes.
>
> The header field array isn't a struct, it's an array (which happens to
> contain structs). The array length is a 4-byte integer, so it's aligned
> to a multiple of 4 bytes. After the length, there are some number of
> structs, and *those* are aligned to a multiple of 8 bytes.
>
> In effect, the beginning of every message looks like this:
>
> bytes 0-3: header start, four 1-byte quantities
> 4-7: body length
> 8-11: serial
> No padding, 12 is already a multiple of 4
> 12-15: header field array length
> No padding, 16 is already a multiple of 8
> 16+: first header field struct
>
> Let's say the first header field struct happens to be 13 bytes long.
> We'd continue as follows:
>
> 16-28: first header field struct
> 29-31: 3 bytes of padding to reach next multiple of 8
> 32+: second header field struct
>
> (Yes, this means the marshalling for `a(whatever)`, an array of structs,
> is not the same as the marshalling for `(a(whatever))`, a struct
> containing a single array of structs. There's no particular reason, it's
> just how this stuff was designed 10+ years ago.)
>
> Regards,
>     S
> --
> Simon McVittie
> Collabora Ltd. <http://www.collabora.com/>
>
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dbus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20160525/143c9b3b/attachment.html>


More information about the dbus mailing list