Fixes for interop (#4)
This commit is contained in:
parent
9fba811117
commit
c282ff68c0
|
@ -64,7 +64,7 @@ type
|
||||||
topic: string
|
topic: string
|
||||||
event {.serializedFieldName: "payload".}: Option[Event]
|
event {.serializedFieldName: "payload".}: Option[Event]
|
||||||
networkConf {.serializedFieldName: "payload".}: Option[NetworkConf]
|
networkConf {.serializedFieldName: "payload".}: Option[NetworkConf]
|
||||||
payload: Option[string]
|
payload: Option[JsonNode]
|
||||||
|
|
||||||
Event* = object
|
Event* = object
|
||||||
#workaround https://github.com/status-im/nim-json-serialization/pull/50
|
#workaround https://github.com/status-im/nim-json-serialization/pull/50
|
||||||
|
@ -207,13 +207,13 @@ proc subscribe*[T](c: Client, topic: string, _: type[T]): AsyncQueue[T] =
|
||||||
while true:
|
while true:
|
||||||
let elem = await theQueue.popFirst()
|
let elem = await theQueue.popFirst()
|
||||||
|
|
||||||
let decoded = json_serialization.decode(Json, unescape(elem), T, allowUnknownFields = true)
|
let decoded = json_serialization.decode(Json, elem, T, allowUnknownFields = true)
|
||||||
resQueue.addLastNoWait(decoded)
|
resQueue.addLastNoWait(decoded)
|
||||||
|
|
||||||
asyncSpawn getter()
|
asyncSpawn getter()
|
||||||
resQueue
|
resQueue
|
||||||
|
|
||||||
proc publish*(c: Client, topic: string, content: string) {.async.} =
|
proc publish*(c: Client, topic: string, content: JsonNode) {.async.} =
|
||||||
## Publish `content` to `topic`
|
## Publish `content` to `topic`
|
||||||
let r = await c.request(Request(
|
let r = await c.request(Request(
|
||||||
publish: some PublishRequest(
|
publish: some PublishRequest(
|
||||||
|
@ -224,7 +224,8 @@ proc publish*(c: Client, topic: string, content: string) {.async.} =
|
||||||
|
|
||||||
proc publish*[T](c: Client, topic: string, content: T) {.async.} =
|
proc publish*[T](c: Client, topic: string, content: T) {.async.} =
|
||||||
mixin toJson
|
mixin toJson
|
||||||
await c.publish(topic, content.toJson())
|
let asJsonNode = json_serialization.decode(Json, content.toJson(), JsonNode)
|
||||||
|
await c.publish(topic, asJsonNode)
|
||||||
|
|
||||||
proc param*[T](c: Client, _: type[T], name: string): T =
|
proc param*[T](c: Client, _: type[T], name: string): T =
|
||||||
let params = getEnv("TEST_INSTANCE_PARAMS").split("|").mapIt(it.split("=", 2)).mapIt((it[0], it[1])).toTable()
|
let params = getEnv("TEST_INSTANCE_PARAMS").split("|").mapIt(it.split("=", 2)).mapIt((it[0], it[1])).toTable()
|
||||||
|
|
Loading…
Reference in New Issue