本文整理汇总了C++中BinaryWriter::put_var_int方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryWriter::put_var_int方法的具体用法?C++ BinaryWriter::put_var_int怎么用?C++ BinaryWriter::put_var_int使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter::put_var_int方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serialize
void LedgerEntryVector::serialize(BinaryWriter& bw) const
{
bw.put_uint8_t(LEDGERENTRYVECTOR_CODE);
bw.put_var_int(leVec_.size());
for (auto& le : leVec_)
{
auto idSize = le.ID_.size();
size_t totalsize = idSize + 53;
bw.put_var_int(totalsize);
bw.put_var_int(idSize);
bw.put_BinaryData((uint8_t*)le.ID_.c_str(), idSize);
bw.put_uint64_t(le.value_);
bw.put_uint32_t(le.blockNum_);
bw.put_BinaryData(le.txHash_);
bw.put_uint32_t(le.index_);
bw.put_uint32_t(le.txTime_);
BitPacker<uint8_t> bp;
bp.putBit(le.isCoinbase_);
bp.putBit(le.isSentToSelf_);
bp.putBit(le.isChangeBack_);
bp.putBit(le.optInRBF_);
bw.put_BitPacker(bp);
}
}
示例2: serialize
BinaryData StackItem_MultiSig::serialize(void) const
{
BinaryWriter bw;
bw.put_uint32_t(id_);
bw.put_uint8_t(STACKITEM_MULTISIG_PREFIX);
bw.put_uint16_t(m_);
bw.put_var_int(sigs_.size());
for (auto& sig_pair : sigs_)
{
bw.put_uint16_t(sig_pair.first);
bw.put_var_int(sig_pair.second.getSize());
bw.put_BinaryData(sig_pair.second);
}
return bw.getData();
}
示例3: serializeWholeBlock
BinaryData BlockHeaderRef::serializeWholeBlock(bool withLead8Bytes) const
{
BinaryWriter serializedBlock;
uint32_t blksize = getBlockSize();
if(withLead8Bytes)
{
serializedBlock.reserve(blksize + 8);
serializedBlock.put_BinaryData(BtcUtils::MagicBytes_);
serializedBlock.put_uint32_t(blksize);
}
else
serializedBlock.reserve(blksize);
serializedBlock.put_BinaryData(self_);
serializedBlock.put_var_int(getNumTx());
for(uint32_t i=0; i<getNumTx(); i++)
serializedBlock.put_BinaryData(txPtrList_[i]->serialize());
return serializedBlock.getData();
}
示例4: getDataForSigHashAll
BinaryData SigHashDataLegacy::getDataForSigHashAll(const TransactionStub& stub,
BinaryDataRef subScript, unsigned inputIndex)
{
//grab subscript
auto lastCSoffset = stub.getLastCodeSeparatorOffset(inputIndex);
auto subScriptLen = subScript.getSize() - lastCSoffset;
auto&& presubscript = subScript.getSliceRef(lastCSoffset, subScriptLen);
//tokenize op_cs chunks
auto&& tokens = tokenize(presubscript, OP_CODESEPARATOR);
BinaryData subscript;
if (tokens.size() == 1)
{
subscript = move(presubscript);
}
else
{
for (auto& token : tokens)
{
subscript.append(token);
}
}
//isolate outputs
auto&& serializedOutputs = stub.getSerializedOutputScripts();
//isolate inputs
auto&& txinsData = stub.getTxInsData();
auto txin_count = txinsData.size();
BinaryWriter strippedTxins;
for (unsigned i=0; i < txin_count; i++)
{
strippedTxins.put_BinaryData(txinsData[i].outputHash_);
strippedTxins.put_uint32_t(txinsData[i].outputIndex_);
if (inputIndex != i)
{
//put empty varint
strippedTxins.put_var_int(0);
//and sequence
strippedTxins.put_uint32_t(txinsData[i].sequence_);
}
else
{
//scriptsig
strippedTxins.put_var_int(subscript.getSize());
strippedTxins.put_BinaryData(subscript);
//sequence
strippedTxins.put_uint32_t(txinsData[i].sequence_);
}
}
//wrap it up
BinaryWriter scriptSigData;
//version
scriptSigData.put_uint32_t(stub.getVersion());
//txin count
scriptSigData.put_var_int(txin_count);
//txins
scriptSigData.put_BinaryData(strippedTxins.getData());
//txout count
scriptSigData.put_var_int(stub.getTxOutCount());
//txouts
scriptSigData.put_BinaryData(serializedOutputs);
//locktime
scriptSigData.put_uint32_t(stub.getLockTime());
//sighashall
scriptSigData.put_uint32_t(1);
return BinaryData(scriptSigData.getData());
}