本文整理汇总了C++中DataBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ DataBuffer类的具体用法?C++ DataBuffer怎么用?C++ DataBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: application_data
void TLSClient_Impl::application_data(DataBuffer record_plaintext)
{
if (conversation_state != cl_tls_state_connected)
throw Exception("Unexpected application data record received");
int pos = recv_out_data.get_size();
recv_out_data.set_size(pos + record_plaintext.get_size());
memcpy(recv_out_data.get_data() + pos, record_plaintext.get_data(), record_plaintext.get_size());
}
示例2:
DataBuffer * NetworkFunctions::createUpdateObjectBuffer(unsigned long netID)
{
GameObject * tempObject = gameObjects->getValue(netID);
if (tempObject == NULL) return NULL;
DataBuffer * tempBuffer = tempObject->serialize();
int functionIndex = EVENT_UPDATE_GAME_OBJECT;
tempBuffer->copy(0, &functionIndex, 4);
tempBuffer->copy(4, &netID, 4);
return tempBuffer;
}
示例3: SendMsg
int SSClient::SendMsg( Packet & packet )
{
DataBuffer * buff = packet.GetBuffer();
int iRet = SockSend( buff->GetReadPtr(), buff->GetDataSize());
if(iRet < 0)
return -1;
return 0;
}
示例4: append
void
append(DataBuffer<sz>& dst, SegmentedSectionPtr ptr, SectionSegmentPool& pool) {
Uint32 len = ptr.sz;
while(len > SectionSegment::DataLength) {
dst.append(ptr.p->theData, SectionSegment::DataLength);
ptr.p = pool.getPtr(ptr.p->m_nextSegment);
len -= SectionSegment::DataLength;
}
dst.append(ptr.p->theData, len);
}
示例5: getGfxFeatureMapData
DataBuffer*
GfxFeatureMapReplyPacket::getGfxFeatureMapData()
{
bool zipped = false;
DataBuffer* maybeZippedBuf = getGfxFeatureMapData( zipped );
if ( zipped ) {
// Zipped, means that we should unzip it.
// Check unzipped length.
int unzippedLength =
GunzipUtil::origLength( maybeZippedBuf->getBufferAddress(),
maybeZippedBuf->getBufferSize() );
// Unzip.
DataBuffer* unzippedBuf = new DataBuffer( unzippedLength );
int retVal = GunzipUtil::gunzip( unzippedBuf->getBufferAddress(),
unzippedBuf->getBufferSize(),
maybeZippedBuf->getBufferAddress(),
maybeZippedBuf->getBufferSize() );
delete maybeZippedBuf;
if ( retVal < 0 ) {
delete unzippedBuf;
return NULL;
}
// Better read past the bytes just to make sure..
unzippedBuf->readPastBytes( unzippedLength );
return unzippedBuf;
} else {
// Was already unzipped.
return maybeZippedBuf;
}
}
示例6: zbuffer
DataBuffer ZLibCompression::compress(const DataBuffer &data, bool raw, int compression_level, CompressionMode mode)
{
const int window_bits = 15;
DataBuffer zbuffer(1024*1024);
IODevice_Memory output;
int strategy = MZ_DEFAULT_STRATEGY;
switch (mode)
{
case default_strategy: strategy = MZ_DEFAULT_STRATEGY; break;
case filtered: strategy = MZ_FILTERED; break;
case huffman_only: strategy = MZ_HUFFMAN_ONLY; break;
case rle: strategy = MZ_RLE; break;
case fixed: strategy = MZ_FIXED; break;
}
mz_stream zs = { nullptr };
int result = mz_deflateInit2(&zs, compression_level, MZ_DEFLATED, raw ? -window_bits : window_bits, 8, strategy); // Undocumented: if wbits is negative, zlib skips header check
if (result != MZ_OK)
throw Exception("Zlib deflateInit failed");
try
{
zs.next_in = (unsigned char *) data.get_data();
zs.avail_in = data.get_size();
while (true)
{
zs.next_out = (unsigned char *) zbuffer.get_data();
zs.avail_out = zbuffer.get_size();
int result = mz_deflate(&zs, MZ_FINISH);
if (result == MZ_NEED_DICT) throw Exception("Zlib deflate wants a dictionary!");
if (result == MZ_DATA_ERROR) throw Exception("Zip data stream is corrupted");
if (result == MZ_STREAM_ERROR) throw Exception("Zip stream structure was inconsistent!");
if (result == MZ_MEM_ERROR) throw Exception("Zlib did not have enough memory to compress file!");
if (result == MZ_BUF_ERROR) throw Exception("Not enough data in buffer when Z_FINISH was used");
if (result != MZ_OK && result != MZ_STREAM_END) throw Exception("Zlib deflate failed while compressing zip file!");
int zsize = zbuffer.get_size() - zs.avail_out;
if (zsize == 0)
break;
output.write(zbuffer.get_data(), zsize);
if (result == MZ_STREAM_END)
break;
}
mz_deflateEnd(&zs);
}
catch (...)
{
mz_deflateEnd(&zs);
throw;
}
return output.get_data();
}
示例7: test_aes192_helper
void TestApp::test_aes192()
{
Console::write_line(" Header: aes192_encrypt.h and aes192_decrypt.h");
Console::write_line(" Class: AES192_Encrypt and AES192_Decrypt");
// Test data from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
// and http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CBC.pdf
test_aes192_helper(
"8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", // KEY
"000102030405060708090A0B0C0D0E0F", // IV
"6bc1bee22e409f96e93d7e117393172a" // PLAINTEXT
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710",
"4f021db243bc633d7178183a9fa071e8" // CIPHERTEXT
"b4d9ada9ad7dedf4e5e738763f69145a"
"571b242012fb7ae07fa9baac3df102e0"
"08b0e27988598881d920a9e64f5615cd"
);
const int test_data_length = 192;
unsigned char test_data[test_data_length];
std::vector<unsigned char> key;
std::vector<unsigned char> iv;
convert_ascii("8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B", key);
convert_ascii("000102030405060708090A0B0C0D0E0F", iv);
for (int cnt=0; cnt<test_data_length; cnt++)
{
test_data[cnt] = (unsigned char) cnt;
AES192_Encrypt aes192_encrypt;
aes192_encrypt.set_iv(&iv[0]);
aes192_encrypt.set_key(&key[0]);
aes192_encrypt.add(test_data, cnt+1);
aes192_encrypt.calculate();
AES192_Decrypt aes192_decrypt;
aes192_decrypt.set_iv(&iv[0]);
aes192_decrypt.set_key(&key[0]);
DataBuffer buffer = aes192_encrypt.get_data();
aes192_decrypt.add(buffer.get_data(), buffer.get_size());
bool result = aes192_decrypt.calculate();
if (!result)
fail();
DataBuffer buffer2 = aes192_decrypt.get_data();
if (buffer2.get_size() != cnt+1)
fail();
unsigned char *data_ptr2 = (unsigned char *) buffer2.get_data();
if (memcmp(data_ptr2, test_data, cnt+1))
fail();
}
}
示例8: test_aes128_helper
void TestApp::test_aes128()
{
Console::write_line(" Header: aes128_encrypt.h and aes128_decrypt.h");
Console::write_line(" Class: AES128_Encrypt and AES128_Decrypt");
// Test data from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
// and http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CBC.pdf
test_aes128_helper(
"2b7e151628aed2a6abf7158809cf4f3c", // KEY
"000102030405060708090A0B0C0D0E0F", // IV
"6bc1bee22e409f96e93d7e117393172a" // PLAINTEXT
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710",
"7649abac8119b246cee98e9b12e9197d" // CIPHERTEXT
"5086cb9b507219ee95db113a917678b2"
"73bed6b8e3c1743b7116e69e22229516"
"3ff1caa1681fac09120eca307586e1a7"
);
const int test_data_length = 128;
unsigned char test_data[test_data_length];
std::vector<unsigned char> key;
std::vector<unsigned char> iv;
convert_ascii("2B7E151628AED2A6ABF7158809CF4F3C", key);
convert_ascii("000102030405060708090A0B0C0D0E0F", iv);
for (int cnt=0; cnt<test_data_length; cnt++)
{
test_data[cnt] = (unsigned char) cnt;
AES128_Encrypt aes128_encrypt;
aes128_encrypt.set_iv(&iv[0]);
aes128_encrypt.set_key(&key[0]);
aes128_encrypt.add(test_data, cnt+1);
aes128_encrypt.calculate();
AES128_Decrypt aes128_decrypt;
aes128_decrypt.set_iv(&iv[0]);
aes128_decrypt.set_key(&key[0]);
DataBuffer buffer = aes128_encrypt.get_data();
aes128_decrypt.add(buffer.get_data(), buffer.get_size());
bool result = aes128_decrypt.calculate();
if (!result)
fail();
DataBuffer buffer2 = aes128_decrypt.get_data();
if (buffer2.get_size() != cnt+1)
fail();
unsigned char *data_ptr2 = (unsigned char *) buffer2.get_data();
if (memcmp(data_ptr2, test_data, cnt+1))
fail();
}
}
示例9: offsetBuff
bool POIInfo::load( const MC2String& filename, uint32 offset ) {
DataBuffer fileBuff;
fileBuff.memMapFile( filename.c_str() );
DataBuffer offsetBuff( fileBuff.getBufferAddress() + offset,
fileBuff.getBufferSize() - offset );
load( offsetBuff );
return true;
}
示例10: integrity
//
// Basic integrity test.
//
void integrity()
{
ClientSession ss(CssmAllocator::standard(), CssmAllocator::standard());
printf("* Generating random sample: ");
DataBuffer<11> sample;
ss.generateRandom(sample);
for (uint32 n = 0; n < sample.length(); n++)
printf("%.2x", ((unsigned char *)sample)[n]);
printf("\n");
}
示例11: IfFailGo
// --------------------------------------------------------------------------------------
//
// Gets next hot heap (*pHotHeap, of index *pHotHeapIndex) from the heaps directory.
// Returns S_OK and fills *pHotHeap and *pHotHeapIndex with the next code:HotHeap information.
// Returns S_FALSE, if the last hot heap was already returned. Clears *pHotHeap and *pHotHeapIndex in this
// case.
// Returns error code if the format is invalid. Clears *pHotHeap and *pHotHeapIndex in this case.
//
__checkReturn
HRESULT
HotHeapsDirectoryIterator::GetNext(
HotHeap *pHotHeap,
HeapIndex *pHotHeapIndex)
{
HRESULT hr;
DataBuffer hotHeapHeaderData;
DataBuffer hotHeapData;
struct HotHeapsDirectoryEntry *pEntry;
if (!m_RemainingHeapsDirectoryData.GetData<struct HotHeapsDirectoryEntry>(
&pEntry))
{
hr = S_FALSE;
goto ErrExit;
}
if (!HeapIndex::IsValid(pEntry->m_nHeapIndex))
{
Debug_ReportError("Invalid hot heaps directory format - invalid heap index.");
IfFailGo(METADATA_E_INVALID_FORMAT);
}
pHotHeapIndex->Set(pEntry->m_nHeapIndex);
hotHeapHeaderData = m_HotHeapsData;
if (!hotHeapHeaderData.SkipToExactSize(pEntry->m_nHeapHeaderStart_NegativeOffset))
{
Debug_ReportError("Invalid hot heaps directory format - heap header offset reaches in front of of hot heaps data.");
IfFailGo(METADATA_E_INVALID_FORMAT);
}
struct HotHeapHeader *pHeader;
if (!hotHeapHeaderData.PeekData<struct HotHeapHeader>(&pHeader))
{
Debug_ReportError("Invalid hot heaps directory format - heap header reaches behind hot heaps data.");
IfFailGo(METADATA_E_INVALID_FORMAT);
}
hotHeapData = m_HotHeapsData;
if (!hotHeapData.TruncateBySize(pEntry->m_nHeapHeaderStart_NegativeOffset))
{
Debug_ReportInternalError("There's a bug because previous call to SkipToExactSize succeeded.");
IfFailGo(METADATA_E_INVALID_FORMAT);
}
IfFailGo(pHotHeap->Initialize(pHeader, hotHeapData));
_ASSERTE(hr == S_OK);
return hr;
ErrExit:
pHotHeap->Clear();
pHotHeapIndex->SetInvalid();
return hr;
} // HotHeapsDirectoryIterator::GetNext
示例12: saveBuffer
void saveBuffer( const DataBuffer& buff, int fd ) throw (MC2String)
{
int retVal = write( fd,
buff.getBufferAddress(),
buff.getCurrentOffset() );
if ( retVal == -1 ) {
throw MC2String("[DBU]: Could not write: ") + strerror(errno);
} else if ( uint32(retVal) != buff.getCurrentOffset() ) {
throw MC2String("[DBU]: Could not write buffer. Short byte count");
}
}
示例13: bufferData
bool StreamSoundSource::fillBufferAndQueue(uint buffer)
{
if(m_waitingFile)
return false;
// fill buffer
static DataBuffer<char> bufferData(2*STREAM_FRAGMENT_SIZE);
ALenum format = m_soundFile->getSampleFormat();
int maxRead = STREAM_FRAGMENT_SIZE;
if(m_downMix != NoDownMix)
maxRead *= 2;
int bytesRead = 0;
do {
bytesRead += m_soundFile->read(&bufferData[bytesRead], maxRead - bytesRead);
// end of sound file
if(bytesRead < maxRead) {
if(m_looping)
m_soundFile->reset();
else {
m_eof = true;
break;
}
}
} while(bytesRead < maxRead);
if(bytesRead > 0) {
if(m_downMix != NoDownMix) {
if(format == AL_FORMAT_STEREO16) {
assert(bytesRead % 2 == 0);
bytesRead /= 2;
uint16_t *data = (uint16_t*)bufferData.data();
for(int i=0;i<bytesRead/2;i++)
data[i] = data[2*i + (m_downMix == DownMixLeft ? 0 : 1)];
format = AL_FORMAT_MONO16;
}
}
alBufferData(buffer, format, &bufferData[0], bytesRead, m_soundFile->getRate());
ALenum err = alGetError();
if(err != AL_NO_ERROR)
g_logger.error(stdext::format("unable to refill audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err)));
alSourceQueueBuffers(m_sourceId, 1, &buffer);
err = alGetError();
if(err != AL_NO_ERROR)
g_logger.error(stdext::format("unable to queue audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err)));
}
// return false if there aren't more buffers to fill
return (bytesRead >= STREAM_FRAGMENT_SIZE && !m_eof);
}
示例14: savePoint
bool ReadSingleSensor::Response::match(DataBuffer& data)
{
const uint16 TOTAL_BYTES = 5;
//if there aren't enough bytes in the buffer to match the response
if(data.bytesRemaining() < TOTAL_BYTES)
{
//not a good response
m_success = false;
return false;
}
//create a save point with the data
ReadBufferSavePoint savePoint(&data);
//verify the command id
if(data.read_uint8() != 0x03)
{
//not a good response
m_success = false;
return false;
}
uint16 sensorVal = data.read_uint16();
ChecksumBuilder checksum;
checksum.append_uint16(sensorVal); //value of the requested channel
//verify the checksum (only a checksum on the actual data value)
if(checksum.simpleChecksum() != data.read_uint16())
{
//not a good response
m_success = false;
return false;
}
//if we made it this far, the bytes match the expected response
m_success = true;
m_sensorValue = sensorVal;
//commit the current read position
savePoint.commit();
//we have fully matched the response
m_fullyMatched = true;
//notify that the response was matched
m_matchCondition.notify();
return true;
}
示例15: strcpy
void Texture::create(char *name, char *filename, unsigned char relativePath, unsigned int flags,
unsigned char filter, float anisotropicFilter) {
strcpy(this->name, name);
DataBuffer *dataBuffer = new DataBuffer();
dataBuffer->read(filename, relativePath);
if (dataBuffer->getSize()) {
load(dataBuffer);
generateId(flags, filter, anisotropicFilter);
freePixel();
delete dataBuffer;
}
}