I am trying to define a structure to read a UDP message definition. Below is what I have. vertices_list is the field I am having problems with. I do not know before compilation time the number of vertices; so I am using a vector.
When I use this structure, the fields are all wrong (compressed). When I read a field in the header, I actually get a field value for field 3 (in the messageData).
I do know the number of vertices for a test set of data. When I create an array of this size, it works fine (i.e. all fields are properly aligned).
When I read a field in the header, I actually get a field value for field 3 (in the messageData).
You haven't shown MessageHeader, so can't comment on that.
line 23: A typedef only defines a type. It does not allocate space in the message.
Even so, you don't want a vector there. A vector has a size of it's own (overhead) in addition to the elements it stores which are not contiguous to the vector base.
if number_of_vertices is less than MAX_VERTICES, make sure the unused entries are initialized (zero), otherwise you're going to have an unpredictable checksum.