syndicated-open/src/protocol.nim

40 lines
1021 B
Nim

import
std/typetraits, preserves
type
XdgOpen* {.preservesRecord: "xdg-open".} = object
`uris`*: seq[string]
UriRunnerConfigKind* {.pure.} = enum
`ListenOn`, `ActionHandler`
`UriRunnerConfig`*[E] {.preservesOr.} = ref object
case orKind*: UriRunnerConfigKind
of UriRunnerConfigKind.`ListenOn`:
`listenon`*: ListenOn[E]
of UriRunnerConfigKind.`ActionHandler`:
`actionhandler`*: ActionHandler[E]
ListenOn*[E] {.preservesRecord: "listen-on".} = ref object
`dataspace`*: Preserve[E]
ActionHandler*[E] {.preservesRecord: "action-handler".} = ref object
`pat`*: string
`action`*: Preserve[E]
`entity`*: Preserve[E]
proc `$`*[E](x: UriRunnerConfig[E] | ListenOn[E] | ActionHandler[E]): string =
`$`(toPreserve(x, E))
proc encode*[E](x: UriRunnerConfig[E] | ListenOn[E] | ActionHandler[E]): seq[
byte] =
encode(toPreserve(x, E))
proc `$`*(x: XdgOpen): string =
`$`(toPreserve(x))
proc encode*(x: XdgOpen): seq[byte] =
encode(toPreserve(x))