logos-messaging-go-bindings/tools/confutils/envvar_serialization.nim
Ivan Folgueira Bande 2f6de9187f Squashed 'third-party/nwaku/' content from commit d94cb7c7
git-subtree-dir: third-party/nwaku
git-subtree-split: d94cb7c73631ffd4b934839ba58bc622d331a135
2025-10-02 11:52:12 +02:00

50 lines
1.3 KiB
Nim

{.push raises: [].}
import stew/shims/macros, serialization
import ./envvar_serialization/reader, ./envvar_serialization/writer
export serialization, reader, writer
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
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)
template saveFile*(
_: type Envvar, prefix: string, value: auto, params: varargs[untyped]
) =
mixin init, WriterType, writeValue
var writer = unpackArgs(init, [EnvvarWriter, prefix, params])
writer.writeValue(value)