本文整理汇总了C++中CAutoFile::GetSerializeSize方法的典型用法代码示例。如果您正苦于以下问题:C++ CAutoFile::GetSerializeSize方法的具体用法?C++ CAutoFile::GetSerializeSize怎么用?C++ CAutoFile::GetSerializeSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAutoFile
的用法示例。
在下文中一共展示了CAutoFile::GetSerializeSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dumpbootstrap
Value dumpbootstrap(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error(
"dumpbootstrap \"destination\" \"blocks\"\n"
"\nCreates a bootstrap format block dump of the blockchain in destination, which can be a directory or a path with filename, up to the given block number.");
string strDest = params[0].get_str();
int nBlocks = params[1].get_int();
if (nBlocks < 0 || nBlocks > nBestHeight)
throw runtime_error("Block number out of range.");
boost::filesystem::path pathDest(strDest);
if (boost::filesystem::is_directory(pathDest))
pathDest /= "bootstrap.dat";
try {
FILE* file = fopen(pathDest.string().c_str(), "wb");
if (!file)
throw JSONRPCError(RPC_MISC_ERROR, "Error: Could not open bootstrap file for writing.");
CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION);
if (!fileout)
throw JSONRPCError(RPC_MISC_ERROR, "Error: Could not open bootstrap file for writing.");
for (int nHeight = 0; nHeight <= nBlocks; nHeight++)
{
CBlock block;
CBlockIndex* pblockindex = FindBlockByHeight(nHeight);
block.ReadFromDisk(pblockindex, true);
fileout << FLATDATA(Params().MessageStart()) << fileout.GetSerializeSize(block) << block;
}
} catch(const boost::filesystem::filesystem_error &e) {
throw JSONRPCError(RPC_MISC_ERROR, "Error: Bootstrap dump failed!");
}
return Value::null;
}