• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 19283036656

12 Nov 2025 01:06AM UTC coverage: 55.036% (-0.2%) from 55.189%
19283036656

push

github

pwelter34
fix build

1737 of 3650 branches covered (47.59%)

Branch coverage included in aggregate %.

4372 of 7450 relevant lines covered (58.68%)

331.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.57
/src/FluentCommand.Caching/MessagePackCacheSerializer.cs
1
using MessagePack;
2
using MessagePack.Resolvers;
3

4
namespace FluentCommand.Caching;
5

6
/// <summary>
7
/// A MessagePack implementation of IDistributedCacheSerializer
8
/// </summary>
9
/// <seealso cref="FluentCommand.Caching.IDistributedCacheSerializer" />
10
public class MessagePackCacheSerializer : IDistributedCacheSerializer
11
{
12
    private readonly MessagePackSerializerOptions _messagePackSerializerOptions;
13

14
    /// <summary>
15
    /// Initializes a new instance of the <see cref="MessagePackCacheSerializer"/> class.
16
    /// </summary>
17
    /// <param name="messagePackSerializerOptions">The message pack serializer options.</param>
18
    public MessagePackCacheSerializer(MessagePackSerializerOptions messagePackSerializerOptions = null)
1✔
19
    {
20
        _messagePackSerializerOptions = messagePackSerializerOptions
1!
21
            ?? ContractlessStandardResolver.Options.WithCompression(MessagePackCompression.Lz4BlockArray);
1✔
22
    }
1✔
23

24
    /// <summary>
25
    /// Deserializes the specified byte array into an instance of <typeparamref name="T" />.
26
    /// </summary>
27
    /// <typeparam name="T">The type to deserialize</typeparam>
28
    /// <param name="byteArray">The byte array to deserialize.</param>
29
    /// <returns>
30
    /// An instance of <typeparamref name="T" /> deserialized
31
    /// </returns>
32
    public T Deserialize<T>(byte[] byteArray)
33
    {
34
        var value = MessagePackSerializer.Deserialize<T>(byteArray, _messagePackSerializerOptions);
2✔
35
        return value;
2✔
36
    }
37

38
    /// <summary>
39
    /// Deserializes the specified byte array into an instance of <typeparamref name="T" />.
40
    /// </summary>
41
    /// <typeparam name="T">The type to deserialize</typeparam>
42
    /// <param name="byteArray">The byte array to deserialize.</param>
43
    /// <param name="cancellationToken">The cancellation token.</param>
44
    /// <returns>
45
    /// An instance of <typeparamref name="T" /> deserialized
46
    /// </returns>
47
    public Task<T> DeserializeAsync<T>(byte[] byteArray, CancellationToken cancellationToken = default)
48
    {
49
        var value = MessagePackSerializer.Deserialize<T>(byteArray, _messagePackSerializerOptions, cancellationToken);
2✔
50
        return Task.FromResult(value);
2✔
51
    }
52

53
    /// <summary>
54
    /// Serializes the specified instance to a byte array for caching.
55
    /// </summary>
56
    /// <typeparam name="T">The type to serialize</typeparam>
57
    /// <param name="instance">The instance to serialize.</param>
58
    /// <returns>
59
    /// The byte array of the serialized instance
60
    /// </returns>
61
    public byte[] Serialize<T>(T instance)
62
    {
63
        var value = MessagePackSerializer.Serialize(instance, _messagePackSerializerOptions);
×
64
        return value;
×
65
    }
66

67
    /// <summary>
68
    /// Serializes the specified instance to a byte array for caching.
69
    /// </summary>
70
    /// <typeparam name="T">The type to serialize</typeparam>
71
    /// <param name="instance">The instance to serialize.</param>
72
    /// <param name="cancellationToken">The cancellation token.</param>
73
    /// <returns>
74
    /// The byte array of the serialized instance
75
    /// </returns>
76
    public Task<byte[]> SerializeAsync<T>(T instance, CancellationToken cancellationToken = default)
77
    {
78
        var value = MessagePackSerializer.Serialize(instance, _messagePackSerializerOptions, cancellationToken);
2✔
79
        return Task.FromResult(value);
2✔
80
    }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc