mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-28 23:55:43 +00:00
2defbd2301
* feat(cbindings): first commit - waku relay (#1632) * test_app.nim: fix compilation issue. App.init(..) -> App.new(..) * Simplifying library name (libwaku) and standardizing function names (waku_*) * Proper wrapper of the waku_node API and creation of the libwaku.a * Rolling back changes that are not needed * Rolling back changes that are out of the scope of this task * wakunode.nim: Removing unnecessary import * Aplying PR suggestions * Renaming 'waku.h' -> 'libwaku.h' * Use of 'isNil' instead of '== nil' * libwaku.nim: explicitly setting waku_poll() as gcsafe
43 lines
1.0 KiB
Nim
43 lines
1.0 KiB
Nim
|
|
import
|
|
std/json
|
|
import
|
|
../../waku/v2/waku_core/message/message,
|
|
json_signal_event
|
|
|
|
type JsonMessage = ref object
|
|
# https://rfc.vac.dev/spec/36/#jsonmessage-type
|
|
payload: string
|
|
contentTopic: string
|
|
version: uint
|
|
timestamp: int64
|
|
|
|
type JsonMessageEvent* = ref object of JsonSignal
|
|
pubsubTopic*: string
|
|
messageId*: string
|
|
wakuMessage*: JsonMessage
|
|
|
|
proc new*(T: type JsonMessageEvent,
|
|
pubSubTopic: string,
|
|
msg: WakuMessage): T =
|
|
# Returns a WakuMessage event as indicated in
|
|
# https://rfc.vac.dev/spec/36/#jsonmessageevent-type
|
|
|
|
var payload = newString(len(msg.payload))
|
|
copyMem(addr payload[0], unsafeAddr msg.payload[0], len(msg.payload))
|
|
|
|
return JsonMessageEvent(
|
|
eventType: "message",
|
|
pubSubTopic: pubSubTopic,
|
|
messageId: "TODO",
|
|
wakuMessage: JsonMessage(
|
|
payload: payload,
|
|
contentTopic: msg.contentTopic,
|
|
version: msg.version,
|
|
timestamp: int64(msg.timestamp)
|
|
)
|
|
)
|
|
|
|
method `$`*(jsonMessage: JsonMessageEvent): string =
|
|
$( %* jsonMessage )
|