< Summary

Information
Class: Chronicler.Serialization.MemoryPackRecordEntryTable
Assembly: Chronicler
File(s): /home/runner/work/Chronicler/Chronicler/src/Chronicler/Serialization/MemoryPack/MemoryPackRecordEntryTable.cs
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 99
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
get_State()100%22100%
set_State(...)100%11100%
set_Item(...)100%11100%
Remove(...)100%11100%
ToEntryMap()100%22100%
TryGetValue(...)100%11100%
LoadState(...)100%66100%

File(s)

/home/runner/work/Chronicler/Chronicler/src/Chronicler/Serialization/MemoryPack/MemoryPackRecordEntryTable.cs

#LineLine coverage
 1//=======================================================================
 2// MemoryPackRecordEntryTable.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
 8#if !CHRONICLER_DISABLE_MEMORYPACK
 9using System;
 10using System.Collections.Generic;
 11using MemoryPack;
 12
 13namespace Chronicler.Serialization;
 14
 15/// <summary>
 16/// Stores ordered MemoryPack entry payloads while preserving the previous SwiftDictionary wire shape.
 17/// </summary>
 18[MemoryPackable]
 19internal sealed partial class MemoryPackRecordEntryTable
 20{
 21    private OrderedStringMap<byte[]?> _entries;
 22
 83023    public MemoryPackRecordEntryTable()
 24    {
 83025        _entries = new OrderedStringMap<byte[]?>(8, StringComparer.Ordinal);
 83026    }
 27
 18628    internal MemoryPackRecordEntryTable(OrderedStringMap<byte[]?> entries)
 29    {
 18630        _entries = entries;
 18631    }
 32
 33    [MemoryPackConstructor]
 34    public MemoryPackRecordEntryTable(MemoryPackRecordEntryTableState state)
 32035        : this()
 36    {
 32037        LoadState(state);
 32038    }
 39
 40    /// <summary>
 41    /// Gets or sets the serializable table state.
 42    /// </summary>
 43    [MemoryPackInclude]
 44    public MemoryPackRecordEntryTableState State
 45    {
 46        get
 47        {
 29448            var items = new KeyValuePair<string, byte[]?>[_entries.Count];
 29449            int index = 0;
 50
 167651            foreach (KeyValuePair<string, byte[]?> entry in _entries)
 54452                items[index++] = entry;
 53
 29454            return new MemoryPackRecordEntryTableState(items);
 55        }
 356        internal set => LoadState(value);
 57    }
 58
 59    internal byte[]? this[string name]
 60    {
 6661        set => _entries[name] = value;
 62    }
 63
 64    internal bool Remove(string name)
 65    {
 3966        return _entries.Remove(name);
 67    }
 68
 69    internal OrderedStringMap<byte[]?> ToEntryMap()
 70    {
 21571        var entries = new OrderedStringMap<byte[]?>(_entries.Count, StringComparer.Ordinal);
 72
 115273        foreach (KeyValuePair<string, byte[]?> entry in _entries)
 36174            entries[entry.Key] = entry.Value;
 75
 21576        return entries;
 77    }
 78
 79    internal bool TryGetValue(string name, out byte[]? payload)
 80    {
 4781        return _entries.TryGetValue(name, out payload);
 82    }
 83
 84    private void LoadState(MemoryPackRecordEntryTableState state)
 85    {
 32386        KeyValuePair<string, byte[]?>[]? items = state.Items;
 32387        int capacity = items?.Length ?? 8;
 32388        var entries = new OrderedStringMap<byte[]?>(capacity, StringComparer.Ordinal);
 89
 32390        if (items != null)
 91        {
 176892            foreach (KeyValuePair<string, byte[]?> item in items)
 56393                entries[item.Key] = item.Value;
 94        }
 95
 32396        _entries = entries;
 32397    }
 98}
 99#endif