| | | 1 | | using ArturRios.Data.Export.Configuration; |
| | | 2 | | using MessagePack; |
| | | 3 | | using Microsoft.Extensions.Logging; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Data.Export.Exporters; |
| | | 6 | | |
| | | 7 | | /// <summary>Serializes the collection to MessagePack (the binary format) using the contractless resolver.</summary> |
| | | 8 | | /// <typeparam name="T">The record type.</typeparam> |
| | | 9 | | /// <param name="options">MessagePack options.</param> |
| | | 10 | | /// <param name="logger">Optional logger; see <see cref="ExporterBase{T}" />.</param> |
| | | 11 | | public class MessagePackExporter<T>(MessagePackOptions options, ILogger<MessagePackExporter<T>>? logger = null) |
| | 8 | 12 | | : ExporterBase<T>(logger) where T : class |
| | | 13 | | { |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | protected override Task WriteCoreAsync(IEnumerable<T> data, Stream destination, CancellationToken ct) |
| | | 16 | | { |
| | 4 | 17 | | var array = data as T[] ?? data.ToArray(); |
| | 4 | 18 | | return MessagePackSerializer.SerializeAsync(destination, array, options.Effective, ct); |
| | | 19 | | } |
| | | 20 | | } |