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

TRecord

The 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>.ReportingInterval
LoaderBase<TRecord, FixedWidthReport>.CurrentItemCount
LoaderBase<TRecord, FixedWidthReport>.CurrentSkippedItemCount
LoaderBase<TRecord, FixedWidthReport>.CurrentErrorItemCount
LoaderBase<TRecord, FixedWidthReport>.MaximumItemCount
LoaderBase<TRecord, FixedWidthReport>.SkipItemCount
LoaderBase<TRecord, FixedWidthReport>.WorkerResilience
LoaderBase<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

stream Stream

The stream to use.

logger ILogger<FixedWidthBinaryLoader<TRecord>>

The logger to use for diagnostic output.

Exceptions

ArgumentNullException

stream is 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

stream Stream

The writable destination stream.

options FixedWidthBinaryLoaderOptions

Options that control behaviour, including the encoding. When null — or omitted — the documented defaults apply.

logger ILogger<FixedWidthBinaryLoader<TRecord>>

An optional ILogger<TCategoryName> for diagnostic output. Pass null (the default) to disable logging.

Exceptions

ArgumentNullException

stream is null.

ArgumentException

stream is not writable.

Properties

Encoding

The Encoding used by this instance. Superseded by 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

Encoding

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

int

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

progress IProgress<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

items IAsyncEnumerable<TRecord>

The items to be loaded to the destination.

cancellationToken CancellationToken

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