Table of Contents

Class S57CatalogWriter

Namespace
EncDotNet.S57.ExchangeSets
Assembly
EncDotNet.S57.dll

Provides methods to write an S57Catalog as an S-57 CATALOG.031 file.

public static class S57CatalogWriter
Inheritance
S57CatalogWriter
Inherited Members

Remarks

The writer is the inverse of S57CatalogReader. It writes the catalogue in the ASCII implementation that exchange sets use: a DDR, then one record per entry holding the 0001 record identifier (numbered from 0) and a CATD field (S-57 Part 3, clause 7.8.1).

The output depends only on the catalogue, so writing the same catalogue always produces the same bytes. Coordinates are written with six decimal places when that represents them exactly, and otherwise with as many as they need; a missing coordinate is written empty. An entry whose RecordName is empty is written as CD.

Use ComputeCrc(ReadOnlySpan<byte>) to fill in CrcChecksum for each file in the exchange set; the catalogue's own entry has none.

Methods

ComputeCrc(ReadOnlySpan<byte>)

Computes the CRC of a file's contents, formatted for CrcChecksum.

public static string ComputeCrc(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The file's contents.

Returns

string

The CRC-32 as eight upper-case hexadecimal digits, as the CATD CRCS subfield holds it.

Remarks

This is the CRC-32 that S57ExchangeSetVerifier checks (S-57 Part 3, clause 3.4, and the ENC product specification).

ComputeCrcAsync(Stream, CancellationToken)

Asynchronously computes the CRC of a stream's contents, formatted for CrcChecksum.

public static Task<string> ComputeCrcAsync(Stream stream, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to read to its end.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string>

The CRC-32 as eight upper-case hexadecimal digits.

Write(S57Catalog)

Writes a catalogue to a byte array.

public static byte[] Write(S57Catalog catalog)

Parameters

catalog S57Catalog

The catalogue to write.

Returns

byte[]

The encoded CATALOG.031 file.

Exceptions

ArgumentException

An entry can't be encoded; the message names it.

Write(Stream, S57Catalog)

Writes a catalogue to a stream.

public static void Write(Stream stream, S57Catalog catalog)

Parameters

stream Stream

The destination stream.

catalog S57Catalog

The catalogue to write.

Exceptions

ArgumentException

An entry can't be encoded. Nothing is written to the stream.

WriteAsync(Stream, S57Catalog, CancellationToken)

Asynchronously writes a catalogue to a stream.

public static Task WriteAsync(Stream stream, S57Catalog catalog, CancellationToken cancellationToken = default)

Parameters

stream Stream

The destination stream.

catalog S57Catalog

The catalogue to write.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task

A task that represents the asynchronous write operation.

Exceptions

ArgumentException

An entry can't be encoded. Nothing is written to the stream.

WriteToFile(string, S57Catalog)

Writes a catalogue to a file.

public static void WriteToFile(string path, S57Catalog catalog)

Parameters

path string

The destination file path, normally CATALOG.031 at the exchange set root.

catalog S57Catalog

The catalogue to write.

Exceptions

ArgumentException

An entry can't be encoded. The file isn't created or changed.

WriteToFileAsync(string, S57Catalog, CancellationToken)

Asynchronously writes a catalogue to a file.

public static Task WriteToFileAsync(string path, S57Catalog catalog, CancellationToken cancellationToken = default)

Parameters

path string

The destination file path, normally CATALOG.031 at the exchange set root.

catalog S57Catalog

The catalogue to write.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task

A task that represents the asynchronous write operation.

Exceptions

ArgumentException

An entry can't be encoded. The file isn't created or changed.