本文整理汇总了C++中SNode::serialize方法的典型用法代码示例。如果您正苦于以下问题:C++ SNode::serialize方法的具体用法?C++ SNode::serialize怎么用?C++ SNode::serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SNode
的用法示例。
在下文中一共展示了SNode::serialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: report
int Slave::report(const string& master_ip, const int& master_port, const int32_t& transid, const vector<string>& filelist, const int& change)
{
vector<string> serlist;
for (vector<string>::const_iterator i = filelist.begin(); i != filelist.end(); ++ i)
{
struct stat s;
if (-1 == stat((m_strHomeDir + *i).c_str(), &s))
continue;
SNode sn;
sn.m_strName = *i;
sn.m_bIsDir = S_ISDIR(s.st_mode) ? 1 : 0;
sn.m_llTimeStamp = s.st_mtime;
sn.m_llSize = s.st_size;
char buf[1024];
sn.serialize(buf);
//update local
Address addr;
addr.m_strIP = "127.0.0.1";
addr.m_iPort = 0;
m_pLocalFile->update(buf, addr, change);
serlist.push_back(buf);
}
if (serlist.empty())
return 0;
SectorMsg msg;
msg.setType(1);
msg.setKey(0);
msg.setData(0, (char*)&transid, 4);
msg.setData(4, (char*)&m_iSlaveID, 4);
msg.setData(8, (char*)&change, 4);
int32_t num = serlist.size();
msg.setData(12, (char*)&num, 4);
int pos = 16;
for (vector<string>::iterator i = serlist.begin(); i != serlist.end(); ++ i)
{
int32_t bufsize = i->length() + 1;
msg.setData(pos, (char*)&bufsize, 4);
msg.setData(pos + 4, i->c_str(), bufsize);
pos += bufsize + 4;
}
cout << "report " << master_ip << " " << master_port << " " << num << endl;
if (m_GMP.rpc(master_ip.c_str(), master_port, &msg, &msg) < 0)
return -1;
if (msg.getType() < 0)
return *(int32_t*)msg.getData();
return 1;
}
示例2: reportMO
int Slave::reportMO(const std::string& master_ip, const int& master_port, const int32_t& transid)
{
vector<MemObj> tba;
vector<string> tbd;
if (m_InMemoryObjects.update(tba, tbd) <= 0)
return 0;
if (!tba.empty())
{
vector<string> serlist;
for (vector<MemObj>::const_iterator i = tba.begin(); i != tba.end(); ++ i)
{
SNode sn;
sn.m_strName = i->m_strName;
sn.m_bIsDir = 0;
sn.m_llTimeStamp = i->m_llCreationTime;
sn.m_llSize = 8;
char buf[1024];
sn.serialize(buf);
serlist.push_back(buf);
}
SectorMsg msg;
msg.setType(1);
msg.setKey(0);
msg.setData(0, (char*)&transid, 4);
msg.setData(4, (char*)&m_iSlaveID, 4);
int32_t num = serlist.size();
msg.setData(8, (char*)&num, 4);
int pos = 12;
for (vector<string>::iterator i = serlist.begin(); i != serlist.end(); ++ i)
{
int32_t bufsize = i->length() + 1;
msg.setData(pos, (char*)&bufsize, 4);
msg.setData(pos + 4, i->c_str(), bufsize);
pos += bufsize + 4;
}
if (m_GMP.rpc(master_ip.c_str(), master_port, &msg, &msg) < 0)
return -1;
}
if (!tbd.empty())
{
SectorMsg msg;
msg.setType(7);
msg.setKey(0);
msg.setData(0, (char*)&transid, 4);
msg.setData(4, (char*)&m_iSlaveID, 4);
int32_t num = tbd.size();
msg.setData(8, (char*)&num, 4);
int pos = 12;
for (vector<string>::iterator i = tbd.begin(); i != tbd.end(); ++ i)
{
int32_t bufsize = i->length() + 1;
msg.setData(pos, (char*)&bufsize, 4);
msg.setData(pos + 4, i->c_str(), bufsize);
pos += bufsize + 4;
}
if (m_GMP.rpc(master_ip.c_str(), master_port, &msg, &msg) < 0)
return -1;
}
return 0;
}
示例3: report
int Slave::report(const string& master_ip, const int& master_port, const int32_t& transid, const vector<string>& filelist, const int32_t& change)
{
vector<string> serlist;
if (change != FileChangeType::FILE_UPDATE_NO)
{
for (vector<string>::const_iterator i = filelist.begin(); i != filelist.end(); ++ i)
{
struct stat s;
if (-1 == stat ((m_strHomeDir + *i).c_str(), &s))
continue;
SNode sn;
sn.m_strName = *i;
sn.m_bIsDir = S_ISDIR(s.st_mode) ? 1 : 0;
sn.m_llTimeStamp = s.st_mtime;
sn.m_llSize = s.st_size;
Address addr;
addr.m_strIP = "127.0.0.1";
addr.m_iPort = 0;
sn.m_sLocation.insert(addr);
if (change == FileChangeType::FILE_UPDATE_WRITE)
{
// file may be created on write; in this case, create a new meta entry instead of update non-existing one
if (m_pLocalFile->update(sn.m_strName, sn.m_llTimeStamp, sn.m_llSize) < 0)
m_pLocalFile->create(sn);
}
else if (change == FileChangeType::FILE_UPDATE_NEW)
m_pLocalFile->create(sn);
else if (change == FileChangeType::FILE_UPDATE_REPLICA)
m_pLocalFile->create(sn);
char* buf = NULL;
sn.serialize(buf);
serlist.push_back(buf);
delete [] buf;
}
}
SectorMsg msg;
msg.setType(1);
msg.setKey(0);
msg.setData(0, (char*)&transid, 4);
msg.setData(4, (char*)&m_iSlaveID, 4);
msg.setData(8, (char*)&change, 4);
int32_t num = serlist.size();
msg.setData(12, (char*)&num, 4);
int pos = 16;
for (vector<string>::iterator i = serlist.begin(); i != serlist.end(); ++ i)
{
int32_t bufsize = i->length() + 1;
msg.setData(pos, (char*)&bufsize, 4);
msg.setData(pos + 4, i->c_str(), bufsize);
pos += bufsize + 4;
}
//TODO: if the current master is down, try a different master
if (m_GMP.rpc(master_ip.c_str(), master_port, &msg, &msg) < 0)
return -1;
if (msg.getType() < 0)
return *(int32_t*)msg.getData();
return 1;
}