Sources/CcgDump/BoneLightBindInfo.cpp
//////////////////////////////////////////////////////////////////////////
// Serialization to/from memory buffer.
// if the buffer is NULL, and bSave is true, returns the required buffer size
// otherwise, tries to save/load from the buffer, returns the number of bytes written/read
// or 0 if the buffer is too small or some error occured

Serialization to/from memory buffer.
if the buffer is NULL, and bSave is true, returns the required buffer size
otherwise, tries to save/load from the buffer, returns the number of bytes written/read
or 0 if the buffer is too small or some error occured
Serialization to / from memory buffer . if the buffer is NULL and bSave is true returns the required buffer size otherwise tries to save / load from the buffer returns the number of bytes written / read or 0 if the buffer is too small or some error occured
unsigned CBoneLightBindInfo::Serialize (bool bSave, void* pBuffer, unsigned nSize)
{
	const int nVersion = 1;
	typedef CBoneLightBindDesc Desc;
	if (bSave)
	{
		unsigned nRequiredSize = unsigned(sizeof(nVersion) + sizeof(Desc) + m_strLightImage.length()+1);
		if (!pBuffer)																	
			return nRequiredSize;
		if (nSize < nRequiredSize)
			return 0;
		*(int*)pBuffer = 1;
		pBuffer = (int*)pBuffer+1;
		*((Desc*)pBuffer) = *(Desc*)this;
		pBuffer = ((Desc*)pBuffer)+1;
		memcpy (pBuffer, m_strLightImage.c_str(), m_strLightImage.length()+1);
		return nRequiredSize;
	}
	else
	{
		if (nSize < sizeof(nVersion) +sizeof(Desc))
			return 0;
		const char* pBufEnd = (const char*)pBuffer + nSize;
		int nRealVersion = *(int*)pBuffer;
		if (nRealVersion != nVersion)
			return 0;
		void* pRawData = (int*)pBuffer + 1;
		*(Desc*)this = *(const Desc*)pRawData;
		pRawData = ((Desc*)pRawData)+1;
		const char* pName = (const char*)pRawData;
		m_strLightImage = "";
		for(;*pName && pName < pBufEnd;++pName)
			m_strLightImage += *pName;
		constructMatLight();
		return (unsigned)(pName+1 - (const char*)pBuffer);
	}
}
unsigned CBoneLightBindInfo :: Serialize ( bool bSave , void * pBuffer , unsigned nSize ) { const int nVersion = 1 ; typedef CBoneLightBindDesc Desc ; if ( bSave ) { unsigned nRequiredSize = unsigned ( sizeof ( nVersion ) + sizeof ( Desc ) + m_strLightImage . length ( ) + 1 ) ; if ( ! pBuffer ) return nRequiredSize ; if ( nSize < nRequiredSize ) return 0 ; * ( int * ) pBuffer = 1 ; pBuffer = ( int * ) pBuffer + 1 ; * ( ( Desc * ) pBuffer ) = * ( Desc * ) this ; pBuffer = ( ( Desc * ) pBuffer ) + 1 ; memcpy ( pBuffer , m_strLightImage . c_str ( ) , m_strLightImage . length ( ) + 1 ) ; return nRequiredSize ; } else { if ( nSize < sizeof ( nVersion ) + sizeof ( Desc ) ) return 0 ; const char * pBufEnd = ( const char * ) pBuffer + nSize ; int nRealVersion = * ( int * ) pBuffer ; if ( nRealVersion != nVersion ) return 0 ; void * pRawData = ( int * ) pBuffer + 1 ; * ( Desc * ) this = * ( const Desc * ) pRawData ; pRawData = ( ( Desc * ) pRawData ) + 1 ; const char * pName = ( const char * ) pRawData ; m_strLightImage = " " ; for ( ; * pName && pName < pBufEnd ; ++ pName ) m_strLightImage += * pName ; constructMatLight ( ) ; return ( unsigned ) ( pName + 1 - ( const char * ) pBuffer ) ; } }
Serialization to/from memory buffer.
Serialization to / from memory buffer .
// calculate the required size
