Hi,
I have a situation where i have to serialize and deserialize a C++ Objects. Can any one Suggest how that can be done using Platforn Symphony Developer Edition 4.0.
Rgds
Bala
Hi,
I have a situation where i have to serialize and deserialize a C++ Objects. Can any one Suggest how that can be done using Platforn Symphony Developer Edition 4.0.
Rgds
Bala
Hi Bala,
You have to manually write each data member of the C++ object into the stream in onSerialze() method of your Symphony messsage class. Similarly, populate the data by reading each data member of the object in onDeserialize() method. Make sure, the order of writing and reading matches, to avoid runtime serialization/deserialization error.
A couple of online documents can help you.
1.C++ tutorial . Go to [Synchronous Symphony C++ client tutorial] -> [Review the sample code, Input and output: declare the message object ]
2.Development guide . Go to [Messages] section.
Hi,
We have tried this approach for passing structure in our previous work. But when we had a chat with one of your team member, he was saying that readbytes & writebytes can be used. So that i have raised this question in this forum to confirm on that.
We did some sample by having pointer object. on serialize it was successful and while deserialize its throws the error.
Rgds
Bala
Hi Bala,
I didn't try this, but you should do something like this;
MyClass x(param1, param2);
writeBytes((void *)x, sizeof(MyClass));
-----
MyClass *x;
// allocate memory for the class
void * buffer = malloc(sizeof(MyClass));
// initialize class data
readBytes(buffer, sizeof(MyClass));
// Construct the class using the placement operator - constuctor should not do any initialization
x = new (buffer) MyClass();
delete x;
Last edited by Ajith; June 4th, 2008 at 04:58 PM.
Hi,
Please excuse me for the delay
When we tried the approach that you have specified, at the time of type casting the object to (void *) it gives error saying cannot covert.
So we tried some other way and we were able to pass the object
Example:
MyClass x(param1, param2);
writeBytes(&x, sizeof(MyClass));
---------
readBytes(&x, sizeof(MyClass));
This solved the issue of passing the object. When we tested with objects that have variables, array …
But the problem we face now is that our real time object has some vector array. When we went with the approach that we have used both serialization and de-serialization happens without error. But the vector data were not populated, so the service go too ideal state.
Do u have any suggestion on this?
Rgds
Bala
Hi Bala,
Yes, this line should be: writeBytes((void *)&x, sizeof(MyClass));
The approach I mentioned is only useful if your class does not have any pointers. If your class has pointers, like a vector, your best approach is to serialize the size first and then the values individually.
Serialize :
int size
value1
value2
...
Deserialize
size and then loop on size, taking out values.
- Ajith