}
}
+extension IPAddressRange: Codable {
+ public func encode(to encoder: Encoder) throws {
+ var container = encoder.singleValueContainer()
+
+ try container.encode(self.stringRepresentation)
+ }
+
+ public init(from decoder: Decoder) throws {
+ let container = try decoder.singleValueContainer()
+ let value = try container.decode(String.self)
+
+ if let ipAddressRange = IPAddressRange(from: value) {
+ self = ipAddressRange
+ } else {
+ let context = DecodingError.Context(
+ codingPath: container.codingPath,
+ debugDescription: "Invalid IPAddressRange representation"
+ )
+ throw DecodingError.dataCorrupted(context)
+ }
+ }
+}
+
extension IPAddressRange {
public var stringRepresentation: String {
return "\(address)/\(networkPrefixLength)"