commitmonitor Code
Monitor your SVN repositories and notifies you on new commits
Brought to you by:
steveking
--- a/trunk/src/SerializeUtils.cpp +++ b/trunk/src/SerializeUtils.cpp @@ -20,7 +20,8 @@ #include "SerializeUtils.h" #include <assert.h> -char CSerializeUtils::buffer[4096] = {0}; +char CSerializeUtils::buffer[SERIALIZEBUFFERSIZE] = {0}; +wchar_t CSerializeUtils::wbuffer[SERIALIZEBUFFERSIZE] = {0}; CSerializeUtils::CSerializeUtils(void) { @@ -79,7 +80,6 @@ if (fwrite(&type, sizeof(type), 1, hFile)) { size_t length = str.size(); - assert(length < (1024*100)); if (fwrite(&length, sizeof(length), 1, hFile)) { if (fwrite(str.c_str(), sizeof(char), length, hFile)>=0) @@ -98,7 +98,6 @@ SerializeTypes type = SerializeType_Buffer; if (fwrite(&type, sizeof(type), 1, hFile)) { - assert(len < (1024*100)); if (fwrite(&len, sizeof(len), 1, hFile)) { if (fwrite(pbData, sizeof(BYTE), len, hFile)>=0) @@ -118,134 +117,121 @@ size_t length = 0; if (fread(&length, sizeof(length), 1, hFile)) { - if (length < (1024*100)) + if (length) { - if (length) - { - if (length < 4096) - { - if (fread(buffer, sizeof(char), length, hFile)) - { - str = string(buffer, length); - return true; - } - } - char * pBuffer = new char[length]; - if (fread(pBuffer, sizeof(char), length, hFile)) - { - str = string(pBuffer, length); - delete [] pBuffer; - return true; - } - delete [] pBuffer; - } - else - { - str = string(""); - return true; - } - } - } - } - } - return false; -} - -bool CSerializeUtils::LoadString(const unsigned char *& buf, std::string &str) -{ - SerializeTypes type = *((SerializeTypes*)buf); - buf += sizeof(SerializeTypes); - - if (type == SerializeType_String) - { - size_t length = *((size_t *)buf); - buf += sizeof(size_t); - if (length < (1024*100)) - { - if (length) - { - str = string((const char *)buf, length); - buf += length; - return true; - } - str = string(""); - return true; - } - } - return false; -} - -bool CSerializeUtils::LoadString(FILE * hFile, wstring& str) -{ - string tempstr; - if (LoadString(hFile, tempstr)) - { - str = CUnicodeUtils::StdGetUnicode(tempstr); - return true; - } - return false; -} - -bool CSerializeUtils::LoadString(const unsigned char *& buf, wstring& str) -{ - SerializeTypes type = *((SerializeTypes*)buf); - buf += sizeof(SerializeTypes); - - if (type == SerializeType_String) - { - size_t length = *((size_t *)buf); - buf += sizeof(size_t); - if (length < (1024*100)) - { - if (length) - { - int size = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, length, NULL, 0); - if (size < 4096) - { - TCHAR wide[4096]; - int ret = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, length, wide, size); - str = wstring(wide, ret); + if (length < SERIALIZEBUFFERSIZE) + { + if (fread(buffer, sizeof(char), length, hFile)) + { + str = string(buffer, length); + return true; + } + } + char * pBuffer = new char[length]; + if (fread(pBuffer, sizeof(char), length, hFile)) + { + str = string(pBuffer, length); + delete [] pBuffer; + return true; + } + delete [] pBuffer; } else { - wchar_t * wide = new wchar_t[size+1]; - int ret = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, length, wide, size); - str = wstring(wide, ret); - delete [] wide; + str = string(""); + return true; } - buf += length; - return true; - } - str = wstring(_T("")); - return true; - } - } - return false; -} - -bool CSerializeUtils::LoadBuffer(const unsigned char *& buf, BYTE *& pbData, size_t & len) -{ - SerializeTypes type = *((SerializeTypes*)buf); - buf += sizeof(SerializeTypes); - - if (type == SerializeType_Buffer) + } + } + } + return false; +} + +bool CSerializeUtils::LoadString(const unsigned char *& buf, std::string &str) +{ + SerializeTypes type = *((SerializeTypes*)buf); + buf += sizeof(SerializeTypes); + + if (type == SerializeType_String) { size_t length = *((size_t *)buf); buf += sizeof(size_t); - if (length < (1024*100)) - { - if (length) - { - pbData = new BYTE[length]; - memcpy(pbData, buf, length); - len = length; - buf += length; - return true; - } - len = 0; - pbData = NULL; - return true; - } - } - return false; -} + if (length) + { + str = string((const char *)buf, length); + buf += length; + return true; + } + str = string(""); + return true; + } + return false; +} + +bool CSerializeUtils::LoadString(FILE * hFile, wstring& str) +{ + string tempstr; + if (LoadString(hFile, tempstr)) + { + str = CUnicodeUtils::StdGetUnicode(tempstr); + return true; + } + return false; +} + +bool CSerializeUtils::LoadString(const unsigned char *& buf, wstring& str) +{ + SerializeTypes type = *((SerializeTypes*)buf); + buf += sizeof(SerializeTypes); + + if (type == SerializeType_String) + { + size_t length = *((size_t *)buf); + buf += sizeof(size_t); + if (length) + { + int size = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, length, NULL, 0); + if (size < SERIALIZEBUFFERSIZE) + { + int ret = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, length, wbuffer, size); + str = wstring(wbuffer, ret); + } + else + { + wchar_t * wide = new wchar_t[size+1]; + int ret = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, length, wide, size); + str = wstring(wide, ret); + delete [] wide; + } + buf += length; + return true; + } + str = wstring(_T("")); + return true; + } + return false; +} + +bool CSerializeUtils::LoadBuffer(const unsigned char *& buf, BYTE *& pbData, size_t & len) +{ + SerializeTypes type = *((SerializeTypes*)buf); + buf += sizeof(SerializeTypes); + + if (type == SerializeType_Buffer) + { + size_t length = *((size_t *)buf); + buf += sizeof(size_t); + if (length) + { + pbData = new BYTE[length]; + memcpy(pbData, buf, length); + len = length; + buf += length; + return true; + } + len = 0; + pbData = NULL; + return true; + } + return false; +}