Move EndpointProtocol Codable to Core spec

This commit is contained in:
Davide De Rosa 2019-04-05 00:45:25 +02:00
parent ed6c3b6113
commit 3717136bd9
2 changed files with 16 additions and 16 deletions

View File

@ -576,22 +576,6 @@ extension TunnelKitProvider.Configuration {
}
}
/// :nodoc:
extension EndpointProtocol: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
guard let proto = try EndpointProtocol(rawValue: container.decode(String.self)) else {
throw TunnelKitProvider.ProviderConfigurationError.parameter(name: "endpointProtocol.decodable")
}
self.init(proto.socketType, proto.port)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
}
/// :nodoc:
public extension UserDefaults {
@objc var dataCountArray: [Int]? {

View File

@ -480,3 +480,19 @@ public struct IPv6Settings: Codable, CustomStringConvertible {
return "addr \(address.maskedDescription)/\(addressPrefixLength) gw \(defaultGateway.maskedDescription) routes \(routes.map { $0.maskedDescription })"
}
}
/// :nodoc:
extension EndpointProtocol: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
guard let proto = try EndpointProtocol(rawValue: container.decode(String.self)) else {
throw ConfigurationError.malformed(option: "remote/proto")
}
self.init(proto.socketType, proto.port)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
}