Пример #1
0
size_t vorbisReadFunc(void *ptr, size_t size, size_t nmemb, void *datasource)
{
    CAudioDecoderVorbis *audio_decoder_vorbis = (CAudioDecoderVorbis *)datasource;
    NLMISC::IStream *stream = audio_decoder_vorbis->getStream();
    nlassert(stream->isReading());
    sint32 length = (sint32)(size * nmemb);
    if (length > audio_decoder_vorbis->getStreamSize() - stream->getPos())
        length = audio_decoder_vorbis->getStreamSize() - stream->getPos();
    stream->serialBuffer((uint8 *)ptr, length);
    return length;
}
// ***************************************************************************
void CInterfaceConfig::CDesktopImage::write(NLMISC::IStream &f)
{
	nlassert(!f.isReading());
	// Version is important when the stream will be saved on Disk.
	f.serialVersion(Version);
	f.serialCont(GCImages);
	// serial extra datas
	uint32 length = ExtraDatas.length();
	if (length > 0)
	{
		uint8 *pBuffer = new uint8[length];
		memcpy(pBuffer, ExtraDatas.buffer(), length);
		f.serialBuffer(pBuffer, length);
		delete [] pBuffer;
	}
}
Пример #3
0
void  CUserComponent::serial(NLMISC::IStream &f)
{
    f.serial(Md5);
    f.serial(Md5Id);
    f.serialEnum(ComponentType);

    f.serial(Name);
    f.serial(Description);

    f.serial(Filename);
    f.serial(CompressedDataLength);
    f.serial(UncompressedDataLength);

    if (f.isReading())
    {
        delete [] CompressedData;
        CompressedData = new uint8[CompressedDataLength];
    }

    f.serialBuffer(CompressedData, CompressedDataLength);

}
// ***************************************************************************
void CInterfaceConfig::CDesktopImage::read(NLMISC::IStream &f)
{
	nlassert(f.isReading());
	f.serialVersion(Version);
	f.serialCont(GCImages);
	// extra datas go until the end of stream
	sint32 begPos = f.getPos();
	f.seek (0, NLMISC::IStream::end);
	sint32 endPos = f.getPos();
	f.seek (begPos, NLMISC::IStream::begin);
	NLMISC::contReset(ExtraDatas);
	if (ExtraDatas.isReading())
	{
		ExtraDatas.invert();
	}
	sint32 length = endPos - begPos;
	if (length > 0)
	{
		uint8 *pBuffer = new uint8[length];
		f.serialBuffer(pBuffer, length); // read buffer from file
		ExtraDatas.serialBuffer(pBuffer, length); // copy buffer to memstream
		delete [] pBuffer;
	}
}