- 博客(1)
- 资源 (5)
- 收藏
- 关注
序列化反序列化源码
namespace ly{
namespace serialize{
static const int UINT64_HEX_BUF_LEN = 17;
static const int BUF_BLK_SIZE = 4096;
class CDummy {
public:
CDummy(const char * szName):m_pName(szName){}
std::string GetName(){return m_pName;}
private:
const char * m_pName;
};
2015-12-11
序列化&反序列化源码
支持网络/本地数据序列化及反序列化
struct WlogRecord{
WlogRecord();
WlogRecord(uint64_t bigid, const std::string &sqlstr, const std::string& dbname);
void Reset();
uint16_t CurrentMaxVersion;
uint64_t bigid;
uint64_t logid;
std::string sqlstr;
std::string dbname;
/////////
//int vsid;
uint32_t enqueue_times;
uint16_t GetVersion();
virtual bool Serialize(CByteStreamMemory& bs)
{
bs & bigid;
bs & logid;
bs & sqlstr;
bs & dbname;
bs & enqueue_times;
if(!bs.isGood()) return true; // 兼容之前没有inout型参数的情况
return bs.isGood();
}
};
**************************序列化*****************************
char* pBuf = new char[MAX_BUF_LEN];
CByteStreamMemory bs(pBuf, MAX_BUF_LEN);
bs.setVersion(m_currentWlog.GetVersion());
bs.isStoring(true);
if(!m_currentWlog.Serialize(bs))
{
log->error("Sql request log Serialize(bs) failed.", false);
continue;
}
*************************反乎列化****************************
CByteStreamMemory bss(pBuf, MAX_BUF_LEN);
bss.isStoring(false);
WlogRecord currentWlog;
currentWlog.Serialize(bss);
2015-11-20
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人