-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputSource.swift
More file actions
31 lines (25 loc) · 1.04 KB
/
InputSource.swift
File metadata and controls
31 lines (25 loc) · 1.04 KB
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
/// https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/data/input/InputSource.java#L61
public indirect enum InputSource: Codable, Hashable, Equatable, Sendable {
case druid(DruidInputSource)
enum CodingKeys: String, CodingKey {
case type
}
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let type = try values.decode(String.self, forKey: .type)
switch type {
case "druid":
self = try .druid(DruidInputSource(from: decoder))
default:
throw EncodingError.invalidValue("Invalid type", .init(codingPath: [CodingKeys.type], debugDescription: "Invalid Type", underlyingError: nil))
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case let .druid(spec):
try container.encode("druid", forKey: .type)
try spec.encode(to: encoder)
}
}
}