/*******************************************************************************
* Filename: PacketPool.cpp *
* Author: 夏磊 *
* eMail: None. *
* Tel: None. *
* Date: 2017-8-4 *
* Description: 数据包池 *
* Reference: None. *
* Module: 数据转换 *
* Version history: *
*------------------------------------------------------------------------------*
* Version YYYY-MM-DD-INDEX Modified By Description *
* 1.0.0 2017-8-4 夏磊 创建初始版本 *
*******************************************************************************/
/*----------------------------------------------------------------------------*/
/* Include Files */
/*----------------------------------------------------------------------------*/
#include "PacketPool.h"
#include "pbc.h"
#include <assert.h>
/*----------------------------------------------------------------------------*/
/* Function Declaration */
/*----------------------------------------------------------------------------*/
//-----------------------------------------------------------------------------
// FunctionName: Node_cl
// Description: 默认构造函数
//-----------------------------------------------------------------------------
Packet_cl::Node_cl::Node_cl()
: m_pclPacket(NULL)
, m_pstWriteMessage(NULL)
, m_pstReadMessage(NULL)
{
}
//-----------------------------------------------------------------------------
// FunctionName: Node_cl
// Description: 构造函数(写数据)
//-----------------------------------------------------------------------------
Packet_cl::Node_cl::Node_cl(
IN Packet_cl* pclPacket, //数据包
IN pbc_wmessage* pstWriteMessage //写入数据
)
: m_pclPacket(pclPacket)
, m_pstWriteMessage(pstWriteMessage)
, m_pstReadMessage(NULL)
{
assert(pclPacket && pstWriteMessage);
if (m_pclPacket)
{
m_pclPacket->AddRef();
}
}
//-----------------------------------------------------------------------------
// FunctionName: Node_cl
// Description: 构造函数(读数据)
//-----------------------------------------------------------------------------
Packet_cl::Node_cl::Node_cl(
IN Packet_cl* pclPacket, //数据包
IN pbc_rmessage* pstReadMessage //读取数据
)
: m_pclPacket(pclPacket)
, m_pstWriteMessage(NULL)
, m_pstReadMessage(pstReadMessage)
{
assert(pclPacket && pstReadMessage);
if (m_pclPacket)
{
m_pclPacket->AddRef();
}
}
//-----------------------------------------------------------------------------
// FunctionName: Node_cl
// Description: 复制构造函数
//-----------------------------------------------------------------------------
Packet_cl::Node_cl::Node_cl(
IN const Node_cl& clNode //节点
)
: m_pclPacket(NULL)
, m_pstWriteMessage(NULL)
, m_pstReadMessage(NULL)
{
operator=(clNode);
}
//-----------------------------------------------------------------------------
// FunctionName: ~Node_cl
// Description: 析构函数
//-----------------------------------------------------------------------------
Packet_cl::Node_cl::~Node_cl()
{
Clear();
}
//-----------------------------------------------------------------------------
// FunctionName: operator=
// Description: 赋值复制操作符
//-----------------------------------------------------------------------------
Packet_cl::Node_cl& //节点
Packet_cl::Node_cl::operator=(
IN const Node_cl& clNode //节点
)
{
if (this != &clNode)
{
Clear();
m_pstWriteMessage = clNode.m_pstWriteMessage;
m_pstReadMessage = clNode.m_pstReadMessage;
m_pclPacket = clNode.m_pclPacket;
if (m_pclPacket)
{
m_pclPacket->AddRef();
}
}
return *this;
}
//-----------------------------------------------------------------------------
// FunctionName: IsNull
// Description: 检查是否为空
//-----------------------------------------------------------------------------
BOOLEAN //为空
Packet_cl::Node_cl::IsNull() const
{
return m_pclPacket == NULL;
}
//-----------------------------------------------------------------------------
// FunctionName: Clear
// Description: 清除数据
//-----------------------------------------------------------------------------
void
Packet_cl::Node_cl::Clear()
{
m_pstWriteMessage = NULL;
m_pstReadMessage = NULL;
if (m_pclPacket)
{
m_pclPacket->DecreaseRef();
m_pclPacket = NULL;
}
}
//-----------------------------------------------------------------------------
// FunctionName: Write
// Description: 写入32位整数
//-----------------------------------------------------------------------------
void
Packet_cl::Node_cl::Write(
IN const CHAR* pcFieldName, //字段名
IN INT32 iData //数据
)
{
CheckWrite();
INT32 iResult = pbc_wmessage_integer(m_pstWriteMessage, pcFieldName, iData, 0);
assert(iResult != -1);
}
//-----------------------------------------------------------------------------
// FunctionName: Write
// Description: 写入32位无符号整数
//-----------------------------------------------------------------------------
void
Packet_cl::Node_cl::Write(
IN const CHAR* pcFieldName, //字段名
IN DWORD dwData //数据
)
{
Write(pcFieldName, INT32(dwData));
}
//-----------------------------------------------------------------------------
// FunctionName: Write
// Description: 写入64位整数
//-----------------------------------------------------------------------------
void
Packet_cl::Node_cl::Write(
IN const CHAR* pcFieldName, //字段名
IN INT64 lData //数据
)
{
CheckWrite();
const UINT32* puiData = reinterpret_cast<const UINT32*>(&lData);
INT32 iResult = pbc_wmessage_integer(m_pstWriteMessage, pcFieldName, puiData[0], puiData[1]);
assert(iResult != -1);
}
//-----------------------------------------------------------------------------
// FunctionName: Write
// Description: 写入单精度浮点数
//-----------------------------------------------------------------------------
void
Packet_cl::Node_cl::Write(
IN const CHAR* pcFieldName, //字段名
IN FLOAT fData //数据
)
{
Write(pcFieldName, DOUBLE(fData));
}
//-----------------------------------------------------------------------------
// FunctionName: Write
// Description: 写入双精度浮点数
//-----------------------------------------------------------------------------
void
Packet_cl::Node_cl::Write(
IN const CHAR* pcFieldName, //字段名
IN DOUBLE dData //数据
)
{
CheckWrite();
INT32 iResult = pbc_wmessage_real(m_pstWriteMessage, pcFieldName, dData);
assert(iResult != -1);
}
//-----------------------------------------------------------------------------
// FunctionName: Write
// Description: 写入字符串
//-----------------------------------------------------------------------------
void
Packet_cl::Node_cl::Write(
IN const CHAR* pcFieldName, //字段名
IN const CHAR* pcData //数据
)
{