1
0

adjust code namespace with binary data format designed.

This commit is contained in:
Ca2didi 2025-03-16 02:53:23 +08:00
parent 1f58525816
commit 48bff49511
24 changed files with 371 additions and 103 deletions

View File

@ -1,9 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Abstraction", "Flawless.Abstraction\Flawless.Abstraction.csproj", "{2AF2AA78-8AFB-49B7-AE38-842D301A4DDE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Abstract", "Flawless.Abstract\Flawless.Abstract.csproj", "{2AF2AA78-8AFB-49B7-AE38-842D301A4DDE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Abstract.Test", "Flawless.Abstract.Test\Flawless.Abstract.Test.csproj", "{5B1CB26D-99F5-491A-B368-7E3552FE67E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Core", "Flawless.Core\Flawless.Core.csproj", "{FA8139D0-FBA4-4F17-9017-B446A732D0E8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -18,5 +20,9 @@ Global
{5B1CB26D-99F5-491A-B368-7E3552FE67E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B1CB26D-99F5-491A-B368-7E3552FE67E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B1CB26D-99F5-491A-B368-7E3552FE67E9}.Release|Any CPU.Build.0 = Release|Any CPU
{FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -17,7 +17,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Flawless.Abstraction\Flawless.Abstraction.csproj" />
<ProjectReference Include="..\Flawless.Abstract\Flawless.Abstract.csproj" />
</ItemGroup>
</Project>

View File

@ -4,6 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Flawless.Abstraction</RootNamespace>
</PropertyGroup>
</Project>

View File

@ -6,9 +6,9 @@ namespace Flawless.Abstraction;
/// An MD5 based hash code storage.
/// </summary>
[Serializable]
public readonly struct HashId : IEquatable<HashId>
public record struct HashId
{
public static HashId Empty { get; } = new(0);
public static HashId Empty => new(0);
private readonly UInt128 _hash;
@ -17,16 +17,16 @@ public readonly struct HashId : IEquatable<HashId>
_hash = hash;
}
public HashId(ulong upper, ulong lower)
{
_hash = new UInt128(upper, lower);
}
public bool Equals(HashId other)
{
return _hash == other._hash;
}
public override bool Equals(object? obj)
{
return obj is HashId other && Equals(other);
}
public override int GetHashCode()
{
return _hash.GetHashCode();

View File

@ -1,33 +0,0 @@
namespace Flawless.Abstraction;
/// <summary>
/// An author setup to indicate who create a depot or identify a depot author when uploading it.
/// </summary>
[Serializable]
public readonly struct Author : IEquatable<Author>
{
public readonly string Name;
public readonly string Email;
public Author(string name, string email)
{
Name = name;
Email = email;
}
public bool Equals(Author other)
{
return Name == other.Name && Email == other.Email;
}
public override bool Equals(object? obj)
{
return obj is Author other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(Name, Email);
}
}

View File

@ -1,11 +0,0 @@
namespace Flawless.Abstraction;
/// <summary>
/// Standardized interface for any platform to describe data block (Not the actual data) in repository.
/// </summary>
public interface IDepotLabel
{
public abstract HashId Id { get; }
public abstract IEnumerable<HashId> Dependencies { get; }
}

View File

@ -1,18 +0,0 @@
namespace Flawless.Abstraction;
/// <summary>
/// Standardized interface to describe a place to store depots and how they connected with each other.
/// </summary>
public interface IReadonlyRepository
{
public bool IsReadonly { get; }
public IEnumerable<RepositoryCommit> GetCommits();
public RepositoryCommit? GetCommitById(uint commitId);
public IAsyncEnumerable<RepositoryCommit> GetCommitsAsync(CancellationToken cancellationToken = default);
public Task<RepositoryCommit?> GetCommitByIdAsync(uint commitId, CancellationToken cancellationToken = default);
}

View File

@ -1,11 +0,0 @@
namespace Flawless.Abstraction;
/// <summary>
/// Standardized interface to describe a place to store depots and how they connected with each other with write support.
/// </summary>
public interface IRepository : IReadonlyRepository
{
public uint GetActiveCommitId();
public Task GetActiveCommitIdAsync(CancellationToken cancellationToken = default);
}

View File

@ -1,21 +0,0 @@
namespace Flawless.Abstraction;
public abstract class RepositoryCommit
{
public abstract IReadonlyRepository Repository { get; }
public abstract UInt64 Id { get; }
public abstract Author Author { get; }
public abstract DateTime CommitTime { get; }
public abstract string Message { get; }
public abstract IDepotLabel Depot { get; }
public abstract RepositoryCommit? GetParentCommit();
public abstract RepositoryCommit? GetChildCommit();
}

View File

@ -0,0 +1,108 @@
using System.Runtime.InteropServices;
namespace Flawless.Core.BinaryDataFormat;
/* Depot Transmission Format Design - Version 1
*
* We have shrink some layout design and remap fields in order to optimize for networking transmission.
*
* Notice that we have assumed that all data are represent as LITTLE ENDIAN.
*
* Padding with 8 byte width, so:
*
* ------------------------------------------
* 0 : Version Code
* 1 : Network Transmission Feature
* 2 : Compressing Algorithm Type (CompressType)
* 3 : Checksum Confuser
* 4 : Depot Generate Time
* 5 : ~
* 6 : ~
* 7 : ~
* ------------------------------------------
* 8 : ~
* 9 : ~
* 10 : ~
* 11 : ~
* 12 : File Map String Size
* 13 : ~
* 14 : ~
* 15 : ~
* ------------------------------------------
* 16 : ~
* 17 : ~
* 18 : ~
* 19 : ~
* 20 : ~
* 21 : ~
* 22 : ~
* 23 : ~
* ------------------------------------------
* 24 : ~
* 25 : ~
* 26 : ~
* 27 : ~
* 28 : Payload Size
* 29 : ~
* 30 : ~
* 31 : ~
* ------------------------------------------
* 32 : ~
* 33 : ~
* 34 : ~
* 35 : ~
* 36 : MD5 Checksum (Standard MD5Checksum)
* 37 : ~
* 38 : ~
* 39 : ~
* ------------------------------------------
* 40 : ~
* 41 : ~
* 42 : ~
* 43 : ~
* 44 : ~
* 45 : ~
* 46 : ~
* 47 : ~
* ------------------------------------------
* 48 : ~
* 49 : ~
* 50 : ~
* 51 : ~
* 52 : ~
* ------------------------------------------
* FILE NAME MAP (STRING IN UTF8)
* ------------------------------------------
* PAYLOAD
*/
[Flags]
public enum NetworkTransmissionFeatureFlag: byte
{
FileMapIsJson = 1 << 0,
FileMapUseCompressionArgument = 1 << 7,
}
[Serializable, StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi, Pack = 8, Size = 52)]
public struct NetworkDepotHeaderV1
{
[FieldOffset(0)] public byte Version;
[FieldOffset(1)] public NetworkTransmissionFeatureFlag NetworkTransmissionFeature;
[FieldOffset(2)] public byte CompressType;
[FieldOffset(3)] public byte Md5Confuser;
[FieldOffset(4)] public ulong GenerateTime;
[FieldOffset(12)] public ulong FileMapStringSizeLower;
[FieldOffset(20)] public ulong FileMapStringSizeUpper;
[FieldOffset(28)] public ulong PayloadSize;
[FieldOffset(36)] public ulong Md5ChecksumLower;
[FieldOffset(44)] public ulong Md5ChecksumUpper;
}

View File

@ -0,0 +1,131 @@
using System.Runtime.InteropServices;
using Flawless.Core.Modal;
namespace Flawless.Core.BinaryDataFormat;
/* Depot File System Format Design - Version 1
*
* For best accessing performance, consider use checksum as filename. Binary info did not contains file name mapping, so
* use another file to get the file map of this depot. The structure to describe a map has already defined below.
*
* Consider of compability when depot format was updated, we have configure a lots of area as empty.
*
* Notice that we assuming that all data are represent as LITTLE ENDIAN.
*
* Padding with 4 byte width, so:
*
* ------------------------------------------
* 0 : Magic Number
* 1 : ~
* 2 : ~
* 3 : ~
* ------------------------------------------
* 4 : MD5 Checksum (Header + Data)
* 5 : ~
* 6 : ~
* 7 : ~
* ------------------------------------------
* 8 : ~
* 9 : ~
* 10 : ~
* 11 : ~
* ------------------------------------------
* 12 : ~
* 13 : ~
* 14 : ~
* 15 : ~
* ------------------------------------------
* 16 : ~
* 17 : ~
* 18 : ~
* 19 : ~
* ------------------------------------------
* 20 : Version Code
* 21 : Checksum Confuser
* 22 : (Unused)
* 23 : (Unused)
* ------------------------------------------
* 24 : Depot Generate Time
* 25 : ~
* 26 : ~
* 27 : ~
* ------------------------------------------
* 28 : ~
* 29 : ~
* 30 : ~
* 31 : ~
* ------------------------------------------
* 32 : Compressing Algorithm Type (CompressType)
* 33 : (Preserve)
* 34 : (Preserve)
* 35 : (Preserve)
* ------------------------------------------
* 36 : (Preserve)
* 37 : (Preserve)
* 38 : (Preserve)
* 39 : (Preserve)
* ------------------------------------------
* 40 : Payload Size
* 41 : ~
* 42 : ~
* 43 : ~
* ------------------------------------------
* 44 : ~
* 45 : ~
* 46 : ~
* 47 : ~
* ------------------------------------------
* 48 : (Unused)
* 49 : (Unused)
* 50 : (Unused)
* 51 : (Unused)
* ------------------------------------------
* 52 : (Unused)
* 53 : (Unused)
* 54 : (Unused)
* 55 : (Unused)
* ------------------------------------------
* 56 : (Unused)
* 57 : (Unused)
* 58 : (Unused)
* 59 : (Unused)
* ------------------------------------------
* 60 : (Unused)
* 61 : (Unused)
* 62 : (Unused)
* 63 : (Unused)
* ------------------------------------------
* PAYLOAD
*/
[Serializable, StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi, Pack = 4, Size = 64)]
public struct StandardDepotHeaderV1
{
public const uint FormatMagicNumber = 0xAAAAAAAAu;
[FieldOffset(0)] public uint MagicNumber;
[FieldOffset(4)] public ulong Md5ChecksumLower;
[FieldOffset(12)] public ulong Md5ChecksumUpper;
[FieldOffset(20)] public byte Version;
[FieldOffset(21)] public byte Md5Confuser;
[FieldOffset(22)] public ushort PayloadUnit;
[FieldOffset(24)] public ulong GenerateTime;
[FieldOffset(32)] public byte CompressType;
[FieldOffset(40)] public ulong PayloadSize;
}
[Serializable]
public struct StandardDepotMapV1
{
public uint FileCount;
public DepotFileInfo[] Files;
}

12
Flawless.Core/Const.cs Normal file
View File

@ -0,0 +1,12 @@
namespace Flawless.Core;
public static class Const
{
public const string RootDirectory = ".flawless";
public static readonly string DepotDirectory = Path.Combine(RootDirectory, "depot");
public static readonly string CommitDirectory = Path.Combine(RootDirectory, "commit");
public static readonly string TrackerFile = Path.Combine(RootDirectory, "tracker");
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Flawless.Abstract\Flawless.Abstract.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,18 @@
namespace Flawless.Core.Interface;
/// <summary>
/// Standardized interface to describe a place to store depots and how they connected with each other.
/// </summary>
public interface IReadonlyRepository
{
public bool IsReadonly { get; }
public IEnumerable<IRepositoryCommit> GetCommits();
public IRepositoryCommit? GetCommitById(uint commitId);
public IAsyncEnumerable<IRepositoryCommit> GetCommitsAsync(CancellationToken cancellationToken = default);
public Task<IRepositoryCommit?> GetCommitByIdAsync(uint commitId, CancellationToken cancellationToken = default);
}

View File

@ -0,0 +1,22 @@
using Flawless.Core.Modal;
namespace Flawless.Core.Interface;
public interface IRepositoryCommit
{
public IReadonlyRepository Repository { get; }
public UInt64 CommitId { get; }
public Author Author { get; }
public DateTime CommitTime { get; }
public string Message { get; }
public IRepositoryCommit? GetParentCommit();
public IRepositoryCommit? GetChildCommit();
public ValueTask<CommitManifest> GetManifest(CancellationToken cancellationToken = default);
}

View File

@ -0,0 +1,7 @@
namespace Flawless.Core.Modal;
/// <summary>
/// An author setup to indicate who create a depot or identify a depot author when uploading it.
/// </summary>
[Serializable]
public record struct Author(string Name, string Email);

View File

@ -0,0 +1,3 @@
namespace Flawless.Core.Modal;
public record class CommitManifest(ulong ManifestId, DepotLabel Depot, string[] FilePaths);

View File

@ -0,0 +1,7 @@
namespace Flawless.Core.Modal;
public enum CompressType: byte
{
Raw = 0,
Gzip = 1,
}

View File

@ -0,0 +1,24 @@
using Flawless.Abstraction;
namespace Flawless.Core.Modal;
public class Depot
{
public string RawDataPath { get; }
public HashId DepotHash { get; }
public byte Version { get; }
public byte ChecksumConfuser { get; }
public DateTime GenerateTime { get; }
public CompressType CompressType { get; }
public ulong PayloadSize { get; }
public uint FileCount { get; }
public DepotFileInfo[] Files { get; }
}

View File

@ -0,0 +1,4 @@
namespace Flawless.Core.Modal;
[Serializable]
public record struct DepotFileInfo(ulong Size, ulong Offset, string Path);

View File

@ -0,0 +1,6 @@
using Flawless.Abstraction;
namespace Flawless.Core.Modal;
[Serializable]
public record struct DepotLabel(HashId Id, HashId[] Baselines);