2023-12-13 09:07:57 +00:00
|
|
|
# json-serialization
|
2024-01-27 08:38:33 +00:00
|
|
|
# Copyright (c) 2019-2024 Status Research & Development GmbH
|
2023-12-13 09:07:57 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
2019-08-12 14:53:04 +00:00
|
|
|
import
|
2024-01-27 09:27:05 +00:00
|
|
|
std/[net, strutils],
|
|
|
|
chronos/transports/common,
|
|
|
|
../../json_serialization
|
2019-08-12 14:53:04 +00:00
|
|
|
|
|
|
|
export
|
|
|
|
net, common
|
2019-06-20 12:35:17 +00:00
|
|
|
|
2023-08-19 11:47:32 +00:00
|
|
|
proc writeValue*(
|
|
|
|
writer: var JsonWriter, value: IpAddress) {.raises: [IOError].} =
|
2020-06-05 14:06:48 +00:00
|
|
|
writeValue(writer, $value)
|
|
|
|
|
|
|
|
proc readValue*(reader: var JsonReader, value: var IpAddress) =
|
|
|
|
let s = reader.readValue(string)
|
|
|
|
try:
|
|
|
|
value = parseIpAddress s
|
|
|
|
except CatchableError:
|
|
|
|
raiseUnexpectedValue(reader, "Invalid IP address")
|
|
|
|
|
2023-08-19 11:47:32 +00:00
|
|
|
proc writeValue*(
|
|
|
|
writer: var JsonWriter, value: Port) {.raises: [IOError].} =
|
2019-06-20 12:35:17 +00:00
|
|
|
writeValue(writer, uint16 value)
|
|
|
|
|
|
|
|
proc readValue*(reader: var JsonReader, value: var Port) =
|
|
|
|
value = Port reader.readValue(uint16)
|
|
|
|
|
2023-08-19 11:47:32 +00:00
|
|
|
proc writeValue*(
|
|
|
|
writer: var JsonWriter, value: AddressFamily) {.raises: [IOError].} =
|
2019-08-12 14:53:04 +00:00
|
|
|
writeValue(writer, $value)
|
|
|
|
|
|
|
|
proc readValue*(reader: var JsonReader, value: var AddressFamily) =
|
|
|
|
value = parseEnum[AddressFamily](reader.readValue(string))
|