当前位置: 首页>>代码示例>>C++>>正文


C++ DataChunk类代码示例

本文整理汇总了C++中DataChunk的典型用法代码示例。如果您正苦于以下问题:C++ DataChunk类的具体用法?C++ DataChunk怎么用?C++ DataChunk使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DataChunk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WinMain

int WINAPI WinMain (
	__in HINSTANCE hInstance,
	__in_opt HINSTANCE hPrevInstance,
	__in LPSTR lpCmdLine,
	__in int nShowCmd
	)
{
	appPath = lpCmdLine;

#if 0
	DynamicMessageHelper file;
	if (file.Read("data\\TestAnimHandlers\\BinHandlers\\SpinXYZ,ffd",true))
	{
		ARMCore armTest;
		DataChunk memory;
		memory.Allocate(file.GetBufferSize());
		memcpy(memory.mData,file.GetBuffer(),file.GetBufferSize());
		armTest.WriteMemory(0x10000,file.GetBuffer(),file.GetBufferSize());

		// Get the frame code offset from the loaded handler
		unsigned int offset;
		file >> offset;
		armTest.SetPC(0x80000000 | 0x10000 + offset);
		armTest.SetRegister(0,6);
		armTest.Execute();
	}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例2: chunkDecode

Status
chunkDecode(DataChunk &result, const std::string &in)
{
    // The string must be a multiple of the chunk size:
    if (in.size() % Chars)
        return ABC_ERROR(ABC_CC_ParseError, "Bad encoding");

    DataChunk out;
    out.reserve(Bytes * (in.size() / Chars));

    constexpr unsigned shift = 8 * Bytes / Chars; // Bits per character
    uint16_t buffer = 0; // Bits waiting to be written out, MSB first
    int bits = 0; // Number of bits currently in the buffer
    auto i = in.begin();
    while (i != in.end())
    {
        // Read one character from the string:
        int value = Decode(*i);
        if (value < 0)
            break;
        ++i;

        // Append the bits to the buffer:
        buffer |= value << (16 - bits - shift);
        bits += shift;

        // Write out some bits if the buffer has a byte's worth:
        if (8 <= bits)
        {
            out.push_back(buffer >> 8);
            buffer <<= 8;
            bits -= 8;
        }
    }
开发者ID:codeaudit,项目名称:airbitz-core,代码行数:34,代码来源:Encoding.cpp

示例3: _EXCEPTIONT

void DataContainer::Allocate() {

	// Check that memory has not been allocated
	if (m_pAllocatedMemory != NULL) {
		_EXCEPTIONT("Attempting Allocate() on attached DataContainer");
	}

	// Allocate memory as one contiguous chunk
	size_t sTotalByteSize = GetTotalByteSize();

	m_pAllocatedMemory =
		reinterpret_cast<unsigned char*>(malloc(sTotalByteSize));

	if (m_pAllocatedMemory == NULL) {
		_EXCEPTIONT("Out of memory");
	}

	// Initialize allocated memory to zero
	memset(m_pAllocatedMemory, 0, sTotalByteSize);

	// Assign memory to DataChunks
	unsigned char * pAccumulated = m_pAllocatedMemory;

	for (size_t i = 0; i < m_vecDataChunks.size(); i++) {
		DataChunk * pDataChunk =
			reinterpret_cast<DataChunk*>(m_vecDataChunks[i]);

		pDataChunk->AttachToData(
			reinterpret_cast<void *>(pAccumulated));

#pragma message "Alignment may be an issue here on 32-bit systems"
		pAccumulated += pDataChunk->GetByteSize();
	}
}
开发者ID:brycelelbach,项目名称:tempestmodel,代码行数:34,代码来源:DataContainer.cpp

示例4: sd

void StreamDataTest::test_isValid()
{
    {
        // Use Case:
        // Stream Data invalid, no associated data
        // expect invalid
        StreamData sd("",(void*)0,10);
        CPPUNIT_ASSERT( ! sd.isValid() );
    }
    {
        // Use Case:
        // Stream Data valid, no associated data
        // expect valid
        StreamData sd("",(void*)1000,10);
        CPPUNIT_ASSERT( sd.isValid() );
    }
    {
        // Use Case:
        // Stream Data is valid, but associate Data is not
        // expect invalid
        DataChunk d;
        {
            StreamData sd("",(void*)1000,10);
            CPPUNIT_ASSERT( ! d.isValid() );
            CPPUNIT_ASSERT( sd.isValid() );
            boost::shared_ptr<DataChunk> ld( new DataChunk("test", &d) );
            sd.addAssociatedData( ld );
            CPPUNIT_ASSERT( ! sd.isValid() );
        }
    }
}
开发者ID:Error323,项目名称:pelican,代码行数:31,代码来源:StreamDataTest.cpp

示例5: WorkerThreadLoop

    static void* WorkerThreadLoop(void * workerThread) {

        WorkerThread* thread = static_cast<WorkerThread*>(workerThread);

        int sum = 0;

        unsigned t0 = clock();

        while(true) {
            // Get next task
            DataChunk data = thread->mDataSource->GetDataChunk();
            if(data.GetSize() == 0) break;

            // Execute task
            for(int i = 0; i < data.GetSize(); i++) {
                usleep(1000);
                sum += data[i];
            }
        }

        thread->mResultData->AddResult(sum);
        printf("%s: Thread is done:%d sum:%d time:%lu\n", __func__, thread->mTID, sum, clock() - t0);

        return NULL;
    }
开发者ID:mrslan,项目名称:toolbox,代码行数:25,代码来源:main.cpp

示例6: Base_ReadDataFrom

/*! \param Offset Offset from the start of the KLV value from which to start reading
 *  \param Size Number of bytes to read, if -1 all available bytes will be read (which could be billions!)
 *  \return The number of bytes read
 *
 *  DRAGONS: This base function may be called from derived class objects to get base behaviour.
 *           It is therefore vital that the function does not call any "virtual" KLVObject
 *           functions, directly or indirectly.
 */
size_t KLVObject::Base_ReadDataFrom(DataChunk &Buffer, Position Offset, size_t Size /*=-1*/)
{
	// Delagate to ReadHandler if defined
	if(ReadHandler) return ReadHandler->ReadData(Buffer, this, Offset, Size);

	if(Source.Offset < 0)
	{
		error("Call to KLVObject::Base_ReadDataFrom() with no read handler defined and DataBase undefined\n");
		return 0;
	}

	if(!Source.File)
	{
		error("Call to KLVObject::Base_ReadDataFrom() with no read handler defined and source file not set\n");
		return 0;
	}

	// Initially plan to read all the bytes available
	Length BytesToRead = Source.OuterLength - Offset;

	// Limit to specified size if > 0 and if < available
	if( (Size > 0) && (Size < BytesToRead)) BytesToRead = Size;

	// Don't do anything if nothing to read
	if(BytesToRead <= 0) 
	{
		Buffer.Resize(0);
		return 0;
	}

	// Sanity check the size of this read
	if((sizeof(size_t) < 8) && (BytesToRead > 0xffffffff))
	{
		error("Tried to read > 4GBytes, but this platform can only handle <= 4GByte chunks\n");
		return 0;
	}

	// Seek to the start of the requested data
	Source.File->Seek(Source.Offset + Source.KLSize + Offset);

	// Resize the chunk
	// Discarding old data first (by setting Size to 0) prevents old data being 
	// copied needlessly if the buffer is reallocated to increase its size
	Buffer.Size = 0;
	Buffer.Resize(static_cast<size_t>(BytesToRead));

	// Read into the buffer (only as big as the buffer is!)
	size_t Bytes = Source.File->Read(Buffer.Data, Buffer.Size);

	// Resize the buffer if something odd happened (such as an early end-of-file)
	if(Bytes != static_cast<size_t>(BytesToRead)) Buffer.Resize(Bytes);

	return Bytes;
}
开发者ID:MOXfiles,项目名称:mxflib,代码行数:62,代码来源:klvobject.cpp

示例7: randomData

Status
randomData(DataChunk &result, size_t size)
{
    DataChunk out;
    out.resize(size);

    if (!RAND_bytes(out.data(), out.size()))
        return ABC_ERROR(ABC_CC_Error, "Random data generation failed");

    result = std::move(out);
    return Status();
}
开发者ID:BitcoinKinetics,项目名称:airbitz-core,代码行数:12,代码来源:Random.cpp

示例8: buildData

DataChunk
buildData(std::initializer_list<DataSlice> slices)
{
    size_t size = 0;
    for (auto slice: slices)
        size += slice.size();

    DataChunk out;
    out.reserve(size);
    for (auto slice: slices)
        out.insert(out.end(), slice.begin(), slice.end());
    return out;
}
开发者ID:Airbitz,项目名称:airbitz-core,代码行数:13,代码来源:Data.cpp

示例9: Append

/*-----------------------------------------------------------------------------
  Append data to the SSL/TLS stream and handle packet framing.
-----------------------------------------------------------------------------*/
void SSLStream::Append(const DataChunk& chunk) {
  if (process_data_) {
    size_t len = chunk.GetLength();
    const char * buff = chunk.GetData();
  
    while (len && buff) {
      size_t copy_bytes = 0;

      // are we starting a new frame?
      if (message_size_ < 0) {
        // see if we can at least copy over the size of the initial frame
        size_t needed = sizeof(SSL_HEADER) - message_len_;
        copy_bytes = min(needed, len);
        if (copy_bytes) {
          memcpy(&message_[message_len_], buff, copy_bytes);
          message_len_ += (int)copy_bytes;
          len -= copy_bytes;
          buff += copy_bytes;
        }

        // see if we have a header to parse and get the actual message size
        if (message_len_ >= sizeof(SSL_HEADER)) {
          SSL_HEADER * header = (SSL_HEADER *)message_;
          message_size_ = htons(header->record_length) + sizeof(SSL_HEADER);
        }
      }

      // see if we have bytes remaining in the current message
      if (message_size_ > 0 &&
          message_len_ < message_size_ &&
          len > 0 &&
          buff) {
        copy_bytes = min(message_size_ - message_len_, (__int32)len);
        memcpy(&message_[message_len_], buff, copy_bytes);
        message_len_ += (int)copy_bytes;
        len -= copy_bytes;
        buff += copy_bytes;
      }

      // see if we have a full message
      if (message_size_ == message_len_) {
        ProcessMessage();

        // reset state for the next message
        message_size_ = -1;
        message_len_ = 0;
      }
    }
  }
}
开发者ID:lucasRolff,项目名称:webpagetest,代码行数:53,代码来源:ssl_stream.cpp

示例10: TEST_F

TEST_F(testsDataChunk, DefaultConstructor) {
    DataChunk empty;
    EXPECT_TRUE(empty.isReferencing(NULL));
    EXPECT_TRUE(empty.getData() == NULL);
    EXPECT_TRUE(empty.getSize() == 0);
    DataChunk emptyRef;
    emptyRef.reference(empty);
    EXPECT_TRUE(emptyRef.isReferencing(NULL));
    EXPECT_TRUE(emptyRef.getData() == NULL);
    EXPECT_TRUE(emptyRef.getSize() == 0);
    EXPECT_TRUE(emptyRef == empty);
}
开发者ID:cyrinux,项目名称:eguan,代码行数:12,代码来源:testsDataChunk.cpp

示例11: watcherBridgeRawTx

Status
watcherBridgeRawTx(Wallet &self, const char *szTxID,
    DataChunk &result)
{
    Watcher *watcher = nullptr;
    ABC_CHECK(watcherFind(watcher, self));

    bc::hash_digest txid;
    if (!bc::decode_hash(txid, szTxID))
        return ABC_ERROR(ABC_CC_ParseError, "Bad txid");
    auto tx = watcher->find_tx(txid);
    result.resize(satoshi_raw_size(tx));
    bc::satoshi_save(tx, result.begin());

    return Status();
}
开发者ID:TSchnaars,项目名称:airbitz-core,代码行数:16,代码来源:WatcherBridge.cpp

示例12: Detach

void DataContainer::Detach() {

	for (size_t i = 0; i < m_vecDataChunks.size(); i++) {
		DataChunk * pDataChunk =
			reinterpret_cast<DataChunk *>(m_vecDataChunks[i]);

		pDataChunk->Detach();
	}

	if ((m_fOwnsData) && (m_pAllocatedMemory != NULL)) {
		free(m_pAllocatedMemory);
	}

	m_fOwnsData = true;
	m_pAllocatedMemory = NULL;
}
开发者ID:brycelelbach,项目名称:tempestmodel,代码行数:16,代码来源:DataContainer.cpp

示例13: makeDataChunks

namespace testDataChunk {
const char* threadsBuffer = "Threads";
const int nbThreads = 50;

int makeDataChunks(const int nbLoop, DataChunk& output) {
    int ret = 0;
    for (int i = 0; i < nbLoop; i++) {
        DataChunk chunk(threadsBuffer);
        ret = chunk.toInt();
        EXPECT_TRUE(chunk.isReferencing(threadsBuffer));
        output.reference(chunk);
    }
    return ret;
}

static std::promise<int> promises[nbThreads];
static std::future<int> futures[nbThreads];

DataChunk sharedData;

void detach_threads() {
    const int nbDataChunk = 1000;
    for (int i = 0; i < nbThreads; i++) {
        promises[i] = std::promise<int>();
        futures[i] = promises[i].get_future();
        std::thread([](std::promise<int>& p) {p.set_value(makeDataChunks(nbDataChunk,sharedData));},
                std::ref(promises[i])).detach();
    }
}

void wait_futures() {
    for (int i = 0; i < nbThreads; i++) {
        futures[i].wait();
        ASSERT_TRUE(sharedData.isReferencing(threadsBuffer));
        ASSERT_TRUE(futures[i].get() == sharedData.toInt());
    }
}

class KeyValueNode {
    public:
        KeyValueNode(const DataChunk&& key, const DataChunk&& data) :
                key(std::move(key)), data(std::move(data)) {
        }

        const DataChunk& getKey() {
            return key;
        }
        const DataChunk& getData() {
            return data;
        }
        void setData(const DataChunk& d) {
            data.reference(d);
        }
    private:
        DataChunk key;
        DataChunk data;
};

} // namespace testDataChunk
开发者ID:cyrinux,项目名称:eguan,代码行数:59,代码来源:testsDataChunk.cpp

示例14: GetTotalByteSize

size_t DataContainer::GetTotalByteSize() const {
	
	// Get the accumulated size of all DataChunks
	size_t sAccumulated = 0;

	for (size_t i = 0; i < m_vecDataChunks.size(); i++) {
		DataChunk * pDataChunk =
			reinterpret_cast<DataChunk*>(m_vecDataChunks[i]);

		// Verify byte alignment
		size_t sByteSize = pDataChunk->GetByteSize();
		if (sByteSize % sizeof(size_t) != 0) {
			_EXCEPTIONT("Misaligned array detected in DataContainer");
		}
		sAccumulated += sByteSize;
	}

	return sAccumulated;
}
开发者ID:brycelelbach,项目名称:tempestmodel,代码行数:19,代码来源:DataContainer.cpp

示例15: apply

void Compressor::apply(DataChunk& samples){
    switch( samples.getFormat()->bitsPerSample()/8){
        case 2:
            maxint =32767;break;
        case 1:
            maxint = 127;
            break;
    }
    b = (1.0-a2)*maxint;
    DiskreteEffect::apply(samples);
}
开发者ID:ReDetection,项目名称:sound-processor,代码行数:11,代码来源:Compressor.cpp


注:本文中的DataChunk类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。