2020-10-22 07:18:08 +00:00
|
|
|
import
|
|
|
|
stew/shims/macros,
|
2020-10-31 10:44:03 +00:00
|
|
|
serialization, ./reader, ./writer
|
2020-10-22 07:18:08 +00:00
|
|
|
|
|
|
|
export
|
2020-10-31 10:44:03 +00:00
|
|
|
serialization, reader, writer
|
2020-10-22 07:18:08 +00:00
|
|
|
|
2021-03-19 02:01:44 +00:00
|
|
|
serializationFormat Envvar
|
|
|
|
|
|
|
|
Envvar.setReader EnvvarReader
|
|
|
|
Envvar.setWriter EnvvarWriter, PreferredOutput = void
|
2020-10-22 07:18:08 +00:00
|
|
|
|
|
|
|
template supports*(_: type Envvar, T: type): bool =
|
|
|
|
# The Envvar format should support every type
|
|
|
|
true
|
|
|
|
|
|
|
|
template decode*(_: type Envvar,
|
|
|
|
prefix: string,
|
|
|
|
RecordType: distinct type,
|
|
|
|
params: varargs[untyped]): auto =
|
|
|
|
mixin init, ReaderType
|
|
|
|
|
|
|
|
{.noSideEffect.}:
|
|
|
|
var reader = unpackArgs(init, [EnvvarReader, prefix, params])
|
|
|
|
reader.readValue(RecordType)
|
|
|
|
|
|
|
|
template encode*(_: type Envvar,
|
|
|
|
prefix: string,
|
|
|
|
value: auto,
|
|
|
|
params: varargs[untyped]) =
|
|
|
|
mixin init, WriterType, writeValue
|
|
|
|
|
|
|
|
{.noSideEffect.}:
|
|
|
|
var writer = unpackArgs(init, [EnvvarWriter, prefix, params])
|
|
|
|
writeValue writer, value
|
|
|
|
|
|
|
|
template loadFile*(_: type Envvar,
|
|
|
|
prefix: string,
|
|
|
|
RecordType: distinct type,
|
|
|
|
params: varargs[untyped]): auto =
|
|
|
|
mixin init, ReaderType, readValue
|
|
|
|
|
|
|
|
var reader = unpackArgs(init, [EnvvarReader, prefix, params])
|
|
|
|
reader.readValue(RecordType)
|
|
|
|
|
2020-10-28 09:17:22 +00:00
|
|
|
template saveFile*(_: type Envvar, prefix: string, value: auto, params: varargs[untyped]) =
|
2020-10-22 07:18:08 +00:00
|
|
|
mixin init, WriterType, writeValue
|
|
|
|
|
|
|
|
var writer = unpackArgs(init, [EnvvarWriter, prefix, params])
|
|
|
|
writer.writeValue(value)
|