Click to See Complete Forum and Search --> : Using serialization for making packets of byte arrays


rynac
June 5th, 1999, 05:07 PM
I'm trying to make packets that will each contain a 3D byte array. Currently I have something like the following. Please help!


#include "stdafx.h"
#include "Twixt.h"
#include "Packet.h"


IMPLEMENT_SERIAL(CPacket,CObject,1)

//#include <string.h>
//#include <stdio.h>

//char stringy[80];

//strcat(stringy, "hello" );






void CPacket::Serialize(CArchive &ar)
{
if (ar.IsLoading()) {
ar>>cmd>>x>>y;
// ar.WriteObject((CObject *)data);
ar.WriteObject((CByteArray *)data);
}
else {
ar<<cmd<<x<<y;
ar.ReadObject((CByteArray *)data);
//data=ar.ReadObject((IsKindOf(*data))data);
}
}

ChrisD
June 6th, 1999, 09:36 PM
If you are trying to serailize a CByteArray ptr created using the new operator just use
ar << data;
else
ar >> data;

if the CByteArray is a memeber variable

use
data.Serialize(ar); for both the save and load

HTH,
Chris