Exemple #1
0
//----------------------------------------------------------------//
bool MOAILuaState::Decode ( int idx, ZLStreamReader& reader ) {

	if ( !this->IsType ( idx, LUA_TSTRING )) return false;

	size_t len;
	void* buffer = ( void* )lua_tolstring ( this->mState, idx, &len );
	if ( !len ) return false;
	
	ZLByteStream cryptStream;
	cryptStream.SetBuffer ( buffer, len );
	cryptStream.SetLength ( len );
	
	ZLMemStream plainStream;
	
	reader.Open ( cryptStream );
	plainStream.WriteStream ( reader );
	reader.Close ();
	
	len = plainStream.GetLength ();
	buffer = malloc ( len );
	
	plainStream.Seek ( 0, SEEK_SET );
	plainStream.ReadBytes ( buffer, len );
	
	lua_pushlstring ( this->mState, ( cc8* )buffer, len );
	
	free ( buffer );
	
	return true;
}
Exemple #2
0
//----------------------------------------------------------------//
void STLString::zl_decode ( ZLStreamAdapter& reader, void* buffer, size_t len ) {

	ZLByteStream byteStream;
	
	byteStream.SetBuffer (( void* )this->str (), this->size ());
	byteStream.SetLength ( this->size ());
	
	reader.Open ( &byteStream );
	reader.ReadBytes ( buffer, len );
	reader.Close ();
}
//----------------------------------------------------------------//
bool MOAIDataBuffer::Decode ( ZLStreamReader& reader ) {
	
	this->mMutex.Lock ();
	
	ZLByteStream cryptStream;
	cryptStream.SetBuffer ( this->mBytes, this->mBytes.Size ());
	cryptStream.SetLength ( this->mBytes.Size ());
	
	ZLMemStream plainStream;
	
	reader.Open ( cryptStream );
	plainStream.WriteStream ( reader );
	reader.Close ();
	
	size_t len = plainStream.GetLength ();
	this->mBytes.Init ( len );
	
	plainStream.Seek ( 0, SEEK_SET );
	plainStream.ReadBytes ( this->mBytes, len );
	
	this->mMutex.Unlock ();
	return true;
}