Files
UnrealEngineUWP/Engine/Source/Programs/Shared/EpicGames.Perforce.Managed/FileContentId.cs
Ben Marsh cbd0f5ea19 Add a common interface for reading/writing to memory (IMemoryReader/IMemoryWriter), which is implemented by the legacy MemoryReader/MemoryWriter classes as well as the newer ByteArrayBuilder.
Also moves VarInt into EpicGames.Core.
#preflight 62bb5e3efd06251187efd3d7

[CL 20863839 by Ben Marsh in ue5-main branch]
2022-06-28 16:14:51 -04:00

60 lines
1.3 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Diagnostics;
using EpicGames.Core;
namespace EpicGames.Perforce.Managed
{
[DebuggerDisplay("{Digest} ({Type})")]
public class FileContentId
{
public Md5Hash Digest
{
get;
}
public Utf8String Type
{
get;
}
public FileContentId(Md5Hash digest, Utf8String type)
{
Digest = digest;
Type = type;
}
public override bool Equals(object? other)
{
return (other is FileContentId otherFile) && Digest == otherFile.Digest && Type == otherFile.Type;
}
public override int GetHashCode()
{
return HashCode.Combine(Digest.GetHashCode(), Type.GetHashCode());
}
}
static class FileContentIdExtensions
{
public static FileContentId ReadFileContentId(this MemoryReader reader)
{
Md5Hash digest = reader.ReadMd5Hash();
Utf8String type = reader.ReadNullTerminatedUtf8String();
return new FileContentId(digest, type);
}
public static void WriteFileContentId(this MemoryWriter writer, FileContentId fileContentId)
{
writer.WriteMd5Hash(fileContentId.Digest);
writer.WriteNullTerminatedUtf8String(fileContentId.Type);
}
public static int GetSerializedSize(this FileContentId fileContentId)
{
return Digest<Md5>.Length + fileContentId.Type.GetNullTerminatedSize();
}
}
}