DotNet.Ships.Class.Slef - Elite-Dangerous-Almanac/Almanac-Core GitHub Wiki

EliteDangerousAlmanac / Ships / Slef

Class: Slef

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:35

The Ship Loadout Export Format: a strict reader, a tolerant inspector and a writer.

Remarks

SLEF is the community interchange format for a fitted ship, which EDSY, Coriolis, Inara and others all read and write. It is the game journal's Loadout event wrapped in an envelope that records which application exported it:

[{ "header": { "appName": "EDSY", "appVersion": "..." },
   "data":   { "event": "Loadout", "Ship": "explorer_nx", "Modules": [ ... ] } }]

The top level is an array, so several builds travel together. This class carries the record shapes only, so it reads no ship, module or blueprint catalogue.

The specification is Inara's, at https://inara.cz/elite/inara-impexp-slef/.

Methods

FindModifier()

static FindModifier(module, label): double?

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:227

Reads one engineering modifier off a fitted module by its journal label.

Parameters

module

LoadoutModule

The fitted module.

label

string?

The stat's journal name, such as FSDOptimalMass. It is matched with the surrounding whitespace removed and the case folded.

Returns

double?

The modifier's numeric value, or null when the module is not engineered, states no modifiers at all, carries no such modifier, or carries one that is not numeric.

Exceptions

ArgumentNullException

module is null.

Inspect()

static Inspect(json): SlefInspection

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:72

Inspects a SLEF payload without losing the entries it cannot read.

Parameters

json

string

The export's JSON text.

Returns

SlefInspection

Every valid entry, and one diagnostic for each entry that was rejected.

Exceptions

ArgumentNullException

json is null.

JsonException

json is not valid JSON.

Inspect()

static Inspect(root): SlefInspection

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:86

Inspects an already-parsed SLEF payload.

Parameters

root

JsonElement

The payload. The accepted shapes, in order of leniency, are the standard array of envelopes, a single envelope, and a bare journal Loadout event, which is given an empty header of its own.

Returns

SlefInspection

Every valid entry, and one diagnostic for each entry that was rejected.

Parse()

static Parse(json): IReadOnlyList<SlefEntry>

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:112

Reads a SLEF payload, refusing the whole export over one bad entry.

Parameters

json

string

The export's JSON text.

Returns

IReadOnlyList<SlefEntry>

The entries, in export order. It is never empty.

Exceptions

ArgumentNullException

json is null.

JsonException

json is not valid JSON.

FormatException

The payload holds no entry, or an entry, a header, a loadout, a module or an engineering field is malformed. Use Inspect to recover the valid entries of a mixed payload instead.

Parse()

static Parse(root): IReadOnlyList<SlefEntry>

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:120

Reads an already-parsed SLEF payload, refusing it over one bad entry.

Parameters

root

JsonElement

The payload, in any of the shapes Inspect takes.

Returns

IReadOnlyList<SlefEntry>

The entries, in export order. It is never empty.

Exceptions

FormatException

The payload holds no entry, or one of its fields is malformed.

Stringify()

static Stringify(slef): string

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:188

Writes a SLEF export as compact JSON.

Parameters

slef

IReadOnlyList<SlefEntry>

The entries, as Wrap answers them.

Returns

string

The JSON text, which is what the clipboard exchange these exports travel by wants.

Exceptions

ArgumentNullException

slef is null.

Stringify()

static Stringify(slef, indent): string

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:200

Writes a SLEF export as indented JSON, for a file a person reads.

Parameters

slef

IReadOnlyList<SlefEntry>

The entries to write.

indent

int

The spaces one indent level costs, from 1 to 127.

Returns

string

The JSON text.

Exceptions

ArgumentNullException

slef is null.

ArgumentOutOfRangeException

indent is outside 1 to 127.

Wrap()

static Wrap(data, header): IReadOnlyList<SlefEntry>

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:131

Wraps one loadout in a SLEF envelope.

Parameters

data

LoadoutEvent

The loadout to export.

header

SlefHeader

Which exporting application to credit. SLEF attribution belongs to the application producing the export, so a caller states its own name and version.

Returns

IReadOnlyList<SlefEntry>

The export, holding the one entry.

Exceptions

ArgumentNullException

An argument is null.

FormatException

The header or the loadout is malformed.

Wrap()

static Wrap(data, header): IReadOnlyList<SlefEntry>

Defined in: dotnet/src/EliteDangerousAlmanac/Ships/Slef.cs:150

Wraps several loadouts in one SLEF export.

Parameters

data

IReadOnlyList<LoadoutEvent>

The loadouts to export. They travel as separate entries, which is what the format's array top level is for.

header

SlefHeader

Which exporting application to credit.

Returns

IReadOnlyList<SlefEntry>

The export, one entry per loadout, in the order given.

Remarks

Every entry is checked by the walker a read uses, so anything this answers reads back.

Exceptions

ArgumentNullException

An argument is null.

ArgumentException

data is empty. A read rejects an empty export, so writing one would break the promise that everything this produces reads back.

FormatException

The header or one of the loadouts is malformed.

⚠️ **GitHub.com Fallback** ⚠️