當前位置: 首頁>>代碼示例>>C#>>正文


C# BinaryWriter.WriteUInt32方法代碼示例

本文整理匯總了C#中System.IO.BinaryWriter.WriteUInt32方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryWriter.WriteUInt32方法的具體用法?C# BinaryWriter.WriteUInt32怎麽用?C# BinaryWriter.WriteUInt32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.BinaryWriter的用法示例。


在下文中一共展示了BinaryWriter.WriteUInt32方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EncodeBlockHeader

 public static void EncodeBlockHeader(BinaryWriter writer, BlockHeader blockHeader)
 {
     writer.WriteUInt32(blockHeader.Version);
     writer.WriteUInt256(blockHeader.PreviousBlock);
     writer.WriteUInt256(blockHeader.MerkleRoot);
     writer.WriteUInt32((uint)blockHeader.Time.ToUnixTimeSeconds());
     writer.WriteUInt32(blockHeader.Bits);
     writer.WriteUInt32(blockHeader.Nonce);
 }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:9,代碼來源:DataEncoder.cs

示例2: EncodeInventoryVector

 public static void EncodeInventoryVector(BinaryWriter writer, InventoryVector invVector)
 {
     writer.WriteUInt32(invVector.Type);
     writer.WriteUInt256(invVector.Hash);
 }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:5,代碼來源:NodeEncoder.cs

示例3: WriteTo

        public void WriteTo(BinaryWriter w)
        {
            // http://www.pkware.com/documents/casestudies/APPNOTE.TXT

            var offsets = new Queue();
            var Items = this.Entries;
            
            #region Local file header:
            foreach (var v in Items)
            {
                // if we box unit, it will actually represent Long 
                // this is for tostring functionality

                offsets.Enqueue((uint)w.BaseStream.Position);

                //var h = v.Header;
                var file_name = Encoding.ASCII.GetBytes(v.FileName);

                //        local file header signature     4 bytes  (0x04034b50)
                w.Write(ZIPFileEntryHeader.FileHeader);
                //        version needed to extract       2 bytes
                w.Write((short)0x000A);
                //        general purpose bit flag        2 bytes
                w.Write((short)0);

                //        compression method              2 bytes
                w.Write(ZIPFileEntryHeader.UNCOMPRESSED);
                //        last mod file time              2 bytes
                //        last mod file date              2 bytes
                w.WriteUInt32(ToMsDosDateTime(DateTime.Now));

                //        crc-32                          4 bytes
                w.WriteUInt32((uint)Crc32Helper.GetCrc32(v.Data.ToArray()));

                //        compressed size                 4 bytes
                w.WriteUInt32((uint)v.Data.Length);
                //        uncompressed size               4 bytes
                w.WriteUInt32((uint)v.Data.Length);


                //        file name length                2 bytes
                w.Write((short)file_name.Length);

                //        extra field length              2 bytes
                w.Write((short)0);

                //        file name (variable size)
                w.Write(file_name);

                //        extra field (variable size)

                v.Data.WriteTo(w.BaseStream);

            }
            #endregion

            var p = w.BaseStream.Position;


            #region Central directory structure
            foreach (var v in Items)
            {
                //var h = v.Header;
                var offset = (uint)offsets.Dequeue();

                var file_name = Encoding.ASCII.GetBytes(v.FileName);


                //       central file header signature   4 bytes  (0x02014b50)
                w.Write((int)0x02014b50);
                //       version made by                 2 bytes
                w.WriteUInt16((ushort)0x0014);
                //       version needed to extract       2 bytes
                w.WriteUInt16((ushort)0x000A);
                //       general purpose bit flag        2 bytes
                w.WriteUInt16((ushort)0x0000);
                //       compression method              2 bytes
                w.Write(ZIPFileEntryHeader.UNCOMPRESSED);
                //       last mod file time              2 bytes
                //       last mod file date              2 bytes
                w.WriteUInt32(ToMsDosDateTime(DateTime.Now));
                //       crc-32                          4 bytes
                w.WriteUInt32((uint)Crc32Helper.GetCrc32(v.Data.ToArray()));
                //       compressed size                 4 bytes
                w.WriteUInt32((uint)v.Data.Length);
                //       uncompressed size               4 bytes
                w.WriteUInt32((uint)v.Data.Length);
                //       file name length                2 bytes
                w.WriteUInt16((ushort)file_name.Length);
                //       extra field length              2 bytes
                w.WriteUInt16((ushort)0x0000);
                //       file comment length             2 bytes
                w.WriteUInt16((ushort)0x0000);
                //       disk number start               2 bytes
                w.WriteUInt16((ushort)0x0000);
                //       internal file attributes        2 bytes
                w.WriteUInt16((ushort)0x0000);
                //       external file attributes        4 bytes
                w.Write((int)0x0000);
                //       relative offset of local header 4 bytes
//.........這裏部分代碼省略.........
開發者ID:exaphaser,項目名稱:JSC-Cross-Compiler,代碼行數:101,代碼來源:ZIPFile.WriteTo.cs

示例4: PrepareSaveData

        private int PrepareSaveData(byte[] destBuf)
        {
            using (var stream = new MemoryStream(destBuf))
            {
                using (var bw = new BinaryWriter(stream))
                {
                    bw.BaseStream.Seek(4, SeekOrigin.Begin);
                    bw.WriteUInt32(SaveFileRevision);
                    bw.WriteUInt32((uint) SystemVars.Instance.GameVersion.Version.Minor);

                    bw.WriteUInt16(_skySound.SaveSounds[0]);
                    bw.WriteUInt16(_skySound.SaveSounds[1]);

                    bw.WriteUInt32(_skyMusic.CurrentMusic);
                    bw.WriteUInt32(_savedCharSet);
                    bw.WriteUInt32(_savedMouse);
                    bw.WriteUInt32(SystemVars.Instance.CurrentPalette);
                    for (var cnt = 0; cnt < Logic.NumSkyScriptVars; cnt++)
                        bw.WriteUInt32(_skyLogic.ScriptVariables[cnt]);
                    var loadedFilesList = _skyDisk.LoadedFilesList;

                    for (var cnt = 0; cnt < 60; cnt++)
                        bw.WriteUInt32(loadedFilesList[cnt]);

                    for (var cnt = 0; cnt < _skyCompact.SaveIds.Length; cnt++)
                    {
                        var rawCpt = _skyCompact.FetchCptRaw(_skyCompact.SaveIds[cnt]);
                        bw.WriteBytes(rawCpt, rawCpt.Length);
                    }

                    var length = bw.BaseStream.Position;
                    bw.BaseStream.Seek(0, SeekOrigin.Begin);
                    bw.WriteUInt32((uint) length);
                    return (int) length;
                }
            }
        }
開發者ID:scemino,項目名稱:nscumm,代碼行數:37,代碼來源:Control.cs

示例5: EncodeTransaction

        public static byte[] EncodeTransaction(UInt32 Version, ImmutableArray<TxInput> Inputs, ImmutableArray<TxOutput> Outputs, UInt32 LockTime)
        {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream))
            {
                writer.WriteUInt32(Version);
                writer.WriteList(Inputs, input => EncodeTxInput(writer, input));
                writer.WriteList(Outputs, output => EncodeTxOutput(writer, output));
                writer.WriteUInt32(LockTime);

                return stream.ToArray();
            }
        }
開發者ID:ArsenShnurkov,項目名稱:BitSharp,代碼行數:13,代碼來源:DataEncoder.cs

示例6: EncodePrevTxOutput

 public static void EncodePrevTxOutput(BinaryWriter writer, PrevTxOutput txOutput)
 {
     writer.WriteUInt64(txOutput.Value);
     writer.WriteVarBytes(txOutput.ScriptPublicKey.ToArray());
     writer.WriteInt32(txOutput.BlockHeight);
     writer.WriteInt32(txOutput.TxIndex);
     writer.WriteUInt32(txOutput.TxVersion);
     writer.WriteBool(txOutput.IsCoinbase);
 }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:9,代碼來源:DataEncoder.cs

示例7: EncodeVersionPayload

        public static void EncodeVersionPayload(BinaryWriter writer, VersionPayload versionPayload, bool withRelay)
        {
            writer.WriteUInt32(versionPayload.ProtocolVersion);
            writer.WriteUInt64(versionPayload.ServicesBitfield);
            writer.WriteUInt64((ulong)versionPayload.Time.ToUnixTimeSeconds());
            EncodeNetworkAddress(writer, versionPayload.RemoteAddress);
            EncodeNetworkAddress(writer, versionPayload.LocalAddress);
            writer.WriteUInt64(versionPayload.Nonce);
            writer.WriteVarString(versionPayload.UserAgent);
            writer.WriteUInt32(versionPayload.StartBlockHeight);

            if (withRelay)
                writer.WriteBool(versionPayload.Relay);
        }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:14,代碼來源:NodeEncoder.cs

示例8: EncodeTransaction

        public static DecodedTx EncodeTransaction(UInt32 Version, ImmutableArray<TxInput> Inputs, ImmutableArray<TxOutput> Outputs, UInt32 LockTime)
        {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream))
            {
                writer.WriteUInt32(Version);
                writer.WriteList(Inputs, input => EncodeTxInput(writer, input));
                writer.WriteList(Outputs, output => EncodeTxOutput(writer, output));
                writer.WriteUInt32(LockTime);

                var txBytes = stream.ToArray();
                var txHash = new UInt256(SHA256Static.ComputeDoubleHash(txBytes));
                var tx = new Transaction(Version, Inputs, Outputs, LockTime, txHash);

                return new DecodedTx(txBytes.ToImmutableArray(), tx);
            }
        }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:17,代碼來源:DataEncoder.cs

示例9: EncodeTxInput

 public static void EncodeTxInput(BinaryWriter writer, TxInput txInput)
 {
     writer.WriteUInt256(txInput.PrevTxOutputKey.TxHash);
     writer.WriteUInt32(txInput.PrevTxOutputKey.TxOutputIndex);
     writer.WriteVarBytes(txInput.ScriptSignature.ToArray());
     writer.WriteUInt32(txInput.Sequence);
 }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:7,代碼來源:DataEncoder.cs

示例10: TxSignature

        public byte[] TxSignature(byte[] scriptPubKey, Transaction tx, int inputIndex, byte hashType)
        {
            ///TODO
            Debug.Assert(inputIndex < tx.Inputs.Length);

            // Blank out other inputs' signatures
            var empty = ImmutableArray.Create<byte>();
            var newInputs = ImmutableArray.CreateBuilder<TxInput>(tx.Inputs.Length);
            for (var i = 0; i < tx.Inputs.Length; i++)
            {
                var oldInput = tx.Inputs[i];
                var newInput = oldInput.With(scriptSignature: i == inputIndex ? scriptPubKey.ToImmutableArray() : empty);
                newInputs.Add(newInput);
            }

            //// Blank out some of the outputs
            //if ((hashType & 0x1F) == (int)ScriptHashType.SIGHASH_NONE)
            //{
            //    //TODO
            //    Debug.Assert(false);

            //    // Wildcard payee

            //    // Let the others update at will
            //}
            //else if ((hashType & 0x1F) == (int)ScriptHashType.SIGHASH_SINGLE)
            //{
            //    //TODO
            //    Debug.Assert(false);

            //    // Only lock-in the txout payee at same index as txin

            //    // Let the others update at will
            //}

            //// Blank out other inputs completely, not recommended for open transactions
            //if ((hashType & 0x80) == (int)ScriptHashType.SIGHASH_ANYONECANPAY)
            //{
            //    //TODO
            //    Debug.Assert(false);
            //}

            // create simplified transaction
            var newTx = tx.With(Inputs: newInputs.ToImmutable());

            // return wire-encoded simplified transaction with the 4-byte hashType tacked onto the end
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream))
            {
                writer.WriteBytes(DataEncoder.EncodeTransaction(newTx));
                writer.WriteUInt32(hashType);

                return stream.ToArray();
            }
        }
開發者ID:ArsenShnurkov,項目名稱:BitSharp,代碼行數:55,代碼來源:ScriptEngine.cs

示例11: EncodeNetworkAddressWithTime

 public static void EncodeNetworkAddressWithTime(BinaryWriter writer, NetworkAddressWithTime networkAddressWithTime)
 {
     writer.WriteUInt32(networkAddressWithTime.Time);
     EncodeNetworkAddress(writer, networkAddressWithTime.NetworkAddress);
 }
開發者ID:ArsenShnurkov,項目名稱:BitSharp,代碼行數:5,代碼來源:NodeEncoder.cs

示例12: EncodeMessage

 public static void EncodeMessage(BinaryWriter writer, Message message)
 {
     writer.WriteUInt32(message.Magic);
     writer.WriteFixedString(12, message.Command);
     writer.WriteUInt32(message.PayloadSize);
     writer.WriteUInt32(message.PayloadChecksum);
     writer.WriteBytes(message.PayloadSize.ToIntChecked(), message.Payload.ToArray());
 }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:8,代碼來源:NodeEncoder.cs

示例13: EncodeUnspentTx

 public static void EncodeUnspentTx(BinaryWriter writer, UnspentTx unspentTx)
 {
     writer.WriteUInt256(unspentTx.TxHash);
     writer.WriteInt32(unspentTx.BlockIndex);
     writer.WriteInt32(unspentTx.TxIndex);
     writer.WriteUInt32(unspentTx.TxVersion);
     writer.WriteBool(unspentTx.IsCoinbase);
     writer.WriteVarBytes(unspentTx.OutputStates.ToByteArray());
     writer.WriteInt32(unspentTx.OutputStates.Length);
 }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:10,代碼來源:DataEncoder.cs

示例14: EncodeNetworkAddressWithTime

 public static void EncodeNetworkAddressWithTime(BinaryWriter writer, NetworkAddressWithTime networkAddressWithTime)
 {
     writer.WriteUInt32((uint)networkAddressWithTime.Time.ToUnixTimeSeconds()); //TODO is time LE or BE on network messages?
     EncodeNetworkAddress(writer, networkAddressWithTime.NetworkAddress);
 }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:5,代碼來源:NodeEncoder.cs

示例15: EncodeTxOutputKey

 public static void EncodeTxOutputKey(BinaryWriter writer, TxOutputKey txOutputKey)
 {
     writer.WriteUInt256(txOutputKey.TxHash);
     writer.WriteUInt32(txOutputKey.TxOutputIndex);
 }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:5,代碼來源:DataEncoder.cs


注:本文中的System.IO.BinaryWriter.WriteUInt32方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。