Implement some missing JSON serialization routines

This commit is contained in:
Zahary Karadjov 2018-12-19 12:56:22 +02:00
parent 5693e706dc
commit 0c2b891096
1 changed files with 14 additions and 3 deletions

View File

@ -5,9 +5,15 @@ import
proc writeValue*(w: var JsonWriter, a: MDigest) {.inline.} =
w.writeValue $a
proc writeValue*(w: var JsonWriter, value: StUint) =
proc readValue*(r: var JsonReader, a: var MDigest) {.inline.} =
a = fromHex(type(a), r.readValue(string))
proc writeValue*(w: var JsonWriter, value: StUint) {.inline.} =
w.writeValue $value
proc readValue*(r: var JsonReader, value: var StUint) {.inline.} =
value = parse(r.readValue(string), type(value))
proc writeValue*(w: var JsonWriter, value: Stint) =
# The Ethereum Yellow Paper defines the RLP serialization only
# for unsigned integers:
@ -17,10 +23,15 @@ proc writeValue*(w: var JsonWriter, value: Stint) =
proc writeValue*(w: var JsonWriter, t: Time) {.inline.} =
w.writeValue t.toUnix()
proc readValue*(r: var JsonReader, t: var Time) {.inline.} =
t = fromUnix r.readValue(int)
# TODO: remove this once case object are fully supported
# by the serialization library
proc writeValue*(w: var JsonWriter, value: HashOrNum) =
w.beginRecord(HashOrNum)
case value.isHash
of true:
w.writeField("isHash", value.isHash)
if value.isHash:
w.writeField("hash", value.hash)
else:
w.writeField("number", value.number)