< Summary

Information
Class: Chronicler.Hashing.ChronicleHashSerializer
Assembly: Chronicler
File(s): /home/runner/work/Chronicler/Chronicler/src/Chronicler/Hashing/ChronicleHashSerializer.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 80
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Compute(...)100%11100%
Compute(...)100%44100%
Contribute(...)100%11100%
Contribute(...)100%44100%

File(s)

/home/runner/work/Chronicler/Chronicler/src/Chronicler/Hashing/ChronicleHashSerializer.cs

#LineLine coverage
 1//=======================================================================
 2// ChronicleHashSerializer.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9
 10namespace Chronicler.Hashing;
 11
 12/// <summary>
 13/// Computes deterministic record hashes by traversing <see cref="IRecordable.RecordData(IChronicler)"/>.
 14/// </summary>
 15/// <remarks>
 16/// The hash includes the recorded types, field names, defaults, values, and stable link IDs in schema order.
 17/// Supported leaf types are Boolean, fixed-width integers up to 64 bits, characters, strings, and enums.
 18/// </remarks>
 19public static class ChronicleHashSerializer
 20{
 21    /// <summary>Computes a record hash with an empty link registry.</summary>
 22    /// <param name="target">The graph whose schema is traversed in saving mode and in recording-call order.</param>
 23    /// <returns>The version-one hash of the declared state.</returns>
 24    /// <exception cref="ArgumentNullException">The target is null.</exception>
 25    /// <exception cref="InvalidOperationException">A non-null link needs a stable ID. Use the overload with a populated
 26    /// <exception cref="NotSupportedException">The schema records a leaf type unsupported by the hash backend.</excepti
 27    public static ChronicleHash Compute(IRecordable target)
 28    {
 25529        return Compute(target, new ChronicleContext());
 30    }
 31
 32    /// <summary>Computes a deterministic hash of the declared state.</summary>
 33    /// <param name="target">The graph whose schema is traversed in saving mode and in recording-call order.</param>
 34    /// <param name="context">The registry context used to look up stable IDs for links.</param>
 35    /// <returns>The hash of the version-one record stream, including its section header.</returns>
 36    /// <exception cref="ArgumentNullException">The target or context is null.</exception>
 37    /// <exception cref="InvalidOperationException">A non-null link has no stable ID in the context.</exception>
 38    /// <exception cref="NotSupportedException">The schema records a leaf type unsupported by the hash backend.</excepti
 39    public static ChronicleHash Compute(IRecordable target, ChronicleContext context)
 40    {
 7399741        if (target == null)
 142            throw new ArgumentNullException(nameof(target));
 7399643        if (context == null)
 144            throw new ArgumentNullException(nameof(context));
 45
 7399546        var writer = new ChronicleHashWriter();
 7399547        writer.WriteSection("chronicler.hash", 1);
 7399548        Contribute(target, context, ref writer);
 7399049        return writer.ToHash();
 50    }
 51
 52    /// <summary>Appends a record hash contribution with an empty link registry.</summary>
 53    /// <param name="target">The graph whose schema is traversed in saving mode and in recording-call order.</param>
 54    /// <param name="writer">The caller's running writer. Appends the record on success and preserves the writer if reco
 55    /// <exception cref="ArgumentNullException">The target is null.</exception>
 56    /// <exception cref="InvalidOperationException">A non-null link needs a stable ID. Use the overload with a populated
 57    /// <exception cref="NotSupportedException">The schema records a leaf type unsupported by the hash backend.</excepti
 58    public static void Contribute(IRecordable target, ref ChronicleHashWriter writer)
 59    {
 260        Contribute(target, new ChronicleContext(), ref writer);
 161    }
 62
 63    /// <summary>Appends a record to a running hash.</summary>
 64    /// <param name="target">The graph whose schema is traversed in saving mode and in recording-call order.</param>
 65    /// <param name="context">The registry context used to look up stable IDs for links.</param>
 66    /// <param name="writer">The caller's running writer. Appends the record on success and preserves the writer if reco
 67    /// <remarks>Use the same contribution order in every caller that needs matching hashes.</remarks>
 68    /// <exception cref="ArgumentNullException">The target or context is null.</exception>
 69    /// <exception cref="InvalidOperationException">A non-null link has no stable ID in the context.</exception>
 70    /// <exception cref="NotSupportedException">The schema records a leaf type unsupported by the hash backend.</excepti
 71    public static void Contribute(IRecordable target, ChronicleContext context, ref ChronicleHashWriter writer)
 72    {
 7399873        if (target == null)
 174            throw new ArgumentNullException(nameof(target));
 7399775        if (context == null)
 176            throw new ArgumentNullException(nameof(context));
 77
 7399678        ChronicleHashChronicler.Contribute(target, context, ref writer);
 7399179    }
 80}