< Summary - Combined Code Coverage

Information
Class: NLightning.Bolt11.Models.TaggedFields.MetadataTaggedField
Assembly: NLightning.Bolt11
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/MetadataTaggedField.cs
Tag: 30_15166811759
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 63
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%11100%
get_Value()100%11100%
get_Length()100%11100%
.ctor(...)100%11100%
WriteToBitWriter(...)100%11100%
IsValid()100%11100%
FromBitReader(...)100%44100%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Bolt11/Models/TaggedFields/MetadataTaggedField.cs

#LineLine coverage
 1namespace NLightning.Bolt11.Models.TaggedFields;
 2
 3using Common.Utils;
 4using Enums;
 5using Interfaces;
 6
 7/// <summary>
 8/// Tagged field for the metadata
 9/// </summary>
 10/// <remarks>
 11/// The metadata is a variable length field that can be used to store additional information
 12/// </remarks>
 13/// <seealso cref="ITaggedField"/>
 14internal sealed class MetadataTaggedField : ITaggedField
 15{
 9616    public TaggedFieldTypes Type => TaggedFieldTypes.METADATA;
 8817    internal byte[] Value { get; }
 7218    public short Length { get; }
 19
 20    /// <summary>
 21    /// Initializes a new instance of the <see cref="MetadataTaggedField"/> class.
 22    /// </summary>
 23    /// <param name="value">The metadata bytes</param>
 8824    internal MetadataTaggedField(byte[] value)
 25    {
 8826        Value = value;
 8827        Length = (short)Math.Ceiling(value.Length * 8 / 5.0);
 8828    }
 29
 30    /// <inheritdoc/>
 31    public void WriteToBitWriter(BitWriter bitWriter)
 32    {
 33        // Write data
 2434        bitWriter.WriteBits(Value, Length * 5);
 2435    }
 36
 37    /// <inheritdoc/>
 38    public bool IsValid()
 39    {
 440        return true;
 41    }
 42
 43    /// <summary>
 44    /// Reads a MetadataTaggedField from a BitReader
 45    /// </summary>
 46    /// <param name="bitReader">The BitReader to read from</param>
 47    /// <param name="length">The length of the field</param>
 48    /// <returns>The MetadataTaggedField</returns>
 49    /// <exception cref="ArgumentException">Thrown when the length is invalid</exception>
 50    internal static MetadataTaggedField FromBitReader(BitReader bitReader, short length)
 51    {
 5252        if (length <= 0)
 53        {
 854            throw new ArgumentException("Invalid length for MetadataTaggedField. Length must be greater than 0", nameof(
 55        }
 56
 57        // Read the data from the BitReader
 4458        var data = new byte[(length * 5 + 7) / 8];
 4459        bitReader.ReadBits(data, length * 5);
 60
 4461        return new MetadataTaggedField(length * 5 % 8 > 0 ? data[..^1] : data);
 62    }
 63}