2024-06-28 10:34:57 +00:00
|
|
|
{.push raises: [].}
|
2022-11-03 16:58:48 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
import stew/shims/macros, serialization
|
|
|
|
import ./envvar_serialization/reader, ./envvar_serialization/writer
|
2022-11-03 16:58:48 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
export serialization, reader, writer
|
2022-11-03 16:58:48 +00:00
|
|
|
|
|
|
|
serializationFormat Envvar
|
|
|
|
|
|
|
|
Envvar.setReader EnvvarReader
|
|
|
|
Envvar.setWriter EnvvarWriter, PreferredOutput = void
|
|
|
|
|
|
|
|
template supports*(_: type Envvar, T: type): bool =
|
|
|
|
# The Envvar format should support every type
|
|
|
|
true
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
template decode*(
|
|
|
|
_: type Envvar, prefix: string, RecordType: distinct type, params: varargs[untyped]
|
|
|
|
): auto =
|
2022-11-03 16:58:48 +00:00
|
|
|
mixin init, ReaderType
|
|
|
|
|
|
|
|
{.noSideEffect.}:
|
|
|
|
var reader = unpackArgs(init, [EnvvarReader, prefix, params])
|
|
|
|
reader.readValue(RecordType)
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
template encode*(
|
|
|
|
_: type Envvar, prefix: string, value: auto, params: varargs[untyped]
|
|
|
|
) =
|
2022-11-03 16:58:48 +00:00
|
|
|
mixin init, WriterType, writeValue
|
|
|
|
|
|
|
|
{.noSideEffect.}:
|
|
|
|
var writer = unpackArgs(init, [EnvvarWriter, prefix, params])
|
|
|
|
writeValue writer, value
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
template loadFile*(
|
|
|
|
_: type Envvar, prefix: string, RecordType: distinct type, params: varargs[untyped]
|
|
|
|
): auto =
|
2022-11-03 16:58:48 +00:00
|
|
|
mixin init, ReaderType, readValue
|
|
|
|
|
|
|
|
var reader = unpackArgs(init, [EnvvarReader, prefix, params])
|
|
|
|
reader.readValue(RecordType)
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
template saveFile*(
|
|
|
|
_: type Envvar, prefix: string, value: auto, params: varargs[untyped]
|
|
|
|
) =
|
2022-11-03 16:58:48 +00:00
|
|
|
mixin init, WriterType, writeValue
|
|
|
|
|
|
|
|
var writer = unpackArgs(init, [EnvvarWriter, prefix, params])
|
|
|
|
writer.writeValue(value)
|