コード例 #1
0
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;
}
コード例 #2
0
ファイル: CompressionTest.cpp プロジェクト: ManS/folly
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);
}
コード例 #3
0
ファイル: Resource.cpp プロジェクト: darkfall/exlibs
    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;
    }
コード例 #4
0
ファイル: CompressionTest.cpp プロジェクト: ManS/folly
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()));
  }
}
コード例 #5
0
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()));
}