[openamq-dev] HELP on OpenAMQ Messages

Martin Sustrik sustrik at imatix.com
Wed Aug 15 11:48:47 CEST 2007


Hi,

>     I just want to send and receive a std::vector via a OpenAMQ, i just 
> send a vector via (
> 
> std::vector<void*>* cbody
> size_t x = (unsigned int)cbody->size();
> amq_content_basic_set_body (content, cbody, x, NULL);

This certainly does not work. Second parameter of 
amq_content_basic_set_body is a pointer to buffer. In your code you 
supply pointer to std::vector object instead...

IIRC STL specification does not specify that individual elements are 
stored in continuous array, but the implementations do it that way. So 
you can send the messages like this:

std::vector<void*> body;
void *buffer = malloc (sizeof (void*) * body.size ());
assert (buffer);
memcpy (buffer, &body [0], sizeof (void*) * body.size ());
amq_content_basic_set_body (content, buffer, sizeof (void*) * body.size 
(), free);

> ) from this code. But how can i receive a std::vector from the receiving 
> end. Can i receive it with this ?
> 
> amq_content_basic_get_body

Yes, but you have to know max size of body in advance to be able to 
allocate the buffer:

char buffer [16384];
amq_content_basic_get_body (content, buffer, 16384);

Afterwards you have to retrieve void pointers from the buffer and store 
them into the vector.

However, passing pointers (void*) via messaging makes little sense.

Martin


More information about the openamq-dev mailing list