Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you have several options.</p> <p>since it looks like you want a contiguous glob of data in the NSData representation...</p> <p>you'll want to create a packed struct, and pass the data to the NSData call as a predefined endianness (so both ends know how to unarchive the data glob).</p> <pre><code>/* pack this struct's ivars and and enable -Wreorder to sanity check that the compiler does not reorder members -- i see no reason for the compiler to do this since the fields are equal size/type */ struct t_midi_message { UInt8 message_type; /* 0-15 */ UInt8 channel; /* 0-15 */ UInt8 data1; /* 0-127 */ UInt8 data2; /* 0-127 */ }; union t_midi_message_archive { /* members - as a union for easy endian swapping */ SInt32 glob; t_midi_message message; enum { ValidateSize = 1 / (4 == sizeof(t_midi_message)) }; /* nothing unusual here, although you may want a ctor which takes NSData as an argument */ t_midi_message_archive(); t_midi_message_archive(const t_midi_message&amp;); t_midi_message_archive(const t_midi_message_archive&amp;); t_midi_message_archive&amp; operator=(const t_midi_message_archive&amp;); /* swap routines -- just pass @member glob to the system's endian routines */ void swapToNativeEndianFromTransferEndian(); void swapToTransferEndianFromNativeEndian(); }; void a(const t_midi_message_archive&amp; msg) { t_midi_message_archive copy(msg); copy.swapToTransferEndianFromNativeEndian(); NSData * packedData([NSData dataWithBytes:&amp;copy.glob length:sizeof(copy.glob)]); assert(packedData); t_midi_message_archive recovered; [packedData getBytes:&amp;recovered.glob]; recovered.swapToNativeEndianFromTransferEndian(); /* recovered may now be used safely */ } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload