| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Chronicler; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Computes deterministic record hashes by traversing <see cref="IRecordable.RecordData(IChronicler)"/>. |
| | | 7 | | /// </summary> |
| | | 8 | | public static class ChronicleHashSerializer |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Computes a deterministic hash for a recordable state graph using an empty context. |
| | | 12 | | /// </summary> |
| | | 13 | | public static ChronicleHash Compute(IRecordable target) |
| | | 14 | | { |
| | 49 | 15 | | return Compute(target, new ChronicleContext()); |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Computes a deterministic hash for a recordable state graph using the supplied context. |
| | | 20 | | /// </summary> |
| | | 21 | | public static ChronicleHash Compute(IRecordable target, ChronicleContext context) |
| | | 22 | | { |
| | 73783 | 23 | | if (target == null) |
| | 1 | 24 | | throw new ArgumentNullException(nameof(target)); |
| | 73782 | 25 | | if (context == null) |
| | 1 | 26 | | throw new ArgumentNullException(nameof(context)); |
| | | 27 | | |
| | 73781 | 28 | | var writer = new ChronicleHashWriter(); |
| | 73781 | 29 | | writer.WriteSection("chronicler.hash", 1); |
| | 73781 | 30 | | Contribute(target, context, ref writer); |
| | 73777 | 31 | | return writer.ToHash(); |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Contributes a recordable state graph to an existing caller-owned hash writer using an empty context. |
| | | 36 | | /// </summary> |
| | | 37 | | public static void Contribute(IRecordable target, ref ChronicleHashWriter writer) |
| | | 38 | | { |
| | 3 | 39 | | Contribute(target, new ChronicleContext(), ref writer); |
| | 2 | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Contributes a recordable state graph to an existing caller-owned hash writer using the supplied context. |
| | | 44 | | /// </summary> |
| | | 45 | | public static void Contribute(IRecordable target, ChronicleContext context, ref ChronicleHashWriter writer) |
| | | 46 | | { |
| | 73785 | 47 | | if (target == null) |
| | 1 | 48 | | throw new ArgumentNullException(nameof(target)); |
| | 73784 | 49 | | if (context == null) |
| | 1 | 50 | | throw new ArgumentNullException(nameof(context)); |
| | | 51 | | |
| | 73783 | 52 | | ChronicleHashChronicler.Contribute(target, context, ref writer); |
| | 73779 | 53 | | } |
| | | 54 | | } |