2021-07-19 11:13:00 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
2022-03-25 15:35:47 -04:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-07-19 10:34:55 -04:00
|
|
|
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>
|
2022-03-25 15:35:47 -04:00
|
|
|
/// <param name="ref"></param>
|
2021-07-19 10:34:55 -04:00
|
|
|
/// <returns></returns>
|
2022-03-25 15:35:47 -04:00
|
|
|
public abstract Task<StreamTree> ReadAsync(StreamTreeRef @ref);
|
2021-07-19 10:34:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2022-03-25 15:35:47 -04:00
|
|
|
readonly Dictionary<IoHash, CbObject> _hashToTree;
|
2021-07-19 10:34:55 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Root"></param>
|
2022-03-25 15:35:47 -04:00
|
|
|
/// <param name="hashToTree"></param>
|
|
|
|
|
public StreamTreeMemoryReader(Dictionary<IoHash, CbObject> hashToTree)
|
2021-07-19 10:34:55 -04:00
|
|
|
{
|
2022-03-25 15:35:47 -04:00
|
|
|
_hashToTree = hashToTree;
|
2021-07-19 10:34:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2022-03-25 15:35:47 -04:00
|
|
|
public override Task<StreamTree> ReadAsync(StreamTreeRef @ref)
|
2021-07-19 10:34:55 -04:00
|
|
|
{
|
2022-03-25 15:35:47 -04:00
|
|
|
return Task.FromResult(new StreamTree(@ref.Path, _hashToTree[@ref.Hash]));
|
2021-07-19 10:34:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|