Files
UnrealEngineUWP/Engine/Source/Programs/Shared/EpicGames.Perforce.Managed/StreamTreeReader.cs
Ben Marsh 508c144999 Horde: Last batch (hopefully) of static analysis fixes/suppressions.
#preflight 623e144c8073508cfc117a87

[CL 19517822 by Ben Marsh in ue5-main branch]
2022-03-25 15:35:47 -04:00

50 lines
1.2 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System.Collections.Generic;
using System.Threading.Tasks;
using EpicGames.Core;
using EpicGames.Serialization;
namespace EpicGames.Perforce.Managed
{
/// <summary>
/// Interface for
/// </summary>
public abstract class StreamTreeReader
{
/// <summary>
/// Reads a node of the tree
/// </summary>
/// <param name="ref"></param>
/// <returns></returns>
public abstract Task<StreamTree> ReadAsync(StreamTreeRef @ref);
}
/// <summary>
/// Implements a <see cref="StreamTreeReader"/> using a contiguous block of memory
/// </summary>
public class StreamTreeMemoryReader : StreamTreeReader
{
/// <summary>
/// Map from hash to encoded CB tree object
/// </summary>
readonly Dictionary<IoHash, CbObject> _hashToTree;
/// <summary>
/// Constructor
/// </summary>
/// <param name="Root"></param>
/// <param name="hashToTree"></param>
public StreamTreeMemoryReader(Dictionary<IoHash, CbObject> hashToTree)
{
_hashToTree = hashToTree;
}
/// <inheritdoc/>
public override Task<StreamTree> ReadAsync(StreamTreeRef @ref)
{
return Task.FromResult(new StreamTree(@ref.Path, _hashToTree[@ref.Hash]));
}
}
}