2023-05-12 16:08:41 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
std/json
|
|
|
|
import
|
2023-08-09 17:11:50 +00:00
|
|
|
../../waku/waku_core/message/message,
|
2023-07-07 08:53:00 +00:00
|
|
|
./json_base_event
|
2023-05-12 16:08:41 +00:00
|
|
|
|
|
|
|
type JsonMessage = ref object
|
|
|
|
# https://rfc.vac.dev/spec/36/#jsonmessage-type
|
|
|
|
payload: string
|
|
|
|
contentTopic: string
|
|
|
|
version: uint
|
|
|
|
timestamp: int64
|
|
|
|
|
2023-07-07 08:53:00 +00:00
|
|
|
type JsonMessageEvent* = ref object of JsonEvent
|
2023-05-12 16:08:41 +00:00
|
|
|
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 )
|