#include "jsoncpp-src-0.5.0/include/json/json.h"
enum class ePARAM_TYPE : BYTE
{
ePARAM_BOOL = 0,
ePARAM_CHAR,
ePARAM_WCHAR,
ePARAM_BYTE,
ePARAM_SHORT,
ePARAM_INT,
ePARAM_INT64,
ePARAM_FLOAT,
ePARAM_DOUBLE,
ePARAM_STRING,
};
bool CPacketHandler_IAP::BindValue( const Json::Value& jsResult, OUT VOID* pValue,
ePARAM_TYPE eType, const char* szArrayName, unsigned int nValueSize )
{
if (nullptr == szArrayName) return false;
if (0 >= nValueSize) return false;
switch (eType)
{
case ePARAM_TYPE::ePARAM_BOOL:
{
bool* pnValue = (bool*)pValue;
*pnValue = jsResult[szArrayName].asBool();
}
break;
case ePARAM_TYPE::ePARAM_CHAR:
{
std::string strValue = jsResult[szArrayName].asString();
if ((int)( strValue.size() ) > nValueSize)
return false;
strcpy( (char*)pValue, strValue.c_str() );
}
break;
case ePARAM_TYPE::ePARAM_WCHAR:
{
std::string strValue = jsResult[szArrayName].asString();
if ((int)( strValue.size() ) > nValueSize)
return false;
std::wstring wstrValue;
CStringConv::AnsiToWide( strValue.c_str(), wstrValue );
wcscpy( (wchar_t*)pValue, wstrValue.c_str() );
}
break;
case ePARAM_TYPE::ePARAM_BYTE:
{
int nValue = jsResult[szArrayName].asInt();
if (( std::numeric_limits<BYTE>::max )( ) < nValue)
return false;
BYTE* pbyValue = (BYTE*)pValue;
*pbyValue = (BYTE)nValue;
}
break;
case ePARAM_TYPE::ePARAM_SHORT:
{
int nValue = jsResult[szArrayName].asInt();
if (( std::numeric_limits<short>::max )( ) < nValue)
return false;
short* pshValue = (short*)pValue;
*pshValue = (short)nValue;
}
break;
case ePARAM_TYPE::ePARAM_INT:
{
int* pnValue = (int*)pValue;
*pnValue = jsResult[szArrayName].asInt();
}
break;
case ePARAM_TYPE::ePARAM_INT64:
{
__int64* plnValue = (__int64*)pValue;
*plnValue = jsResult[szArrayName].asInt64();
}
break;
case ePARAM_TYPE::ePARAM_FLOAT:
{
float* pfValue = (float*)pValue;
*pfValue = jsResult[szArrayName].asFloat();
}
break;
case ePARAM_TYPE::ePARAM_DOUBLE:
{
double* plfValue = (double*)pValue;
*plfValue = jsResult[szArrayName].asDouble();
}
break;
case ePARAM_TYPE::ePARAM_STRING:
{
std::string* pstrValue = ( std::string* )pValue;
*pstrValue = jsResult[szArrayName].asString();
}
break;
} // !switch
return true;
}
string strRead = szBuffer;
Json::Value jsRoot;
Json::Reader jsReader;
bool bResult = jsReader.parse( strRead.c_str(), jsRoot );
int nItemID = 0;
BindValue( jsRoot, &nItemID, ePARAM_TYPE::ePARAM_INT, "item_id", sizeof( int ) );
'[ Programing ] > C++' 카테고리의 다른 글
스레드 관련 정리. (0) | 2021.09.28 |
---|---|
C++ JSON 파싱 (0) | 2021.09.17 |
C++ 시간 차이 -> 남은 시간 계산하기. (0) | 2020.12.23 |
C++ int YYYMMDD -> DATE로 설정하기. (0) | 2020.12.23 |
C++ int YYYMMDDHH -> DATE로 설정하기. (0) | 2020.12.23 |