本文整理汇总了C++中ISerializer::binary方法的典型用法代码示例。如果您正苦于以下问题:C++ ISerializer::binary方法的具体用法?C++ ISerializer::binary怎么用?C++ ISerializer::binary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISerializer
的用法示例。
在下文中一共展示了ISerializer::binary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serialize
// unpack to strings to maintain protocol compatibility with older versions
void serialize(RawBlock& rawBlock, ISerializer& serializer) {
if (serializer.type() == ISerializer::INPUT) {
uint64_t blockSize;
serializer(blockSize, "block_size");
rawBlock.block.resize(static_cast<size_t>(blockSize));
} else {
auto blockSize = rawBlock.block.size();
serializer(blockSize, "block_size");
}
serializer.binary(rawBlock.block.data(), rawBlock.block.size(), "block");
if (serializer.type() == ISerializer::INPUT) {
uint64_t txCount;
serializer(txCount, "tx_count");
rawBlock.transactions.resize(static_cast<size_t>(txCount));
for (auto& txBlob : rawBlock.transactions) {
uint64_t txSize;
serializer(txSize, "tx_size");
txBlob.resize(txSize);
serializer.binary(txBlob.data(), txBlob.size(), "transaction");
}
} else {
auto txCount = rawBlock.transactions.size();
serializer(txCount, "tx_count");
for (auto& txBlob : rawBlock.transactions) {
auto txSize = txBlob.size();
serializer(txSize, "tx_size");
serializer.binary(txBlob.data(), txBlob.size(), "transaction");
}
}
}
示例2: serializeBlockHeader
void serializeBlockHeader(BlockHeader& header, ISerializer& serializer) {
serializer(header.majorVersion, "major_version");
if (header.majorVersion > BLOCK_MAJOR_VERSION_1) {
throw std::runtime_error("Wrong major version");
}
serializer(header.minorVersion, "minor_version");
serializer(header.timestamp, "timestamp");
serializer(header.previousBlockHash, "prev_id");
serializer.binary(&header.nonce, sizeof(header.nonce), "nonce");
}