2021-04-28 23:13:14 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
using System;
|
2021-05-28 13:22:15 -04:00
|
|
|
using System.Diagnostics;
|
2021-04-28 23:13:14 -04:00
|
|
|
using EpicGames.Core;
|
|
|
|
|
|
|
|
|
|
namespace EpicGames.Perforce.Managed
|
|
|
|
|
{
|
2021-05-28 13:22:15 -04:00
|
|
|
[DebuggerDisplay("{Digest} ({Type})")]
|
2021-05-29 10:08:31 -04:00
|
|
|
public class FileContentId
|
2021-04-28 23:13:14 -04:00
|
|
|
{
|
2021-07-06 11:00:26 -04:00
|
|
|
public Md5Hash Digest
|
2021-04-28 23:13:14 -04:00
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 12:16:55 -04:00
|
|
|
public Utf8String Type
|
2021-04-28 23:13:14 -04:00
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 15:35:47 -04:00
|
|
|
public FileContentId(Md5Hash digest, Utf8String type)
|
2021-04-28 23:13:14 -04:00
|
|
|
{
|
2022-03-25 15:35:47 -04:00
|
|
|
Digest = digest;
|
|
|
|
|
Type = type;
|
2021-04-28 23:13:14 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 15:35:47 -04:00
|
|
|
public override bool Equals(object? other)
|
2021-04-28 23:13:14 -04:00
|
|
|
{
|
2022-03-25 15:35:47 -04:00
|
|
|
return (other is FileContentId otherFile) && Digest == otherFile.Digest && Type == otherFile.Type;
|
2021-04-28 23:13:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2021-05-28 13:22:15 -04:00
|
|
|
return HashCode.Combine(Digest.GetHashCode(), Type.GetHashCode());
|
2021-04-28 23:13:14 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class FileContentIdExtensions
|
|
|
|
|
{
|
2022-03-25 15:35:47 -04:00
|
|
|
public static FileContentId ReadFileContentId(this MemoryReader reader)
|
2021-04-28 23:13:14 -04:00
|
|
|
{
|
2022-03-25 15:35:47 -04:00
|
|
|
Md5Hash digest = reader.ReadMd5Hash();
|
2022-06-28 16:14:51 -04:00
|
|
|
Utf8String type = reader.ReadNullTerminatedUtf8String();
|
2022-03-25 15:35:47 -04:00
|
|
|
return new FileContentId(digest, type);
|
2021-04-28 23:13:14 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 15:35:47 -04:00
|
|
|
public static void WriteFileContentId(this MemoryWriter writer, FileContentId fileContentId)
|
2021-04-28 23:13:14 -04:00
|
|
|
{
|
2022-03-25 15:35:47 -04:00
|
|
|
writer.WriteMd5Hash(fileContentId.Digest);
|
2022-06-28 16:14:51 -04:00
|
|
|
writer.WriteNullTerminatedUtf8String(fileContentId.Type);
|
2021-05-28 13:44:15 -04:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 15:35:47 -04:00
|
|
|
public static int GetSerializedSize(this FileContentId fileContentId)
|
2021-05-28 13:44:15 -04:00
|
|
|
{
|
2022-06-28 16:14:51 -04:00
|
|
|
return Digest<Md5>.Length + fileContentId.Type.GetNullTerminatedSize();
|
2021-04-28 23:13:14 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|