Added MemoryStreamDebugVisualizer
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>12</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Remove="C:\Users\heilm\source\repos\DebugVisualizer\stylecop.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.DebuggerVisualizers" Version="17.6.1032901" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,64 @@
|
||||
// <copyright file="MemoryStreamVisualizerObjectSource.cs" company="PlaceholderCompany">
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace MemoryStreamObjectSource;
|
||||
|
||||
using Microsoft.VisualStudio.DebuggerVisualizers;
|
||||
using System.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Object source class for the MemoryStreamVisualizer.
|
||||
/// </summary>
|
||||
public class MemoryStreamVisualizerObjectSource : VisualizerObjectSource
|
||||
{
|
||||
/// <summary>
|
||||
/// How many rows will be transfered, at most, responding to a single request.
|
||||
/// </summary>
|
||||
public const int RowsCountPerRequest = 1024;
|
||||
|
||||
/// <summary>
|
||||
/// How many bytes will be transfered for each row.
|
||||
/// </summary>
|
||||
public const int RowLength = 16;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void TransferData(object target, Stream incomingData, Stream outgoingData)
|
||||
{
|
||||
if (target is not MemoryStream memoryStream)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
using BinaryReader binaryReader = new(incomingData);
|
||||
var index = binaryReader.ReadInt32(); // The extension will send the offset (Int32) to start reading from
|
||||
|
||||
using BinaryWriter binaryWriter = new(outgoingData);
|
||||
var backupPosition = memoryStream.Position;
|
||||
|
||||
// Will reply with the current MemoryStream.Position (Int64),
|
||||
// followed by MemoryStream.Length (Int64),
|
||||
// followed by up to 16KB of data retrieved from the MemoryStream
|
||||
binaryWriter.Write(backupPosition);
|
||||
binaryWriter.Write(memoryStream.Length);
|
||||
if (index < memoryStream.Length)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = new byte[RowsCountPerRequest * RowLength];
|
||||
memoryStream.Seek(index, SeekOrigin.Begin);
|
||||
var count = memoryStream.Read(data, 0, data.Length);
|
||||
binaryWriter.Write(data, 0, count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Make sure to restore the MemoryStream to its original position
|
||||
memoryStream.Seek(backupPosition, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
binaryWriter.Flush();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user