зеркало из https://github.com/microsoft/Tx.git
Extention method to dump byte[]
This commit is contained in:
Родитель
82c84279a8
Коммит
878606ad2a
Двоичные данные
References/LinqPad/LINQPad.exe
Двоичные данные
References/LinqPad/LINQPad.exe
Двоичный файл не отображается.
|
@ -5,5 +5,5 @@ using System.Reflection;
|
|||
[assembly: AssemblyCompany("MS Open Tech")]
|
||||
[assembly: AssemblyProduct("Tx (LINQ to Logs and Traces)")]
|
||||
[assembly: AssemblyCopyright("Copyright © MS Open Tech 2012")]
|
||||
[assembly: AssemblyVersion("1.0.40408.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.40408.0")]
|
||||
[assembly: AssemblyVersion("1.0.40424.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.40424.0")]
|
|
@ -0,0 +1,72 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace System.Reactive
|
||||
{
|
||||
public static class ByteArrayExtensions
|
||||
{
|
||||
public static string ToDump(this byte[] bytes)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int lineOffset = 0;
|
||||
|
||||
while (lineOffset < bytes.Length)
|
||||
{
|
||||
// output line offset from the start of the buffer
|
||||
sb.Append(lineOffset.ToString("x4"));
|
||||
sb.Append(": ");
|
||||
|
||||
// output hex dump
|
||||
int endOffset = Math.Min(lineOffset + 16, bytes.Length);
|
||||
int index = 0;
|
||||
for (int byteOffset = lineOffset; byteOffset < endOffset; byteOffset++)
|
||||
{
|
||||
if (index == 8)
|
||||
sb.Append(' ');
|
||||
|
||||
index++;
|
||||
sb.Append(bytes[byteOffset].ToString("x2"));
|
||||
sb.Append(' ');
|
||||
}
|
||||
|
||||
// fill in the blanks if we cut off without completing entire line
|
||||
int lineLength = endOffset - lineOffset;
|
||||
if (lineLength < 16)
|
||||
{
|
||||
for (int i = lineLength; i < 16; i++ )
|
||||
{
|
||||
if (index == 8)
|
||||
sb.Append(' ');
|
||||
|
||||
index++;
|
||||
|
||||
sb.Append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
sb.Append(" ");
|
||||
|
||||
// output character dump
|
||||
index = 0;
|
||||
for (int byteOffset = lineOffset; byteOffset < endOffset; byteOffset++)
|
||||
{
|
||||
index++;
|
||||
byte b = bytes[byteOffset];
|
||||
if (b > 32)
|
||||
sb.Append((char)b);
|
||||
else
|
||||
sb.Append('.');
|
||||
|
||||
if (index == 8)
|
||||
sb.Append(' ');
|
||||
}
|
||||
|
||||
sb.AppendLine();
|
||||
lineOffset += 16;
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,6 +48,7 @@
|
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<Compile Include="Attributes.cs" />
|
||||
<Compile Include="ByteArrayExtensions.cs" />
|
||||
<Compile Include="CustomAttributeProviderExtensions.cs" />
|
||||
<Compile Include="BufferQueue.cs" />
|
||||
<Compile Include="IPlaybackConfiguration.cs" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче