For some time now I've been trying to get a little message bus running using
FutureStreams. It works when the messages are strings. Full code at
<https://gist.github.com/ingoogni/b29fde37f74216e57abf7ed7812d2a52>
Now I would like to get it working with different message types/kinds. The
following works in one direction.
type
MsgKind = enum
mkString,
mkInt,
mkFloat
Message* = object
topic*: string
id*: string
msgtype*: string #"p/s", "req/rep", "reply". req/rep requires id
case msg*: MsgKind
of mkString: strVal: string
of mkInt: intVal: int
of mkFloat: floatVal: float
[...]
proc post*(topic:string, msg:string|int|float, id:string = "",
msgtype:string = "p/s"){.async.}=
var message = Message(
topic: topic,
msg: cast[MsgKind](msg),
id: id,
msgType: msgType
)
echo type(message.msg) #---> this only tells me MsgKind, not what kind it
originally was.
await bus.fsBus.write(message)
Run
But how do I go the other way, from `MsgKind` back to for example `int`?
(I also tried it with the big `T`, but failed. There it is the `var bus*` that
gives me problems)