Skip to content

Commit 34de4a9

Browse files
committed
Favor enums rather than structs holding enums
1 parent 440593f commit 34de4a9

File tree

1 file changed

+31
-64
lines changed

1 file changed

+31
-64
lines changed

mambaSharedFramework/HLSValueTypes.swift

+31-64
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,18 @@ public func ==(lhs: HLSEncryptionMethodType, rhs: HLSEncryptionMethodType) -> Bo
132132
}
133133

134134
/// Represents a minimum required HDCP level needed to play content.
135-
public struct HLSHDCPLevel: Equatable, FailableStringLiteralConvertible {
136-
public let type: HDCPLevel
137-
public enum HDCPLevel: String {
138-
/// Indicates that the content does not require output copy protections.
139-
case none = "NONE"
140-
/// Indicates that the Variant Stream could fail to play unless the output is protected by High-bandwidth
141-
/// Digital Content Protection (HDCP) Type 0 or equivalent.
142-
case type0 = "TYPE-0"
143-
/// Indicates that the Variant Stream could fail to play unless the output is protected by HDCP Type 1 or
144-
/// equivalent.
145-
case type1 = "TYPE-1"
146-
}
135+
public enum HLSHDCPLevel: String, Equatable, FailableStringLiteralConvertible {
136+
/// Indicates that the content does not require output copy protections.
137+
case none = "NONE"
138+
/// Indicates that the Variant Stream could fail to play unless the output is protected by High-bandwidth Digital
139+
/// Content Protection (HDCP) Type 0 or equivalent.
140+
case type0 = "TYPE-0"
141+
/// Indicates that the Variant Stream could fail to play unless the output is protected by HDCP Type 1 or
142+
/// equivalent.
143+
case type1 = "TYPE-1"
144+
147145
public init?(string: String) {
148-
self.init(hdcpLevel: string)
149-
}
150-
public init?(hdcpLevel: String) {
151-
guard let type = HDCPLevel(rawValue: hdcpLevel) else {
152-
return nil
153-
}
154-
self.type = type
155-
}
156-
public init(hdcpLevel: HDCPLevel) {
157-
self.type = hdcpLevel
146+
self.init(rawValue: string)
158147
}
159148
}
160149

@@ -166,54 +155,32 @@ public struct HLSHDCPLevel: Equatable, FailableStringLiteralConvertible {
166155
/// For example, `SDR` covers TransferCharacteristics code points 1, 6, 13, 14 and 15. More information on what each
167156
/// code point represents can be found in _"Information technology - MPEG systems technologies - Part 8: Coding-_
168157
/// _independent code points" ISO/IEC International Standard 23001-8, 2016_ [CICP].
169-
public struct HLSVideoRange: Equatable, FailableStringLiteralConvertible {
170-
public let type: VideoRange
171-
public enum VideoRange: String {
172-
/// The value MUST be SDR if the video in the Variant Stream is encoded using one of the following reference
173-
/// opto-electronic transfer characteristic functions specified by the TransferCharacteristics code point: 1, 6,
174-
/// 13, 14, 15. Note that different TransferCharacteristics code points can use the same transfer function.
175-
case sdr = "SDR"
176-
/// The value MUST be HLG if the video in the Variant Stream is encoded using a reference opto-electronic
177-
/// transfer characteristic function specified by the TransferCharacteristics code point 18, or consists of such
178-
/// video mixed with video qualifying as SDR.
179-
case hlg = "HLG"
180-
/// The value MUST be PQ if the video in the Variant Stream is encoded using a reference opto-electronic
181-
/// transfer characteristic function specified by the TransferCharacteristics code point 16, or consists of such
182-
/// video mixed with video qualifying as SDR or HLG.
183-
case pq = "PQ"
184-
}
158+
public enum HLSVideoRange: String, Equatable, FailableStringLiteralConvertible {
159+
/// The value MUST be SDR if the video in the Variant Stream is encoded using one of the following reference
160+
/// opto-electronic transfer characteristic functions specified by the TransferCharacteristics code point: 1, 6, 13,
161+
/// 14, 15. Note that different TransferCharacteristics code points can use the same transfer function.
162+
case sdr = "SDR"
163+
/// The value MUST be HLG if the video in the Variant Stream is encoded using a reference opto-electronic transfer
164+
/// characteristic function specified by the TransferCharacteristics code point 18, or consists of such video mixed
165+
/// with video qualifying as SDR.
166+
case hlg = "HLG"
167+
/// The value MUST be PQ if the video in the Variant Stream is encoded using a reference opto-electronic transfer
168+
/// characteristic function specified by the TransferCharacteristics code point 16, or consists of such video mixed
169+
/// with video qualifying as SDR or HLG.
170+
case pq = "PQ"
171+
185172
public init?(string: String) {
186-
self.init(videoRange: string)
187-
}
188-
public init?(videoRange: String) {
189-
guard let type = VideoRange(rawValue: videoRange) else {
190-
return nil
191-
}
192-
self.type = type
193-
}
194-
public init(videoRange: VideoRange) {
195-
self.type = videoRange
173+
self.init(rawValue: string)
196174
}
197175
}
198176

199177
/// Represents the format of the file referenced by `EXT-X-SESSION-DATA:URI`.
200-
public struct HLSSessionDataFormat: Equatable, FailableStringLiteralConvertible {
201-
public let type: Format
202-
public enum Format: String {
203-
case json = "JSON"
204-
case raw = "RAW"
205-
}
178+
public enum HLSSessionDataFormat: String, Equatable, FailableStringLiteralConvertible {
179+
case json = "JSON"
180+
case raw = "RAW"
181+
206182
public init?(string: String) {
207-
self.init(format: string)
208-
}
209-
public init?(format: String) {
210-
guard let type = Format(rawValue: format) else {
211-
return nil
212-
}
213-
self.type = type
214-
}
215-
public init(format: Format) {
216-
self.type = format
183+
self.init(rawValue: string)
217184
}
218185
}
219186

0 commit comments

Comments
 (0)