0

I'm using DDS to buffer data between modules in software I'm working on. I'm new to the whole DDS thing, but one of the things I need to do is to access the data in a sequence<octect,1024> and pass it to a function as a array<double>.

I know that I can access the data using the sequence.get_contiguous_buffer() (docs) function, but this returns an array of type DDS_Octet (docs). How can I make this passable to my function (i.e. turn it into a primitive array)?

NOTE: The function can take any primitive, not just double; that's just what I'm using.

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69
marcman
  • 3,233
  • 4
  • 36
  • 71
  • So you want to convert a array of bytes (because that is what `sequence` is, essentially) to an array of doubles, or even to an array of any primitive type? What do you want that conversion to look like, should the new array have the same number of elements and should each value remain the same, but just be converted from byte to double? – Reinier Torenbeek Feb 28 '15 at 05:52
  • Yeah more or less just a double array. I can't cast it or anything. I was hoping to do this without having to copy all the data to a new array. I know sequence is essentially a byte array, but I can't access it as such. I'm stuck with the DDS_Octect data type as far as I can tell...? tl;dr: Basically I have some octet sequence that I would like to manipulate as a primitive array sized to the number of non-null elements in the sequence (e.g. a sequence with 4 elements produces a length-4 array) – marcman Feb 28 '15 at 20:16
  • 1
    I am not sure I understand what you are asking. When you call sequence.get_contiguous_buffer() you get a (DDS_Octet *). DDS_Octet is a typedef for "unsigned char" so basically you get a pointer to a contiguous array of unsigned char, something equivalent to "unsigned char buffer[sequence.get_length()]". If you make a double* point to this,i.e. double *dptr = (double *) sequence.get_contiguous_buffer(). You could access them as doubles, but this assumes that they are indeed doubles and were stored with the same endianess. – Gerardo Pardo Mar 01 '15 at 07:24
  • When you say array are you referring to "array" as defined by the IDL language or some other type? If so "IDL array" is mapped to a plain language array: "double my_array[SIZE];". Are you trying to then stuff the bytes you have inside the sequence into the my_array[1024]. if so I think this is not possible without a copy because the my_array[1024] has its own memory allocated. Could you use a sequence instead? – Gerardo Pardo Mar 01 '15 at 07:37
  • I feel like an idiot. It was as simple as casting to a double pointer... Thank you both for your help – marcman Mar 02 '15 at 04:51

0 Answers0