[openamq-dev] Help on receving Vector objects
Martin Sustrik
sustrik at imatix.com
Thu Aug 16 14:27:00 CEST 2007
Malinga,
Hard to say, depends on how the MotageDataStructure-s are encoded
on-the-wire. You have to choose binary format for them, make sender
transform individual structures in the vector into the binary format and
receiver to parse the structures from the binary format and push them
into the vector.
I believe you should read the STL specification/tutorial carefully as
your problem is not related to OpenAMQ but to STL vectors.
To help you here's a way how to serialize vector of integers into a
binary buffer:
void *save (const vector<int> &vec)
{
int *buffer = (int*) malloc (sizeof (int) * vec.size ());
for (int i = 0; i != vec.size (); i++)
buffer [i] = vec [i];
return (void*) buffer;
}
And to get integers from buffer to vector:
vector<int> load (void *buffer, size_t size)
{
int *buf = (int*) buffer;
size /= sizeof (int);
vector<int> vec;
for (int i = 0; i != size; i++)
rec.push_back (buf [i]);
return vec;
}
I hope the example helps.
Martin
More information about the openamq-dev
mailing list