1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
/// Represents system package providers.
public enum SystemPackageProviderDescription: Hashable, Codable, Sendable {
case brew([String])
case apt([String])
case yum([String])
case nuget([String])
}
extension SystemPackageProviderDescription {
private enum CodingKeys: String, CodingKey {
case brew, apt, yum, nuget
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case let .brew(a1):
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .brew)
try unkeyedContainer.encode(a1)
case let .apt(a1):
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .apt)
try unkeyedContainer.encode(a1)
case let .yum(a1):
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .yum)
try unkeyedContainer.encode(a1)
case let .nuget(a1):
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .nuget)
try unkeyedContainer.encode(a1)
}
}
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
guard let key = values.allKeys.first(where: values.contains) else {
throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Did not find a matching key"))
}
switch key {
case .brew:
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
let a1 = try unkeyedValues.decode([String].self)
self = .brew(a1)
case .apt:
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
let a1 = try unkeyedValues.decode([String].self)
self = .apt(a1)
case .yum:
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
let a1 = try unkeyedValues.decode([String].self)
self = .yum(a1)
case .nuget:
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
let a1 = try unkeyedValues.decode([String].self)
self = .nuget(a1)
}
}
}
|