本文整理汇总了C#中System.IO.BinaryWriter.WriteBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.WriteBytes方法的具体用法?C# BinaryWriter.WriteBytes怎么用?C# BinaryWriter.WriteBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter.WriteBytes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: EncodeNetworkAddress
public static void EncodeNetworkAddress(BinaryWriter writer, NetworkAddress networkAddress)
{
writer.WriteUInt64(networkAddress.Services);
writer.WriteBytes(16, networkAddress.IPv6Address.ToArray());
writer.WriteUInt16BE(networkAddress.Port);
}
示例3: EncodeTotalWork
public static void EncodeTotalWork(BinaryWriter writer, BigInteger totalWork)
{
if (totalWork < 0)
throw new ArgumentOutOfRangeException();
var totalWorkBytesLittleEndian = totalWork.ToByteArray();
if (totalWorkBytesLittleEndian.Length > 64)
throw new ArgumentOutOfRangeException();
var totalWorkBytesLittleEndian64 = new byte[64];
Buffer.BlockCopy(totalWorkBytesLittleEndian, 0, totalWorkBytesLittleEndian64, 0, totalWorkBytesLittleEndian.Length);
var totalWorkBytesBigEndian = totalWorkBytesLittleEndian64.Reverse().ToArray();
writer.WriteBytes(totalWorkBytesBigEndian);
Debug.Assert(new BigInteger(totalWorkBytesLittleEndian64) == totalWork);
}
示例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: EncodeBlockTxNode
public static void EncodeBlockTxNode(BinaryWriter writer, BlockTxNode blockTx)
{
writer.WriteInt32(blockTx.Index);
writer.WriteInt32(blockTx.Depth);
writer.WriteUInt256(blockTx.Hash);
writer.WriteBool(blockTx.Pruned);
if (!blockTx.Pruned)
writer.WriteBytes(blockTx.TxBytes.ToArray());
}
示例6: EncodeBlock
public static void EncodeBlock(BinaryWriter writer, Block block)
{
EncodeBlockHeader(writer, block.Header);
writer.WriteList(block.BlockTxes, tx => writer.WriteBytes(tx.TxBytes.ToArray()));
}
示例7: 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();
}
}
示例8: EncodeNetworkAddress
public static void EncodeNetworkAddress(Stream stream, NetworkAddress networkAddress)
{
using (var writer = new BinaryWriter(stream, Encoding.ASCII, leaveOpen: true))
{
writer.Write8Bytes(networkAddress.Services);
writer.WriteBytes(16, networkAddress.IPv6Address.ToArray());
writer.Write2BytesBE(networkAddress.Port);
}
}
示例9: EncodeMessage
public static void EncodeMessage(Stream stream, Message message)
{
using (var writer = new BinaryWriter(stream, Encoding.ASCII, leaveOpen: true))
{
writer.Write4Bytes(message.Magic);
writer.WriteFixedString(12, message.Command);
writer.Write4Bytes(message.PayloadSize);
writer.Write4Bytes(message.PayloadChecksum);
writer.WriteBytes(message.PayloadSize.ToIntChecked(), message.Payload.ToArray());
}
}