-
Notifications
You must be signed in to change notification settings - Fork 104
/
DataBox.swift
56 lines (45 loc) · 1 KB
/
DataBox.swift
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
//
// DataBox.swift
// XMLCoder
//
// Created by Vincent Esche on 12/19/18.
//
import Foundation
struct DataBox: Equatable {
enum Format: Equatable {
case base64
}
typealias Unboxed = Data
let unboxed: Unboxed
let format: Format
init(_ unboxed: Unboxed, format: Format) {
self.unboxed = unboxed
self.format = format
}
init?(base64 string: String) {
guard let data = Data(base64Encoded: string) else {
return nil
}
self.init(data, format: .base64)
}
func xmlString(format: Format) -> String {
switch format {
case .base64:
return unboxed.base64EncodedString()
}
}
}
extension DataBox: Box {
var isNull: Bool {
return false
}
func xmlString() -> String? {
return xmlString(format: format)
}
}
extension DataBox: SimpleBox {}
extension DataBox: CustomStringConvertible {
var description: String {
return unboxed.description
}
}