mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-28 15:46:33 +00:00
18 lines
446 B
Nim
18 lines
446 B
Nim
|
import std/options, ../../json_serialization/[reader, writer, lexer]
|
||
|
export options
|
||
|
|
||
|
proc writeValue*(writer: var JsonWriter, value: Option) =
|
||
|
if value.isSome:
|
||
|
writer.writeValue value.get
|
||
|
else:
|
||
|
writer.writeValue JsonString("null")
|
||
|
|
||
|
proc readValue*[T](reader: var JsonReader, value: var Option[T]) =
|
||
|
let tok = reader.lexer.tok
|
||
|
if tok == tkNull:
|
||
|
reset value
|
||
|
reader.lexer.next()
|
||
|
else:
|
||
|
value = some reader.readValue(T)
|
||
|
|