Support for tuples

This commit is contained in:
Zahary Karadjov 2019-08-12 17:53:04 +03:00 committed by Zahary Karadjov
parent a0607c6375
commit f4bd22e054
2 changed files with 17 additions and 3 deletions

View File

@ -221,7 +221,11 @@ proc readValue*(r: var JsonReader, value: var auto) =
let fields = T.fieldReadersTable(JsonReader)
var expectedFieldPos = 0
while r.lexer.tok == tkString:
let reader = findFieldReader(fields[], r.lexer.strVal, expectedFieldPos)
when T is tuple:
var reader = fields[][expectedFieldPos].reader
expectedFieldPos += 1
else:
var reader = findFieldReader(fields[], r.lexer.strVal, expectedFieldPos)
r.lexer.next()
r.skipToken tkColon
if reader != nil:

View File

@ -1,5 +1,9 @@
import std/net, ../../json_serialization.nim
export net
import
std/[net, strutils],
../../json_serialization, chronos/transports/common
export
net, common
proc writeValue*(writer: var JsonWriter, value: Port) =
writeValue(writer, uint16 value)
@ -7,3 +11,9 @@ proc writeValue*(writer: var JsonWriter, value: Port) =
proc readValue*(reader: var JsonReader, value: var Port) =
value = Port reader.readValue(uint16)
proc writeValue*(writer: var JsonWriter, value: AddressFamily) =
writeValue(writer, $value)
proc readValue*(reader: var JsonReader, value: var AddressFamily) =
value = parseEnum[AddressFamily](reader.readValue(string))