本文整理汇总了C++中SNode::deserialize方法的典型用法代码示例。如果您正苦于以下问题:C++ SNode::deserialize方法的具体用法?C++ SNode::deserialize怎么用?C++ SNode::deserialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SNode
的用法示例。
在下文中一共展示了SNode::deserialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: list
int Client::list(const string& path, vector<SNode>& attr)
{
string revised_path = Metadata::revisePath(path);
SectorMsg msg;
msg.resize(65536);
msg.setType(101);
msg.setKey(m_iKey);
msg.setData(0, revised_path.c_str(), revised_path.length() + 1);
Address serv;
m_Routing.lookup(revised_path, serv);
login(serv.m_strIP, serv.m_iPort);
if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
return SectorError::E_CONNECTION;
if (msg.getType() < 0)
return *(int32_t*)(msg.getData());
string filelist = msg.getData();
unsigned int s = 0;
while (s < filelist.length())
{
int t = filelist.find(';', s);
SNode sn;
sn.deserialize(filelist.substr(s, t - s).c_str());
attr.insert(attr.end(), sn);
s = t + 1;
}
return attr.size();
}
示例2: stat
int Client::stat(const string& path, SNode& attr)
{
string revised_path = Metadata::revisePath(path);
SectorMsg msg;
msg.resize(65536);
msg.setType(102);
msg.setKey(m_iKey);
msg.setData(0, revised_path.c_str(), revised_path.length() + 1);
Address serv;
m_Routing.lookup(revised_path, serv);
login(serv.m_strIP, serv.m_iPort);
if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
return SectorError::E_CONNECTION;
if (msg.getType() < 0)
return *(int32_t*)(msg.getData());
attr.deserialize(msg.getData());
int n = (msg.m_iDataLength - SectorMsg::m_iHdrSize - 128) / 68;
char* al = msg.getData() + 128;
for (int i = 0; i < n; ++ i)
{
Address addr;
addr.m_strIP = al + 68 * i;
addr.m_iPort = *(int32_t*)(al + 68 * i + 64);
attr.m_sLocation.insert(addr);
}
// check local cache: updated files may not be sent to the master yet
m_StatCache.stat(path, attr);
return 0;
}
示例3: copy
DWORD WINAPI Slave::copy(LPVOID p)
#endif
{
Slave* self = ((Param3*)p)->serv_instance;
int transid = ((Param3*)p)->transid;
int dir = ((Param3*)p)->dir;
string src = ((Param3*)p)->src;
string dst = ((Param3*)p)->dst;
string master_ip = ((Param3*)p)->master_ip;
int master_port = ((Param3*)p)->master_port;
delete (Param3*)p;
if (src.c_str()[0] == '\0')
src = "/" + src;
if (dst.c_str()[0] == '\0')
dst = "/" + dst;
bool success = true;
queue<string> tr; // files to be replicated
queue<string> td; // directories to be explored
if (dir > 0)
td.push(src);
else
tr.push(src);
while (!td.empty())
{
// If the file to be replicated is a directory, recursively list all files first
string src_path = td.front();
td.pop();
// try list this path
SectorMsg msg;
msg.setType(101);
msg.setKey(0);
msg.setData(0, src_path.c_str(), src_path.length() + 1);
Address addr;
self->m_Routing.lookup(src_path, addr);
if (self->m_GMP.rpc(addr.m_strIP.c_str(), addr.m_iPort, &msg, &msg) < 0)
{
success = false;
break;
}
// the master only returns positive if this is a directory
if (msg.getType() >= 0)
{
// if this is a directory, create it, and put all files and sub-directories into the queue of files to be copied
// create a local dir
string dst_path = dst;
if (src != src_path)
dst_path += "/" + src_path.substr(src.length() + 1, src_path.length() - src.length() - 1);
//create at .tmp first, then move to real location
self->createDir(string(".tmp") + dst_path);
string filelist = msg.getData();
unsigned int s = 0;
while (s < filelist.length())
{
int t = filelist.find(';', s);
SNode sn;
sn.deserialize(filelist.substr(s, t - s).c_str());
if (sn.m_bIsDir)
td.push(src_path + "/" + sn.m_strName);
else
tr.push(src_path + "/" + sn.m_strName);
s = t + 1;
}
continue;
}
}
while (!tr.empty())
{
string src_path = tr.front();
tr.pop();
SNode tmp;
if (self->m_pLocalFile->lookup(src_path.c_str(), tmp) >= 0)
{
//if file is local, copy directly
//note that in this case, src != dst, therefore this is a regular "cp" command, not a system replication
//IMPORTANT!!!
//local files must be read directly from local disk, and cannot be read via datachn due to its limitation
string dst_path = dst;
if (src != src_path)
dst_path += "/" + src_path.substr(src.length() + 1, src_path.length() - src.length() - 1);
//copy to .tmp first, then move to real location
self->createDir(string(".tmp") + dst_path.substr(0, dst_path.rfind('/')));
//.........这里部分代码省略.........
示例4: copy
void* Slave::copy(void* p)
{
Slave* self = ((Param3*)p)->serv_instance;
int transid = ((Param3*)p)->transid;
string src = ((Param3*)p)->src;
string dst = ((Param3*)p)->dst;
string master_ip = ((Param3*)p)->master_ip;
int master_port = ((Param3*)p)->master_port;
delete (Param3*)p;
if (src.c_str()[0] == '\0')
src = "/" + src;
if (dst.c_str()[0] == '\0')
dst = "/" + dst;
SNode tmp;
if (self->m_pLocalFile->lookup(src.c_str(), tmp) >= 0)
{
//if file is local, copy directly
//note that in this case, src != dst, therefore this is a regular "cp" command, not a system replication
//TODO: check disk space
self->createDir(dst.substr(0, dst.rfind('/')));
string rhome = self->reviseSysCmdPath(self->m_strHomeDir);
string rsrc = self->reviseSysCmdPath(src);
string rdst = self->reviseSysCmdPath(dst);
system(("cp " + rhome + rsrc + " " + rhome + rdst).c_str());
// if the file has been modified during the replication, remove this replica
int type = (src == dst) ? +FileChangeType::FILE_UPDATE_REPLICA : +FileChangeType::FILE_UPDATE_NEW;
struct stat64 s;
if (stat64((self->m_strHomeDir + dst).c_str(), &s) < 0)
type = +FileChangeType::FILE_UPDATE_NO;
if (self->report(master_ip, master_port, transid, dst, type) < 0)
system(("rm " + rhome + rdst).c_str());
// clear this transaction
self->m_TransManager.updateSlave(transid, self->m_iSlaveID);
return NULL;
}
bool success = true;
queue<string> tr;
tr.push(src);
while (!tr.empty())
{
string src_path = tr.front();
tr.pop();
// try list this path
SectorMsg msg;
msg.setType(101);
msg.setKey(0);
msg.setData(0, src_path.c_str(), src_path.length() + 1);
Address addr;
self->m_Routing.lookup(src_path, addr);
if (self->m_GMP.rpc(addr.m_strIP.c_str(), addr.m_iPort, &msg, &msg) < 0)
{
success = false;
break;
}
if (msg.getType() >= 0)
{
// if this is a directory, put all files and sub-drectories into the queue of files to be copied
string filelist = msg.getData();
unsigned int s = 0;
while (s < filelist.length())
{
int t = filelist.find(';', s);
SNode sn;
sn.deserialize(filelist.substr(s, t - s).c_str());
tr.push(src_path + "/" + sn.m_strName);
s = t + 1;
}
continue;
}
// open the file and copy it to local
msg.setType(110);
msg.setKey(0);
int32_t mode = SF_MODE::READ;
msg.setData(0, (char*)&mode, 4);
int64_t reserve = 0;
msg.setData(4, (char*)&reserve, 8);
int32_t localport = self->m_DataChn.getPort();
msg.setData(12, (char*)&localport, 4);
msg.setData(16, "\0", 1);
msg.setData(80, src_path.c_str(), src_path.length() + 1);
//.........这里部分代码省略.........
示例5: deserialize
int Index::deserialize(ifstream& ifs, map<string, SNode>& metadata, const Address* addr)
{
vector<string> dirs;
dirs.resize(1024);
map<string, SNode>* currdir = &metadata;
int currlevel = 1;
while (!ifs.eof())
{
char tmp[4096];
tmp[4095] = 0;
char* buf = tmp;
ifs.getline(buf, 4096);
int len = strlen(buf);
if ((len <= 0) || (len >= 4095))
continue;
for (int i = 0; i < len; ++ i)
{
if (buf[i] == ' ')
{
buf[i] = '\0';
break;
}
}
int level = atoi(buf);
SNode sn;
sn.deserialize(buf + strlen(buf) + 1);
if ((!sn.m_bIsDir) && (NULL != addr))
{
sn.m_sLocation.clear();
sn.m_sLocation.insert(*addr);
}
if (level == currlevel)
{
(*currdir)[sn.m_strName] = sn;
dirs[level] = sn.m_strName;
}
else if (level == currlevel + 1)
{
map<string, SNode>::iterator s = currdir->find(dirs[currlevel]);
currdir = &(s->second.m_mDirectory);
currlevel = level;
(*currdir)[sn.m_strName] = sn;
dirs[level] = sn.m_strName;
}
else if (level < currlevel)
{
currdir = &metadata;
for (int i = 1; i < level; ++ i)
{
map<string, SNode>::iterator s = currdir->find(dirs[i]);
currdir = &(s->second.m_mDirectory);
}
currlevel = level;
(*currdir)[sn.m_strName] = sn;
dirs[level] = sn.m_strName;
}
}
return 0;
}
示例6: update
int Index::update(const string& fileinfo, const Address& loc, const int& type)
{
CMutexGuard mg(m_MetaLock);
SNode sn;
sn.deserialize(fileinfo.c_str());
sn.m_sLocation.insert(loc);
vector<string> dir;
parsePath(sn.m_strName.c_str(), dir);
if (dir.empty())
return -1;
string filename = *(dir.rbegin());
sn.m_strName = filename;
dir.erase(dir.begin() + dir.size() - 1);
map<string, SNode>* currdir = &m_mDirectory;
map<string, SNode>::iterator s;
for (vector<string>::iterator d = dir.begin(); d != dir.end(); ++ d)
{
s = currdir->find(*d);
if (s == currdir->end())
{
if ((type == 3) || (type == 2))
{
// this is for new files only
return -1;
}
SNode n;
n.m_strName = *d;
n.m_bIsDir = true;
n.m_llTimeStamp = sn.m_llTimeStamp;
n.m_llSize = 0;
(*currdir)[*d] = n;
s = currdir->find(*d);
}
s->second.m_llTimeStamp = sn.m_llTimeStamp;
currdir = &(s->second.m_mDirectory);
}
s = currdir->find(filename);
if (s == currdir->end())
{
if ((type == 3) || (type == 2))
{
// this is for new files only
return -1;
}
(*currdir)[filename] = sn;
return 1;
}
else
{
if ((type == 1) || (type == 2))
{
// modification to an existing copy
// this maybe a new file and the master already registered the file when it is created, so it is treated as an existing file too
if ((s->second.m_llSize != sn.m_llSize) || (s->second.m_llTimeStamp != sn.m_llTimeStamp))
{
s->second.m_llSize = sn.m_llSize;
s->second.m_llTimeStamp = sn.m_llTimeStamp;
s->second.m_sLocation.insert(loc);
}
return s->second.m_sLocation.size();
}
if (type == 3)
{
// a new replica
if (s->second.m_sLocation.find(loc) != s->second.m_sLocation.end())
return -1;
if ((s->second.m_llSize != sn.m_llSize) || (s->second.m_llTimeStamp != sn.m_llTimeStamp))
return -1;
s->second.m_sLocation.insert(loc);
return s->second.m_sLocation.size();
}
}
return -1;
}