Class FixedWidthBinaryLoader<TRecord>
- Namespace
- Wolfgang.Etl.FixedWidth
- Assembly
- Wolfgang.Etl.FixedWidth.dll
Writes records of type TRecord to a fixed-length binary record
stream (mainframe / COBOL, #21) — the write counterpart of
FixedWidthBinaryExtractor<TRecord>. Each record is encoded to a fixed number of
bytes (the field byte widths) and written back-to-back with no delimiters, encoding
COMP-3 packed-decimal and COMP binary-integer fields alongside text.
public sealed class FixedWidthBinaryLoader<TRecord> : LoaderBase<TRecord, FixedWidthReport>, ILoadWithProgressAndCancellationAsync<TRecord, FixedWidthReport>, ILoadWithProgressAsync<TRecord, FixedWidthReport>, ILoadWithCancellationAsync<TRecord>, ILoadAsync<TRecord>, IReportsItemErrors, IAsyncDisposable, IDisposable where TRecord : notnull
Type Parameters
TRecordThe record type, whose FixedWidthBinaryFieldAttribute properties define the byte layout.
- Inheritance
-
LoaderBase<TRecord, FixedWidthReport>FixedWidthBinaryLoader<TRecord>
- Implements
-
ILoadWithProgressAndCancellationAsync<TRecord, FixedWidthReport>ILoadWithProgressAsync<TRecord, FixedWidthReport>ILoadWithCancellationAsync<TRecord>ILoadAsync<TRecord>IReportsItemErrors
- Inherited Members
-
LoaderBase<TRecord, FixedWidthReport>.DisposeAsync()LoaderBase<TRecord, FixedWidthReport>.Dispose()LoaderBase<TRecord, FixedWidthReport>.ReportingIntervalLoaderBase<TRecord, FixedWidthReport>.CurrentItemCountLoaderBase<TRecord, FixedWidthReport>.CurrentSkippedItemCountLoaderBase<TRecord, FixedWidthReport>.CurrentErrorItemCountLoaderBase<TRecord, FixedWidthReport>.MaximumItemCountLoaderBase<TRecord, FixedWidthReport>.SkipItemCountLoaderBase<TRecord, FixedWidthReport>.WorkerResilienceLoaderBase<TRecord, FixedWidthReport>.ErrorPolicy
Constructors
FixedWidthBinaryLoader(Stream, ILogger<FixedWidthBinaryLoader<TRecord>>)
Initializes a new FixedWidthBinaryLoader<TRecord> from a Stream using the default options, with diagnostic logging.
[Obsolete("Use the constructor that takes FixedWidthBinaryLoaderOptions. This overload will be removed in a future release.")]
public FixedWidthBinaryLoader(Stream stream, ILogger<FixedWidthBinaryLoader<TRecord>> logger)
Parameters
streamStreamThe stream to use.
loggerILogger<FixedWidthBinaryLoader<TRecord>>The logger to use for diagnostic output.
Exceptions
- ArgumentNullException
streamis null.
FixedWidthBinaryLoader(Stream, FixedWidthBinaryLoaderOptions?, ILogger<FixedWidthBinaryLoader<TRecord>>?)
Initializes a new FixedWidthBinaryLoader<TRecord> that writes fixed-length
binary records to stream. The caller retains ownership of the stream.
public FixedWidthBinaryLoader(Stream stream, FixedWidthBinaryLoaderOptions? options = null, ILogger<FixedWidthBinaryLoader<TRecord>>? logger = null)
Parameters
streamStreamThe writable destination stream.
optionsFixedWidthBinaryLoaderOptionsOptions that control behaviour, including the encoding. When
null— or omitted — the documented defaults apply.loggerILogger<FixedWidthBinaryLoader<TRecord>>An optional ILogger<TCategoryName> for diagnostic output. Pass null (the default) to disable logging.
Exceptions
- ArgumentNullException
streamis null.- ArgumentException
streamis not writable.
Properties
Encoding
[Obsolete("Set Encoding on FixedWidthBinaryLoaderOptions and pass it to the constructor instead. This property will be removed in a future release.")]
public Encoding Encoding { get; init; }
Property Value
Remarks
Retained for source compatibility with 0.10.x. It is honoured only when the constructor was given no options object; a caller who passes options is using the supported route and that value wins. The two cannot conflict in existing code, because the options constructor did not exist before 0.11.0.
RecordByteLength
The number of bytes in one record, derived from the field layout.
public int RecordByteLength { get; }
Property Value
Methods
CreateProgressReport()
Creates a progress report of type TProgress. This gives the derived class the opportunity to implement a custom progress report that is specific to the loading process.
protected override FixedWidthReport CreateProgressReport()
Returns
- FixedWidthReport
Progress of type TProgress
CreateProgressTimer(IProgress<FixedWidthReport>)
Creates the Wolfgang.Etl.Abstractions.IProgressTimer used to drive progress callbacks. Override this method in a derived class to inject a custom timer (for example, a custom implementation that allows manual control in unit tests).
protected override IProgressTimer CreateProgressTimer(IProgress<FixedWidthReport> progress)
Parameters
progressIProgress<FixedWidthReport>The progress sink that will receive callbacks.
Returns
- IProgressTimer
A started Wolfgang.Etl.Abstractions.IProgressTimer instance.
LoadWorkerAsync(IAsyncEnumerable<TRecord>, CancellationToken)
This method is the core implementation of the loading logic and should be overridden by derived classes.
protected override Task LoadWorkerAsync(IAsyncEnumerable<TRecord> items, CancellationToken cancellationToken)
Parameters
itemsIAsyncEnumerable<TRecord>The items to be loaded to the destination.
cancellationTokenCancellationToken
Returns
- Task
A task representing the asynchronous operation.
Remarks
Items may be an empty sequence if no data is available or if the loading fails.
Exceptions
- ArgumentNullException
Argument items is null