本文整理汇总了C#中System.IO.BinaryWriter.WriteVarInt方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.WriteVarInt方法的具体用法?C# BinaryWriter.WriteVarInt怎么用?C# BinaryWriter.WriteVarInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter.WriteVarInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHashForSigning
internal byte[] GetHashForSigning(HashType hashType, uint index)
{
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter writer = new BinaryWriter(ms))
{
writer.Write(Version);
writer.WriteVarInt(Inputs.Length);
for (uint i = 0; i < Inputs.Length; i++)
{
writer.Write(Inputs[i].TxId);
writer.Write(Inputs[i].Index);
if (i == index)
{
writer.WriteVarInt(Inputs[i].ScriptPubKey.Length);
writer.Write(Inputs[i].ScriptPubKey);
}
else
{
writer.WriteVarInt(0);
}
writer.Write(uint.MaxValue);
}
writer.Write(Outputs);
writer.Write(LockTime);
writer.Write((int)hashType);
writer.Flush();
return ms.ToArray().Sha256().Sha256();
}
}
示例2: Serialize
public void Serialize(BinaryWriter writer)
{
int expectedByteCount = Y.PrimePolynomial.SizeInBytes;
byte[] pointBytes = Y.PolynomialValue.ToUnsignedBigEndianBytes();
writer.WriteVarInt((long)X.PolynomialValue);
writer.WriteVarInt(expectedByteCount);
writer.Write(new byte[expectedByteCount - pointBytes.Length]);
writer.Write(pointBytes);
}
示例3: foreach
void ISignable.SerializeUnsigned(BinaryWriter writer)
{
writer.Write(PrevHash);
writer.Write(Miner);
writer.WriteVarInt(NoncePieces.Count);
foreach (var pair in NoncePieces)
{
writer.Write(pair.Key);
writer.WriteVarInt(pair.Value.Length); writer.Write(pair.Value);
}
writer.Write(MerkleRoot);
}
示例4:
void ISerializable.Serialize(BinaryWriter writer)
{
writer.Write(PrevHash);
writer.Write(PrevIndex);
writer.WriteVarInt(Script.Length); writer.Write(Script);
writer.Write(Sequence);
}
示例5: OnGetHeaders
private void OnGetHeaders(RemoteNode remoteNode, GetBlocksPayload payload)
{
// if in comparison mode, synchronize all work before returning current headers
if (this.Type == LocalClientType.ComparisonToolTestNet)
this.blockchainDaemon.WaitForFullUpdate();
var currentBlockchainLocal = this.blockchainDaemon.CurrentBlockchain;
var blockHeaders = new List<BlockHeader>(currentBlockchainLocal.BlockCount);
foreach (var chainedBlock in currentBlockchainLocal.BlockList)
{
BlockHeader blockHeader;
if (this.blockchainDaemon.CacheContext.BlockHeaderCache.TryGetValue(chainedBlock.BlockHash, out blockHeader))
{
blockHeaders.Add(blockHeader);
}
else
{
Debugger.Break();
Debug.WriteLine("Couldn't generate getheaders response");
return;
}
}
var payloadStream = new MemoryStream();
using (var payloadWriter = new BinaryWriter(payloadStream))
{
payloadWriter.WriteVarInt((UInt64)blockHeaders.Count);
foreach (var blockHeader in blockHeaders)
{
NetworkEncoder.EncodeBlockHeader(payloadStream, blockHeader);
payloadWriter.WriteVarInt(0);
}
}
remoteNode.Sender.SendMessageAsync(Messaging.ConstructMessage("headers", payloadStream.ToArray())).Wait();
}
示例6: Save
public void Save(string path, string password)
{
byte[] aes_key = Encoding.UTF8.GetBytes(password).Sha256().Sha256();
using (AesManaged aes = new AesManaged())
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
fs.Write(aes.IV, 0, aes.IV.Length);
using (ICryptoTransform encryptor = aes.CreateEncryptor(aes_key, aes.IV))
using (CryptoStream cs = new CryptoStream(fs, encryptor, CryptoStreamMode.Write))
using (BinaryWriter w = new BinaryWriter(cs))
{
w.WriteVarInt(accounts.Count);
foreach (WalletEntry entry in accounts)
{
using (entry.Decrypt())
{
w.Write(entry.PrivateKey);
}
w.Write(entry.Compressed);
}
}
}
Array.Clear(aes_key, 0, aes_key.Length);
}
示例7: SerializeExclusiveData
protected override void SerializeExclusiveData(BinaryWriter writer)
{
writer.Write(AssetId);
writer.Write(ValueAssetId);
writer.Write(Agent);
writer.WriteVarInt(Orders.Length);
for (int i = 0; i < Orders.Length; i++)
{
Orders[i].SerializeInTransaction(writer);
}
if (SplitOrder == null)
{
writer.WriteVarInt(0);
}
else
{
writer.WriteVarInt(1);
writer.Write(SplitOrder);
}
}
示例8:
void ISerializable.Serialize(BinaryWriter writer)
{
writer.WriteVarInt(StackScript.Length); writer.Write(StackScript);
writer.WriteVarInt(RedeemScript.Length); writer.Write(RedeemScript);
}
示例9: SendHeaders
public async Task SendHeaders(ImmutableArray<BlockHeader> blockHeaders)
{
await Task.Yield();
using (var payloadStream = new MemoryStream())
using (var payloadWriter = new BinaryWriter(payloadStream))
{
payloadWriter.WriteVarInt((UInt64)blockHeaders.Length);
foreach (var blockHeader in blockHeaders)
{
DataEncoder.EncodeBlockHeader(payloadWriter, blockHeader);
payloadWriter.WriteVarInt(0);
}
await SendMessageAsync(Messaging.ConstructMessage("headers", payloadStream.ToArray()));
}
}
示例10: Serialize
public override void Serialize(BinaryWriter writer)
{
((ISignable)this).SerializeUnsigned(writer);
writer.WriteVarInt(Script.Length); writer.Write(Script);
}
示例11: Serialize
public override void Serialize(BinaryWriter writer)
{
writer.Write(PrevHash);
writer.Write(Miner);
writer.WriteVarInt(NoncePieces.Count);
foreach (var pair in NoncePieces)
{
writer.Write(pair.Key);
writer.WriteVarInt(pair.Value.Length);
writer.Write(pair.Value);
}
writer.Write(NonceHash);
writer.Write(TransactionHashes);
writer.WriteVarInt(Script.Length); writer.Write(Script);
}
示例12: using
byte[] ISignable.ToUnsignedArray()
{
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter writer = new BinaryWriter(ms))
{
writer.Write(PrevHash);
writer.Write(Miner);
writer.WriteVarInt(NoncePieces.Count);
foreach (var pair in NoncePieces)
{
writer.Write(pair.Key);
writer.WriteVarInt(pair.Value.Length);
writer.Write(pair.Value);
}
writer.Write(NonceHash);
writer.Write(TransactionHashes);
writer.Flush();
return ms.ToArray();
}
}
示例13: EncodeTransaction
public static byte[] EncodeTransaction(UInt32 Version, ImmutableArray<TxInput> Inputs, ImmutableArray<TxOutput> Outputs, UInt32 LockTime)
{
var stream = new MemoryStream();
using (var writer = new BinaryWriter(stream))
{
writer.Write4Bytes(Version);
writer.WriteVarInt((UInt64)Inputs.Length);
foreach (var input in Inputs)
{
writer.Write32Bytes(input.PreviousTxOutputKey.TxHash);
writer.Write4Bytes(input.PreviousTxOutputKey.TxOutputIndex);
writer.WriteVarBytes(input.ScriptSignature.ToArray());
writer.Write4Bytes(input.Sequence);
}
writer.WriteVarInt((UInt64)Outputs.Length);
foreach (var output in Outputs)
{
writer.Write8Bytes(output.Value);
writer.WriteVarBytes(output.ScriptPublicKey.ToArray());
}
writer.Write4Bytes(LockTime);
return stream.ToArray();
}
}
示例14: Serialize
public override void Serialize(BinaryWriter writer)
{
writer.WriteVarInt(m);
writer.Write(publicKeys);
writer.Write(PublicKeyHash);
}
示例15:
void ISerializable.Serialize(BinaryWriter writer)
{
writer.Write(Value);
writer.WriteVarInt(Script.Length); writer.Write(Script);
}