`Message.msg` is the enum `MsgKind`, but `msg` for the proc is string, int or
float. Those types aren't compatible.
You want something like this
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") =
var message =
when msg is string:
Message(
topic: topic,
msg: mkString,
strVar: msg,
id: id,
msgType: msgType
)
elif msg is int:
Message(
topic: topic,
msg: mkInt,
intVal: msg,
id: id,
msgType: msgType
)
elif msg is float:
Message(
topic: topic,
msg: mkString,
floatVal: msg,
id: id,
msgType: msgType
)
Run
Do you need to know the different msg types and do something with that
knowledge? If not, You can do something like this
type
Message*[T] = object
topic*: string
id*: string
msgtype*: string #"p/s", "req/rep", "reply". req/rep requires id
msg*: T
proc post*[T](topic:string, msg: T, id:string = "", msgtype:string = "p/s")
=
var message = Message[T](
topic: topic,
msg: msg,
id: id,
msgType: msgType
)
Run