Re: 0-size array marshaling ?

Jean Parpaillon <[email protected]>
Newsgroups gmane.comp.freedesktop.dbus
Message-ID <[email protected]>
Hi,
Thanks for the tip.
Answer is: always pad, even with 0-size array.
Test code in attachment.
I think I've fixed dbus-java code in https://github.com/jeanparpaillon/
dbus-java
Would be glad to push into the right repository, but freedesktop one
does not seem to be up-to-date (no 2.8 tag).
Regards
Jean
Le mardi 05 juillet 2016 à 10:41 +0100, Simon McVittie a écrit :
> On 04/07/16 14:43, Jean Parpaillon wrote:
> > The question is: for 0-size array, is padding to the alignment
> > boundary
> > of the array element type required ?
> 
> libdbus (dbus.git) is the reference implementation. What does it do?
> That's your answer. I would be happy to review a spec patch that
> clarifies what the right thing is (via
> 
> re>).
> 
> Because the array length is aligned to a 4-byte boundary, I would
> suggest serializing this message:
> 
> - type 'u', uint32 0x11223344 (to make it easy to find the payload)
> - type 'y', byte with arbitrary non-zero value, say 0x42
> - type 'at', empty array of uint64
> - type 'y', byte with arbitrary non-zero value, say 0x23
> 
> and looking at the resulting serialized bytes. If arrays of length 0
> do
> insert padding appropriate for the content, I would expect this hex-
> dump:
> 
> 44 33 22 11                 # uint32 (I've assumed little-endian)
>             42              # first byte
>                00 00 00     # pad to 4-byte boundary
> 00 00 00 00                 # array length
>             00 00 00 00     # pad to 8-byte boundary
>                             # no array contents
> 23                          # second byte
> 
> and if they don't, I would expect:
> 
> 44 33 22 11                 # uint32 (I've assumed little-endian)
>             42              # first byte
>                00 00 00     # pad to 4-byte boundary
> 00 00 00 00                 # array length
>                             # no padding, no array contents
>             23              # second byte
> 
> Whichever one libdbus does, that's correct and the other one is
> wrong.
> 
> Regards,
>     S
-- 
Jean Parpaillon
--
Open Source Consultant
Director @ OW2 Consortium
OCCIware Strategic Orientation Committee Chairman
Research Engineer @ Inria
--
Phone: +33 6 30 10 92 86
im: [email protected]
skype: jean.parpaillon
linkedin: http://www.linkedin.com/in/jeanparpaillon/en

_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
marshal.c (text/x-csrc, 783 B)
#include <stdlib.h>
#include <stdio.h>

#include <dbus/dbus.h>

void main(int argc, char* argv[]) {
  DBusMessage* m;
  dbus_uint32_t arg_a = 0x11223344;
  char arg_b = 0x42;
  const dbus_uint64_t array[] = {};
  const dbus_uint64_t *arg_c = array;
  char arg_d = 0x23;

  char* wire;
  int len;

  m = dbus_message_new_method_call(NULL,
				   "/",
				   NULL,
				   "Test");
  dbus_message_append_args(m,
			   DBUS_TYPE_UINT32, &arg_a,
			   DBUS_TYPE_BYTE, &arg_b,
			   DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64, &arg_c, 0,
			   DBUS_TYPE_BYTE, &arg_d,
			   DBUS_TYPE_INVALID);
  dbus_message_marshal(m, &wire, &len);

  for (int i = 0; i < len; i++) {
    printf("%02x", wire[i]);
    if ( (i+1) % 8) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
  
  exit(0);
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.