< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Serialization.ValueObjects.ShortChannelIdTypeSerializer
Assembly: NLightning.Infrastructure.Serialization
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Serialization/ValueObjects/ShortChannelIdTypeSerializer.cs
Tag: 36_15743069263
Line coverage
72%
Covered lines: 8
Uncovered lines: 3
Coverable lines: 11
Total lines: 51
Line coverage: 72.7%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SerializeAsync()50%2.06275%
DeserializeAsync()100%11100%
NLightning-Domain-Serialization-Interfaces-IValueObjectTypeSerializer-DeserializeAsync()100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Serialization/ValueObjects/ShortChannelIdTypeSerializer.cs

#LineLine coverage
 1using System.Buffers;
 2using NLightning.Domain.Channels.ValueObjects;
 3using NLightning.Domain.Interfaces;
 4using NLightning.Domain.Serialization.Interfaces;
 5
 6namespace NLightning.Infrastructure.Serialization.ValueObjects;
 7public class ShortChannelIdTypeSerializer : IValueObjectTypeSerializer<ShortChannelId>
 8{
 9    /// <summary>
 10    /// Serializes a ShortChannelId value into a stream.
 11    /// </summary>
 12    /// <param name="valueObject">The ShortChannelId value to serialize.</param>
 13    /// <param name="stream">The stream where the serialized value will be written.</param>
 14    /// <returns>A task that represents the asynchronous serialization operation.</returns>
 15    /// <exception cref="ArgumentNullException">Thrown when the stream is null.</exception>
 16    /// <exception cref="IOException">Thrown when an I/O error occurs during the write operation.</exception>
 17    public async Task SerializeAsync(IValueObject valueObject, Stream stream)
 18    {
 419        if (valueObject is not ShortChannelId shortChannelId)
 020            throw new ArgumentException("Value object must be of type ShortChannelId.", nameof(valueObject));
 21
 422        await stream.WriteAsync(shortChannelId);
 423    }
 24
 25    /// <summary>
 26    /// Deserializes a ShortChannelId value from a stream.
 27    /// </summary>
 28    /// <param name="stream">The stream from which the ShortChannelId value will be deserialized.</param>
 29    /// <returns>A task that represents the asynchronous deserialization operation, containing the deserialized ShortCha
 30    /// <exception cref="ArgumentException">Thrown when the stream is empty or contains insufficient data for deserializ
 31    /// <exception cref="IOException">Thrown when an I/O error occurs during the read operation.</exception>
 32    public async Task<ShortChannelId> DeserializeAsync(Stream stream)
 33    {
 434        var buffer = ArrayPool<byte>.Shared.Rent(ShortChannelId.Length);
 35
 36        try
 37        {
 438            await stream.ReadExactlyAsync(buffer.AsMemory()[..ShortChannelId.Length]);
 39
 440            return new ShortChannelId(buffer[..ShortChannelId.Length]);
 41        }
 42        finally
 43        {
 444            ArrayPool<byte>.Shared.Return(buffer);
 45        }
 446    }
 47    async Task<IValueObject> IValueObjectTypeSerializer.DeserializeAsync(Stream stream)
 48    {
 049        return await DeserializeAsync(stream);
 050    }
 51}