Accessing structure elements from Mesage Buffer

I have created message buffer and sent a structure to it. I want to compare some struct elements in the message buffer.
How to read structure elements for message buffer??
for example:

MessageBufferHandle_t message_buffer;

struct body
double p[3];//position
double v[3];//velocity
double a[3];//acceleration
double radius;
double mass;

struct body this_body;
xMessageBufferSend(message_buffer[x], &this_body, sizeof(this_event), 0);

how to read struct element to compare with something i get from some other tsak??

Sorry but it is not clear what you are asking.

Are you asking how to access structures that are inside the message buffer without reading them out? If so, then you can’t, you would have to read them out first.

Or are you asking how you compare structures, which is more of a C question?

If you mean to say how to read struct from the message buffer, it should look something like following:

struct body received_body;
xMessageBufferReceive( message_buffer,          /* Handle of the message buffer. */
                       &( received_body ),      /* Pointer to the struct where to receive data. */
                       sizeof( received_body ), /* Size of the struct. */
                       0                        /* Time to block. */


Hi Richard Barry,

Thanks for your reply,
sorry for not giving clarity. I have several structures in a message buffer with same length and when i get new struct values i have to check all structs in message buffer, if the values exist already then i just update that struct. if not i need to add new struct to message buffer.

To make sure that we are on the same page, you have a message buffer which contains multiple messages (M1, M2, M3 and M4) all of which are of the same type (and hence same length):

         |             |             |            |            |
         |     M1      |    M2       |    M3      |    M4      |
         |             |             |            |            |

And based on some criteria, you want to update a message (say M2) without reading it from the buffer. If so, then as pointed by Richard earlier, it is not possible. What is your use case? What are you trying to implement here?


Hi Gaurav,

That was exactly i was trying to implement. Those M1, M2,M3 … are structures with same length. I want to compare some variables of each structure before adding new structure or message to message buffer to avoid repetition. As Richard mentioned above it is not possible to compare without reading, I need to read all messages one by one and compare each.

If the number of types of messages are somewhat limited, rather than queueing up the messages themselves, it might make sense to create an ‘array’ of the different messages (maybe not a physical array in the C sense, but a collection of them, if they really are the same C type it could be a real array) and queue up requests indicating which message types need to be processed, with appropriate flags to indicate which types are pending. There will need to be some form of access protection to these buffers and the notification ‘queue’ to avoid races.