当前位置: 首页>>代码示例>>C#>>正文


C# BinaryWriter.WriteVarInt方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:erikzhang,项目名称:IceWallet,代码行数:29,代码来源:UnsignedTransaction.cs

示例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);
 }
开发者ID:zhengger,项目名称:AntShares,代码行数:9,代码来源:FiniteFieldPoint.cs

示例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);
 }
开发者ID:EppoFq,项目名称:AntShares,代码行数:12,代码来源:BlockConsensusResponse.cs

示例4:

 void ISerializable.Serialize(BinaryWriter writer)
 {
     writer.Write(PrevHash);
     writer.Write(PrevIndex);
     writer.WriteVarInt(Script.Length); writer.Write(Script);
     writer.Write(Sequence);
 }
开发者ID:erikzhang,项目名称:IceWallet,代码行数:7,代码来源:TransactionInput.cs

示例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();
        }
开发者ID:knocte,项目名称:BitSharp,代码行数:36,代码来源:LocalClient.cs

示例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);
 }
开发者ID:erikzhang,项目名称:IceWallet,代码行数:24,代码来源:MyWallet.cs

示例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);
     }
 }
开发者ID:imcoddy,项目名称:AntShares,代码行数:20,代码来源:AgencyTransaction.cs

示例8:

 void ISerializable.Serialize(BinaryWriter writer)
 {
     writer.WriteVarInt(StackScript.Length); writer.Write(StackScript);
     writer.WriteVarInt(RedeemScript.Length); writer.Write(RedeemScript);
 }
开发者ID:zhengger,项目名称:AntShares,代码行数:5,代码来源:Script.cs

示例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()));
            }
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:17,代码来源:RemoteSender.cs

示例10: Serialize

 public override void Serialize(BinaryWriter writer)
 {
     ((ISignable)this).SerializeUnsigned(writer);
     writer.WriteVarInt(Script.Length); writer.Write(Script);
 }
开发者ID:4T-Shirt,项目名称:AntShares,代码行数:5,代码来源:BlockConsensusResponse.cs

示例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);
 }
开发者ID:imcoddy,项目名称:AntShares,代码行数:15,代码来源:BlockConsensusRequest.cs

示例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();
     }
 }
开发者ID:imcoddy,项目名称:AntShares,代码行数:20,代码来源:BlockConsensusRequest.cs

示例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();
            }
        }
开发者ID:holinov,项目名称:BitSharp,代码行数:25,代码来源:DataCalculator.cs

示例14: Serialize

 public override void Serialize(BinaryWriter writer)
 {
     writer.WriteVarInt(m);
     writer.Write(publicKeys);
     writer.Write(PublicKeyHash);
 }
开发者ID:zhengger,项目名称:AntShares,代码行数:6,代码来源:MultiSigContract.cs

示例15:

 void ISerializable.Serialize(BinaryWriter writer)
 {
     writer.Write(Value);
     writer.WriteVarInt(Script.Length); writer.Write(Script);
 }
开发者ID:erikzhang,项目名称:IceWallet,代码行数:5,代码来源:TransactionOutput.cs


注:本文中的System.IO.BinaryWriter.WriteVarInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。