Skip to content

IConfigSerializer

interface IConfigSerializer

Reads and writes a ConfigSpec to/from a specific file format (JSON, JSON5, TOML, ...). Built-in implementations live in net.kernelpanicsoft.archie.config.serializer; ConfigSpec.fileSerializer picks one per-platform by default.

configPath, load, and save all take a configFolder that defaults to the platform's shared config folder (Platform.getConfigFolder); ConfigSpec passes its own ConfigSpec.configFolder instead, which a ConfigSpec.Server repoints at the current world's per-save serverconfig/ folder.

Inheritors

Types

SerializationException

Thrown when writing a config file fails (e.g. an I/O error).

Functions

configPath

abstract fun configPath(config: ConfigSpec, configFolder: Path = Platform.getConfigFolder()): Path

File the given config is read from and written to, resolved under configFolder.

load

open fun load(config: ConfigSpec, configFolder: Path = Platform.getConfigFolder())

Reads config's file if present via loadString, then always saves it back out - this both formats a freshly-created file with defaults and rewrites an existing one with any newly-added fields. If the existing file fails to parse, it's logged and renamed to <file>.corrupted rather than deleted, and loading falls through to writing fresh defaults so startup isn't blocked.

loadString

abstract fun loadString(config: ConfigSpec, string: String)

Parses string and populates config's fields from it. Implemented per-format.

save

open fun save(config: ConfigSpec, configFolder: Path = Platform.getConfigFolder())

Writes config's current field values to configPath, creating parent directories as needed.

saveString

abstract fun saveString(config: ConfigSpec): String

Renders config's current field values as a file-format string. Implemented per-format.