本文整理汇总了C#中StreamHandler.ToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# StreamHandler.ToByteArray方法的具体用法?C# StreamHandler.ToByteArray怎么用?C# StreamHandler.ToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StreamHandler
的用法示例。
在下文中一共展示了StreamHandler.ToByteArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalWriteMetaData
protected unsafe override void InternalWriteMetaData()
{
m_stream.DoAt(m_streamOriginalPosition, () =>
{
var bytes = new byte[MainHeader.Size];
byte[] extraData;
using (var writer = new StreamHandler())
{
var flags = this.ExtraInfoFlags;
if (flags.HasFlag(ExtraDataFlags.HasClientIPv4) ||
flags.HasFlag(ExtraDataFlags.HasClientIPv6))
writer.WriteBytes(this.ClientAddress.GetAddressBytes());
if (flags.HasFlag(ExtraDataFlags.HasServerIPv4) ||
flags.HasFlag(ExtraDataFlags.HasServerIPv6))
writer.WriteBytes(this.ServerAddress.GetAddressBytes());
if (flags.HasFlag(ExtraDataFlags.HasClientPort))
writer.WriteInt32(this.ClientPort);
if (flags.HasFlag(ExtraDataFlags.HasServerPort))
writer.WriteInt32(this.ServerPort);
if (flags.HasFlag(ExtraDataFlags.HasSnifferIdString))
{
byte[] arr = Encoding.UTF8.GetBytes(this.SnifferDesc ?? string.Empty);
writer.WriteInt32(arr.Length);
using (MemoryStream oStream = new MemoryStream())
{
// BUG http://blogs.msdn.com/b/bclteam/archive/2006/05/10/592551.aspx
using (var ds = new DeflateStream(oStream, CompressionMode.Compress, true))
ds.Write(arr, 0, arr.Length);
arr = oStream.ToArray();
}
writer.WriteInt32(arr.Length);
writer.WriteBytes(arr);
}
extraData = writer.ToByteArray();
}
fixed (byte* bytesPtr = bytes)
{
var header = (MainHeader*)bytesPtr;
header->PacketCount = this.Count;
Marshal.Copy(SignatureBytes, 0, new IntPtr(header->Signature), SignatureBytes.Length);
header->StartedOnTicks = this.StartTicks;
header->StartedOnUnix = this.StartTime.ToUnixTime();
header->ExtraDataLength = extraData.Length;
header->ExtraInfoFlags = this.ExtraInfoFlags;
}
m_stream.WriteBytes(bytes);
m_stream.WriteBytes(extraData);
});
}
示例2: Save
/// <summary>
/// When overriden in a derived class, writes the packet data to a byte array.
/// </summary>
/// <returns>The byte array that contains the packet structure.</returns>
public virtual byte[] Save()
{
byte[] result;
using (var writer = new StreamHandler())
{
Save(writer);
result = writer.ToByteArray();
}
return result;
}