Files
UnrealEngineUWP/Engine/Source/Programs/Shared/EpicGames.Perforce.Managed/FileContentId.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

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.ReadString();
return new FileContentId(digest, type);
}
public static void WriteFileContentId(this MemoryWriter writer, FileContentId fileContentId)
{
writer.WriteMd5Hash(fileContentId.Digest);
writer.WriteString(fileContentId.Type);
}
public static int GetSerializedSize(this FileContentId fileContentId)
{
return Digest<Md5>.Length + fileContentId.Type.GetSerializedSize();
}
}
}