Three people have asked me how to write binary data into messages, so I decided to give it a try. Here are two methods that make sense to me - is this how we intend people to do it?

Jonathan

// Method 1: create string, write to message

  // Let's format it all in a string buffer
  std::string s(100, 0);

  // Write some stuff into the string
  memcpy(&s[0], &i, sizeof(i));
  memcpy(&s[4], &f, sizeof(f));

  // Put it in the message
  message.setData(s);

// Method 2: write directly to message

  // Send the message as per usual

  Message msg;
  msg.getData().resize(100);

  memcpy(&msg.getData()[0], &i, sizeof(i));
  memcpy(&msg.getData()[4], &f, sizeof(f));

Reply via email to