BOOL DataStore::ReleaseData(WORD wIdent, void *pvData, WORD wLength) { BOOL bReturn = FALSE; if (pvData != NULL && wLength > 0) { DataHolderMap::iterator iter = m_dhmData.find(wIdent); if (iter != m_dhmData.end()) { DataHolder* pdhData = iter->second; if (pdhData != NULL) { pdhData->GetData(pvData, wLength); delete pdhData; bReturn = TRUE; } m_dhmData.erase(iter); } } return bReturn; }
void CompressionCorruptionTest::runSimpleTest(const DataHolder& dh) { constexpr uint64_t uncompressedLength = 42; auto original = IOBuf::wrapBuffer(dh.data(uncompressedLength)); auto compressed = codec_->compress(original.get()); if (!codec_->needsUncompressedLength()) { auto uncompressed = codec_->uncompress(compressed.get()); EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength()); EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get())); } { auto uncompressed = codec_->uncompress(compressed.get(), uncompressedLength); EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength()); EXPECT_EQ(dh.hash(uncompressedLength), hashIOBuf(uncompressed.get())); } EXPECT_THROW(codec_->uncompress(compressed.get(), uncompressedLength + 1), std::runtime_error); // Corrupt the first character ++(compressed->writableData()[0]); if (!codec_->needsUncompressedLength()) { EXPECT_THROW(codec_->uncompress(compressed.get()), std::runtime_error); } EXPECT_THROW(codec_->uncompress(compressed.get(), uncompressedLength), std::runtime_error); }
virtual result_t compile ( ISerializeNode* _pNode ) { string_t text; text = text + "title: " + m_title + "\n"; text = text + "author: " + m_author + "\n"; // for ( file_map_t::c_iterator iter = this->rawFiles().begin(); iter != this->rawFiles().end(); ++iter ) { // ex::path_t fullPath = (*iter).rawfile(); IFile::smart_ptr_t spFile = futil::file::readonly<PhysicalFile>(fullPath); if ( spFile ) { DataHolder dataHolder; dataHolder.alloc ( size_t(spFile->size()) ); spFile->read( dataHolder.data(), spFile->size() ); text += string_t( (const char*)(dataHolder.data()), dataHolder.size() ); } else { ex_warning ( "autogen resource failed: file %s not found.", fullPath.c_str() ); return EResult::not_found; } } EX_SERIALIZE ( _pNode, "text", text ); return EResult::ok; }
void CompressionTest::runSimpleTest(const DataHolder& dh) { auto original = IOBuf::wrapBuffer(dh.data(uncompressedLength_)); auto compressed = codec_->compress(original.get()); if (!codec_->needsUncompressedLength()) { auto uncompressed = codec_->uncompress(compressed.get()); EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength()); EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get())); } { auto uncompressed = codec_->uncompress(compressed.get(), uncompressedLength_); EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength()); EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get())); } }
void CompressionVarintTest::runSimpleTest(const DataHolder& dh) { auto original = IOBuf::wrapBuffer(dh.data(uncompressedLength_)); auto compressed = codec_->compress(original.get()); auto breakPoint = 1UL + Random::rand64(std::max(9UL, oneBasedMsbPos(uncompressedLength_)) / 9UL); auto tinyBuf = IOBuf::copyBuffer(compressed->data(), std::min(compressed->length(), breakPoint)); compressed->trimStart(breakPoint); tinyBuf->prependChain(std::move(compressed)); compressed = std::move(tinyBuf); auto uncompressed = codec_->uncompress(compressed.get()); EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength()); EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get())); }