本文整理汇总了C++中MemoryBuffer::GetDataLength方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::GetDataLength方法的具体用法?C++ MemoryBuffer::GetDataLength怎么用?C++ MemoryBuffer::GetDataLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::GetDataLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DebugMsg
int ehttp:: parse_message( int fd, void *cookie, MemoryBuffer &message )
{
if( !contentlength ) return EHTTP_ERR_OK;
DebugMsg( "HTTPServer-embed","Parsed content length:%d\r\n",contentlength);
DebugMsg( "HTTPServer-embed","Actual message length read in:%d\r\n", message.GetDataLength());
unsigned int recieved = message.GetDataLength();
while( recieved < contentlength)
{
input_buffer[0]=0;
int r = recv((int)fd, input_buffer, INPUT_BUFFER_SIZE, 0);
if( r < 0 )
return EHTTP_ERR_GENERIC;
message.Add(input_buffer, r);
DebugMsg( "HTTPServer-embed", "Message Length: %d", r);
// Decrement our recieved content
recieved += r;
}
if(request_header["Content-Type"].find("multipart") == 0)
{
DebugMsg("HTTPServer-embed", "Parsing Multipart Upload");
if(parse_out_chunks(cookie, message, post_chunks) == EHTTP_ERR_OK) {
if(parse_out_entries(cookie, post_chunks) == EHTTP_ERR_OK) {
if(parse_out_entry_headers( cookie, post_chunks) == EHTTP_ERR_OK) {
DebugMsg("HTTPServer-embed", "Parsing Successful");
}
}
}
}
else
{
// Got here, good, we got the entire reported msg length
//DebugMsg( "HTTPServer-embed","Entire message is <%s>\r\n",message.c_str());
string test = (char*)message.GetData();
parse_out_pairs(cookie, test, post_parms);
}
return EHTTP_ERR_OK;
}
示例2: parse_out_chunks
int ehttp::parse_out_chunks( void *cookie, MemoryBuffer& memoryBuffer, vector<HTTP_CHUNK> &chunks)
{
const BYTE * bufferAddr = (BYTE*)memoryBuffer.GetData();
DWORD bufferSize = memoryBuffer.GetDataLength();
// Get our boundary to search for
string boundary = request_header["Content-Type"];
boundary = "--" + boundary.substr(boundary.find("boundary=") + 9);
// Now get a pointer to each chunk
BYTE* temp = (BYTE*)bufferAddr;
DWORD boundaryLen = boundary.length();
DWORD foundChunkCount = 0;
while((temp + boundaryLen) < (bufferAddr + bufferSize)) {
if(memcmp(temp, boundary.c_str(), boundaryLen) == 0) {
HTTP_CHUNK tempChunk;
tempChunk.Data = temp;
// Initialize the file data for this chunk
tempChunk.FileData.Data = NULL;
tempChunk.FileData.Length = 0;
chunks.push_back(tempChunk);
temp += boundaryLen;
foundChunkCount++;
} else
temp++;
}
// Now we have our chunk positions, lets get our lengths
vector<DWORD> sizes;
DWORD size = 0;
for(DWORD x = 0; x < foundChunkCount - 1; x++) {
size = chunks.at(x + 1).Data - chunks.at(x).Data;
//size = chunks.at(x + 1) - chunks.at(x);
chunks.at(x).Length = size;
}
size = (bufferAddr + bufferSize) - chunks.at(foundChunkCount - 1).Data;
chunks.at(foundChunkCount - 1).Length = size;
#ifdef DUMP_TO_FILE
if(!FileExists("game:\\HTTPDumps\\")) _mkdir("game:\\HTTPDumps\\");
if(!FileExists("game:\\HTTPDumps\\Chunks\\")) _mkdir("game:\\HTTPDumps\\Chunks\\");
for(int nCount = 0; nCount < (int)chunks.size(); nCount++)
{
FILE * fHandle;
string fileName = sprintfaA("game:\\HTTPDumps\\Chunks\\ChunkDump_%d.bin", nCount);
fopen_s(&fHandle, fileName.c_str(), "wb");
fwrite(chunks.at(nCount).Data, 1, chunks.at(nCount).Length, fHandle);
fclose(fHandle);
}
#endif
// If it found chunks, return that it was successful
return foundChunkCount == 0 ? EHTTP_ERR_GENERIC : EHTTP_ERR_OK;
}
示例3: ConvertMemoryBufferToBMPBuffer
HRESULT ConvertMemoryBufferToBMPBuffer( MemoryBuffer &image_in, MemoryBuffer &image_out)
{
// Check to ensure that our data has a valid length before proceeding
if( image_in.GetDataLength() == 0 ) return S_FALSE;
// Set up a timer class to profile our code
ATG::Timer m_Timer;
double timeStart, timeStop;
// Begin Profiling our Texture Creation Code
timeStart = m_Timer.GetAbsoluteTime();
IDirect3DTexture9 * pTexture;
HRESULT retVal = D3DXCreateTextureFromFileInMemoryEx(
CFreestyleApp::getInstance().m_pd3dDevice,
image_in.GetData(),
image_in.GetDataLength(),
D3DX_DEFAULT_NONPOW2,
D3DX_DEFAULT_NONPOW2,
1,
D3DUSAGE_CPU_CACHED_MEMORY,
D3DFMT_LIN_A8R8G8B8,
D3DPOOL_DEFAULT,
D3DX_FILTER_NONE,
D3DX_FILTER_NONE,
0,
NULL,
NULL,
&pTexture
);
// End Profiling our Texture Creation Code
timeStop = m_Timer.GetAbsoluteTime();
DebugMsg("ConvertImageToBMP", "Texture Creation took %4.2f seconds to complete", (float)(timeStop - timeStart));
// If our texture was created successfully,
if(retVal = D3D_OK) {
//Begin Profiling our Data Manipulation Code
timeStart = m_Timer.GetAbsoluteTime();
// Get our level desc
D3DSURFACE_DESC desc;
pTexture->GetLevelDesc(0, &desc);
// Now lock our data
D3DLOCKED_RECT lock;
RECT rect = {0, 0, desc.Width, desc.Height};
pTexture->LockRect(0, &lock, &rect, D3DLOCK_READONLY);
//Read our data
DWORD headerSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
DWORD dataLen = lock.Pitch * desc.Height;
DWORD * dataBuffer = (DWORD*)malloc( dataLen + headerSize );
DWORD * address = (DWORD*)lock.pBits;
// Create file our header
BITMAPFILEHEADER* fHead = (BITMAPFILEHEADER*)dataBuffer;
fHead->bfType = 0x424D; // "BM"
fHead->bfSize = SwapDWORD(dataLen + headerSize);
fHead->bfReserved1 = 0;
fHead->bfReserved2 = 0;
fHead->bfOffBits = SwapDWORD(headerSize);
// Create our info header
BITMAPINFOHEADER* iHead = (BITMAPINFOHEADER*)(fHead + 1);
ZeroMemory(iHead, sizeof(BITMAPINFOHEADER));
iHead->biSize = SwapDWORD(sizeof(BITMAPINFOHEADER));
iHead->biWidth = SwapDWORD(desc.Width);
iHead->biHeight = SwapDWORD(desc.Height);
iHead->biPlanes = SwapWORD(1);
iHead->biBitCount = SwapWORD(32);
iHead->biSizeImage = SwapDWORD(dataLen);
// Copy over our raw (BGRA)
DWORD* rawPtr = (DWORD*)(iHead + 1);
for(int y = desc.Height - 1; y >= 0; y--) {
for(DWORD x = 0; x < desc.Width; x++) {
DWORD cp = (y * lock.Pitch) + (x * 4);
DWORD * temp = (DWORD*)(address + (cp / 4));
*rawPtr = SwapDWORD(*temp);
rawPtr++;
}
}
// Unlock our texture
pTexture->UnlockRect(0);
// End Profiling our Data Modification Code
timeStop = m_Timer.GetAbsoluteTime();
DebugMsg("ConvertImageToBMP", "Data Modification took %4.2f seconds to complete", (float)(timeStop - timeStart));
// Begin Profiling our Memory Copy Code
timeStart = m_Timer.GetAbsoluteTime();
// Copy our completed data to our new buffer
image_out.Add(dataBuffer, (headerSize + dataLen));
// End Profiling our Memory Copy Code
//.........这里部分代码省略.........