Zarr.NET  0.8.0
Zarr reader and writer in .NET
Loading...
Searching...
No Matches
ZarrNET.CodecPipeline Class Referencesealed

Applies an ordered list of codecs as a pipeline. More...

Public Member Functions

 CodecPipeline (IReadOnlyList< IZarrCodec > codecs, int byteOrderElementSize)
 
Task< byte[]> DecodeAsync (byte[] input, CancellationToken ct=default)
 
Task< byte[]> EncodeAsync (byte[] input, CancellationToken ct=default)
 

Properties

bool CanStoreDecodedBytesWithoutTransform [get]
 True when encoded storage bytes are identical to decoded in-memory array bytes. This allows whole-chunk IO to bypass byte-array materialization without skipping any Zarr-required transform.
 

Detailed Description

Applies an ordered list of codecs as a pipeline.

Zarr v3 codec pipeline: Decode: last codec → ... → first codec (compressed bytes → array bytes) Encode: first codec → ... → last codec (array bytes → compressed bytes)

The pipeline also resolves byte-order swapping for the BytesCodec based on the data type byte-order element size from ZarrArrayMetadata. For complex dtypes this is the real/imag component size, not the full complex size.

When all codecs in the pipeline are synchronous (returning completed Tasks), the decode/encode path avoids async state machine overhead entirely. This is the common case for Blosc, Zstd, and BytesCodec pipelines.

Constructor & Destructor Documentation

◆ CodecPipeline()

ZarrNET.CodecPipeline.CodecPipeline ( IReadOnlyList< IZarrCodec > codecs,
int byteOrderElementSize )
25 {
26 _codecs = codecs;
27 _byteOrderElementSize = byteOrderElementSize;
28
29 // Detect whether every codec in the pipeline is synchronous.
30 // Synchronous codecs return Task.FromResult — we identify them by
31 // interface marker or by known type. GzipCodec is the only async
32 // codec in the codebase (uses Stream.CopyToAsync).
33 _allCodecsSync = codecs.All(c => c is not GzipCodec);
34 }

Member Function Documentation

◆ DecodeAsync()

Task< byte[]> ZarrNET.CodecPipeline.DecodeAsync ( byte[] input,
CancellationToken ct = default )
52 {
53 // Fast path: when all codecs are synchronous, avoid async state machine
54 if (_allCodecsSync)
55 return Task.FromResult(DecodeSynchronous(input, ct));
56
57 return DecodeAsyncCore(input, ct);
58 }

◆ EncodeAsync()

Task< byte[]> ZarrNET.CodecPipeline.EncodeAsync ( byte[] input,
CancellationToken ct = default )
61 {
62 if (_allCodecsSync)
63 return Task.FromResult(EncodeSynchronous(input, ct));
64
65 return EncodeAsyncCore(input, ct);
66 }

The documentation for this class was generated from the following file: