本文整理汇总了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);
}
示例2: EncodeInventoryVector
public static void EncodeInventoryVector(BinaryWriter writer, InventoryVector invVector)
{
writer.WriteUInt32(invVector.Type);
writer.WriteUInt256(invVector.Hash);
}
示例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
//.........这里部分代码省略.........
示例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;
}
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例11: EncodeNetworkAddressWithTime
public static void EncodeNetworkAddressWithTime(BinaryWriter writer, NetworkAddressWithTime networkAddressWithTime)
{
writer.WriteUInt32(networkAddressWithTime.Time);
EncodeNetworkAddress(writer, networkAddressWithTime.NetworkAddress);
}
示例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());
}
示例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);
}
示例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);
}
示例15: EncodeTxOutputKey
public static void EncodeTxOutputKey(BinaryWriter writer, TxOutputKey txOutputKey)
{
writer.WriteUInt256(txOutputKey.TxHash);
writer.WriteUInt32(txOutputKey.TxOutputIndex);
}