序列化&反序列化源码

时间:2018-12-10 13:37:31
【文件属性】:
文件名称:序列化&反序列化源码
文件大小:19KB
文件格式:H
更新时间:2018-12-10 13:37:31
序列化 支持网络/本地数据序列化及反序列化 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);

网友评论