Rebuilding a Data Object from RTByteBlock |
Category: |
C++
Applicable to: |
All Versions
Description: |
The following code works in both SimulationRTS and TargetRTS. This is a function called 'unpackData'. It returns an RTDataObject * (user must manage the memory allocated for this), and takes an RTByteBlock as a parameter:
RTDataObject *unpackData( RTByteBlock &blk )
{
//This function rebuilds a data object from
//a string representation (ascii encoding)
//using built-in RTS functions.
//You can do your own, of course, if you
//have different encoding/decoding schemes.
//This versions works in both SimulationRTS
//and MicroRTS.
char *databuf = (char *)(void *)blk;
RTDataObject *obj = 0;
int bufsize = strlen(databuf) + 1;
#ifdef __RTSInternal__ //SimulationRTS version
RTPacket packet(bufsize);
strcpy(packet.value(),databuf);
obj = packet.parse_object2();
#else //MicroRTS version
RTAsciiDecoding decoder(databuf, bufsize);
obj = decoder.getNew();
#endif
//receiver is responsible for deallocating object
return obj;
}
Copyright © 1999, ObjecTime Limited. |