bool OggStream::init(const void* data, unsigned int len) { release(); _memStream = MemoryStream(data, len); return _init(cb_memoryStream, &_memStream); }
void FileEntitySchemeOutputStream::Write(const void* data, size_t size) { BEGIN_TRY(); const char* dataPtr = (const char*)data; while(size) { // if there's no current block stream, create it if(!currentBlockStream) currentBlockStream = NEW(MemoryStream(blockSize)); // write data size_t sizeToWrite = blockSize - currentBlockSize; if(sizeToWrite > size) sizeToWrite = size; currentBlockStream->Write(dataPtr, sizeToWrite); // write it also to total hash stream totalHashStream->Write(dataPtr, sizeToWrite); // move pointers and counters dataPtr += sizeToWrite; size -= sizeToWrite; currentBlockSize += sizeToWrite; // if block is over, finish it if(currentBlockSize >= blockSize) FinishCurrentBlock(); } END_TRY("Can't write data to file entity"); }
void FileEntitySchemeOutputStream::End() { // if there's current block, finish it if(currentBlockStream) FinishCurrentBlock(); // get hashes file ptr<File> hashes = descriptorHashStream->ToFile(); descriptorHashStream = nullptr; // get total hash file ptr<File> totalHash = NEW(MemoryFile(totalHashStream->GetHashSize())); totalHashStream->End(); totalHashStream->GetHash(totalHash->GetData()); // write descriptor, version 1 ptr<MemoryStream> descriptorStream = NEW(MemoryStream(hashes->GetSize() + 9)); StreamWriter writer(descriptorStream); writer.WriteShortly(1); // descriptor version writer.WriteShortlyBig(totalSize); writer.Write(totalHash); writer.Write(hashes); // store descriptor WriteData(nullptr, descriptorStream->ToFile()); }
bool KVBinaryOutputStreamSerializer::beginObject(Common::StringView name) { checkArrayPreamble(BIN_KV_SERIALIZE_TYPE_OBJECT); m_stack.push_back(Level(name)); m_objectsStack.push_back(MemoryStream()); return true; }
FileEntitySchemeOutputStream::FileEntitySchemeOutputStream(ptr<Action> action, ptr<Entity> entity, size_t blockSize) : action(action), entity(entity), blockSize(blockSize), totalSize(0), currentBlockIndex(0), currentBlockSize(0) { descriptorHashStream = NEW(MemoryStream()); descriptorHashWriter = NEW(StreamWriter(descriptorHashStream)); hashStream = NEW(Crypto::WhirlpoolStream()); totalHashStream = NEW(Crypto::WhirlpoolStream()); }
BEGIN_INANITY_OIL static ptr<File> GetBlockName(size_t index) { ptr<MemoryStream> stream = NEW(MemoryStream(9)); StreamWriter writer(stream); writer.WriteShortly(index); return stream->ToFile(); }
template<class Class> void PostDelayed(Class *Instance, void (Class::*Function)(MemoryStream &Arguments), uint32 Length, const MemoryStream &Stream = MemoryStream()) { if(!WasStarted) { Log::Instance.LogErr("Future", "Future Subsystem not started yet!"); return; } DisposablePointer<FutureInfo> Future(new FutureInfo()); Future->StartTime = GameClockTime(); Future->Length = Length; Future->Stream = Stream; Future->Stream.Seek(0); Future->Signal.Connect(Instance, Function); Futures.push_back(Future); }
void SendToConsole(unsigned char* pSendBuffer, unsigned int CurrPos, CCommsChannelLiveEdit* pCommsChannel) { for (CElement* pElement = m_pNodes->GetFirst(); pElement != NULL; pElement = pElement->m_pNext) { CDebugVariableTreeNode* pNode = (CDebugVariableTreeNode*)pElement->m_pData; memcpy(&pSendBuffer[CurrPos], pNode->m_pName, strlen(pNode->m_pName)); int Len = strlen(pNode->m_pName); pSendBuffer[CurrPos + Len] = '/'; pNode->SendToConsole(pSendBuffer, CurrPos + Len + 1, pCommsChannel); } for (CElement* pElement = m_pDebugVariables->GetFirst(); pElement != NULL; pElement = pElement->m_pNext) { ILiveEditVariable* pVariable = (ILiveEditVariable*)pElement->m_pData; CMemoryStreamWriter MemoryStream(pSendBuffer, CurrPos, scBiggestVariableSize); pVariable->Serialize(&MemoryStream); pCommsChannel->Send(pSendBuffer, MemoryStream.GetOffset()); } }
void D3D9VertexShader::Initialize( IDirect3DDevice9* const pD3DDevice, const IDataStream& Stream ) { ASSERT( pD3DDevice ); const int Length = Stream.Size(); byte* pBuffer = new byte[ Length ]; Stream.Read( Length, pBuffer ); // We're passing this along as a DWORD pointer, it better be aligned. If not, round up and memset it to 0 first. DEBUGASSERT( Length % sizeof( DWORD ) == 0 ); const HRESULT hr = pD3DDevice->CreateVertexShader( reinterpret_cast<DWORD*>( pBuffer ), &m_VertexShader ); ASSERT( m_VertexShader ); ASSERT( hr == D3D_OK ); Unused( hr ); D3D9ConstantTable::ParseConstantTable( MemoryStream( pBuffer, Length ), m_ConstantTable ); SafeDeleteArray( pBuffer ); }
virtual void OnReceive(unsigned int Size) { CMemoryStreamReader MemoryStream(m_pCommsBuffer, 0, Size); unsigned int MessageType = MemoryStream.Read<unsigned int>(); switch(MessageType) { case eSendTree: { CLiveEditTree::Instance().SendTreeToConsole(); break; } case eVariableUpdate: { CLiveEditTree::Instance().UpdateDebugVariable(&MemoryStream); break; } default: Assert(0); break; } }
static std::vector<TitleCommand> LegacyScriptRead(utf8* script, size_t scriptLength, std::vector<utf8*> saves) { std::vector<TitleCommand> commands; auto fs = MemoryStream(script, scriptLength); do { char parts[3 * 128], *token, *part1, *part2; LegacyScriptGetLine(&fs, parts); token = &parts[0 * 128]; part1 = &parts[1 * 128]; part2 = &parts[2 * 128]; TitleCommand command = {}; command.Type = TITLE_SCRIPT_UNDEFINED; if (token[0] != 0) { if (_stricmp(token, "LOAD") == 0) { command.Type = TITLE_SCRIPT_LOAD; command.SaveIndex = SAVE_INDEX_INVALID; for (size_t i = 0; i < saves.size(); i++) { if (String::Equals(part1, saves[i], true)) { command.SaveIndex = (uint8_t)i; break; } } } else if (_stricmp(token, "LOCATION") == 0) { command.Type = TITLE_SCRIPT_LOCATION; command.X = atoi(part1) & 0xFF; command.Y = atoi(part2) & 0xFF; } else if (_stricmp(token, "ROTATE") == 0) { command.Type = TITLE_SCRIPT_ROTATE; command.Rotations = atoi(part1) & 0xFF; } else if (_stricmp(token, "ZOOM") == 0) { command.Type = TITLE_SCRIPT_ZOOM; command.Zoom = atoi(part1) & 0xFF; } else if (_stricmp(token, "SPEED") == 0) { command.Type = TITLE_SCRIPT_SPEED; command.Speed = std::max(1, std::min(4, atoi(part1) & 0xFF)); } else if (_stricmp(token, "FOLLOW") == 0) { command.Type = TITLE_SCRIPT_FOLLOW; command.SpriteIndex = atoi(part1) & 0xFFFF; safe_strcpy(command.SpriteName, part2, USER_STRING_MAX_LENGTH); } else if (_stricmp(token, "WAIT") == 0) { command.Type = TITLE_SCRIPT_WAIT; command.Milliseconds = atoi(part1) & 0xFFFF; } else if (_stricmp(token, "RESTART") == 0) { command.Type = TITLE_SCRIPT_RESTART; } else if (_stricmp(token, "END") == 0) { command.Type = TITLE_SCRIPT_END; } else if (_stricmp(token, "LOADMM") == 0) { command.Type = TITLE_SCRIPT_LOADMM; } else if (_stricmp(token, "LOADRCT1") == 0) { command.Type = TITLE_SCRIPT_LOADRCT1; command.SaveIndex = atoi(part1) & 0xFF; } else if (_stricmp(token, "LOADSC") == 0) { command.Type = TITLE_SCRIPT_LOADSC; // Confirm the scenario exists // source_desc desc; // if (ScenarioSources::TryGetByName(part1, &desc)) //{ safe_strcpy(command.Scenario, part1, sizeof(command.Scenario)); //} } } if (command.Type != TITLE_SCRIPT_UNDEFINED) { commands.push_back(command); } } while (fs.GetPosition() < scriptLength); return commands; }
/*static*/ void ConfigManager::LoadTiny( const SimpleString& TinyString ) { ConfigParser::ParseTiny( MemoryStream( const_cast< char* >( TinyString.CStr() ), TinyString.Length() + 1 ) ); }