Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 977ec25e79 |
@@ -27,6 +27,29 @@ extension IPAddressRange: Hashable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
extension IPAddressRange {
|
||||||
public var stringRepresentation: String {
|
public var stringRepresentation: String {
|
||||||
return "\(address)/\(networkPrefixLength)"
|
return "\(address)/\(networkPrefixLength)"
|
||||||
|
|||||||
Reference in New Issue
Block a user