-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathNSCoder.swift
265 lines (209 loc) · 8.14 KB
/
NSCoder.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 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
//
public protocol NSCoding {
func encodeWithCoder(aCoder: NSCoder)
init?(coder aDecoder: NSCoder)
}
public protocol NSSecureCoding : NSCoding {
static func supportsSecureCoding() -> Bool
}
public class NSCoder : NSObject {
internal var _pendingBuffers = Array<(UnsafeMutablePointer<Void>, Int)>()
deinit {
for buffer in _pendingBuffers {
buffer.0.destroy()
buffer.0.dealloc(buffer.1)
}
}
public func encodeValueOfObjCType(type: UnsafePointer<Int8>, at addr: UnsafePointer<Void>) {
NSRequiresConcreteImplementation()
}
public func encodeDataObject(data: NSData) {
NSRequiresConcreteImplementation()
}
public func decodeValueOfObjCType(type: UnsafePointer<Int8>, at data: UnsafeMutablePointer<Void>) {
NSRequiresConcreteImplementation()
}
public func decodeDataObject() -> NSData? {
NSRequiresConcreteImplementation()
}
public func versionForClassName(className: String) -> Int {
NSRequiresConcreteImplementation()
}
@warn_unused_result
public func decodeObjectOfClass<DecodedObjectType : NSCoding where DecodedObjectType : NSObject>(cls: DecodedObjectType.Type, forKey key: String) -> DecodedObjectType? {
NSUnimplemented()
}
@warn_unused_result
public func decodeObjectOfClasses(classes: NSSet?, forKey key: String) -> AnyObject? {
NSUnimplemented()
}
@warn_unused_result
public func decodeTopLevelObject() throws -> AnyObject? {
NSUnimplemented()
}
@warn_unused_result
public func decodeTopLevelObjectForKey(key: String) throws -> AnyObject? {
NSUnimplemented()
}
@warn_unused_result
public func decodeTopLevelObjectOfClass<DecodedObjectType : NSCoding where DecodedObjectType : NSObject>(cls: DecodedObjectType.Type, forKey key: String) throws -> DecodedObjectType? {
NSUnimplemented()
}
@warn_unused_result
public func decodeTopLevelObjectOfClasses(classes: NSSet?, forKey key: String) throws -> AnyObject? {
NSUnimplemented()
}
internal var error: NSError? {
return nil
}
public func encodeObject(object: AnyObject?) {
var object = object
withUnsafePointer(&object) { (ptr: UnsafePointer<AnyObject?>) -> Void in
encodeValueOfObjCType("@", at: unsafeBitCast(ptr, UnsafePointer<Void>.self))
}
}
public func encodeRootObject(rootObject: AnyObject) {
encodeObject(rootObject)
}
public func encodeBycopyObject(anObject: AnyObject?) {
encodeObject(anObject)
}
public func encodeByrefObject(anObject: AnyObject?) {
encodeObject(anObject)
}
public func encodeConditionalObject(object: AnyObject?) {
encodeObject(object)
}
public func encodeArrayOfObjCType(type: UnsafePointer<Int8>, count: Int, at array: UnsafePointer<Void>) {
encodeValueOfObjCType("[\(count)\(String.fromCString(type)!)]", at: array)
}
public func encodeBytes(byteaddr: UnsafePointer<Void>, length: Int) {
var newLength = UInt32(length)
withUnsafePointer(&newLength) { (ptr: UnsafePointer<UInt32>) -> Void in
encodeValueOfObjCType("I", at: ptr)
}
encodeArrayOfObjCType("c", count: length, at: byteaddr)
}
public func decodeObject() -> AnyObject? {
if self.error != nil {
return nil
}
var obj: AnyObject? = nil
withUnsafeMutablePointer(&obj) { (ptr: UnsafeMutablePointer<AnyObject?>) -> Void in
decodeValueOfObjCType("@", at: unsafeBitCast(ptr, UnsafeMutablePointer<Void>.self))
}
return obj
}
public func decodeArrayOfObjCType(itemType: UnsafePointer<Int8>, count: Int, at array: UnsafeMutablePointer<Void>) {
decodeValueOfObjCType("[\(count)\(String.fromCString(itemType)!)]", at: array)
}
public func decodeBytesWithReturnedLength(lengthp: UnsafeMutablePointer<Int>) -> UnsafeMutablePointer<Void> {
var length: UInt32 = 0
withUnsafeMutablePointer(&length) { (ptr: UnsafeMutablePointer<UInt32>) -> Void in
decodeValueOfObjCType("I", at: unsafeBitCast(ptr, UnsafeMutablePointer<Void>.self))
}
// we cannot autorelease here so instead the pending buffers will manage the lifespan of the returned data... this is wasteful but good enough...
let result = UnsafeMutablePointer<Void>.alloc(Int(length))
decodeValueOfObjCType("c", at: result)
lengthp.memory = Int(length)
_pendingBuffers.append((result, Int(length)))
return result
}
public func encodePropertyList(aPropertyList: AnyObject) {
NSUnimplemented()
}
public func decodePropertyList() -> AnyObject? {
NSUnimplemented()
}
public var systemVersion: UInt32 {
return 1000
}
public var allowsKeyedCoding: Bool {
get {
return false
}
}
public func encodeObject(objv: AnyObject?, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func encodeConditionalObject(objv: AnyObject?, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func encodeBool(boolv: Bool, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func encodeInt(intv: Int32, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func encodeInt32(intv: Int32, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func encodeInt64(intv: Int64, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func encodeFloat(realv: Float, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func encodeDouble(realv: Double, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func encodeBytes(bytesp: UnsafePointer<UInt8>, length lenv: Int, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func containsValueForKey(key: String) -> Bool {
NSRequiresConcreteImplementation()
}
public func decodeObjectForKey(key: String) -> AnyObject? {
NSRequiresConcreteImplementation()
}
public func decodeBoolForKey(key: String) -> Bool {
NSRequiresConcreteImplementation()
}
public func decodeIntForKey(key: String) -> Int32 {
NSRequiresConcreteImplementation()
}
public func decodeInt32ForKey(key: String) -> Int32 {
NSRequiresConcreteImplementation()
}
public func decodeInt64ForKey(key: String) -> Int64 {
NSRequiresConcreteImplementation()
}
public func decodeFloatForKey(key: String) -> Float {
NSRequiresConcreteImplementation()
}
public func decodeDoubleForKey(key: String) -> Double {
NSRequiresConcreteImplementation()
}
public func decodeBytesForKey(key: String, returnedLength lengthp: UnsafeMutablePointer<Int>) -> UnsafePointer<UInt8> { // returned bytes immutable!
NSRequiresConcreteImplementation()
}
public func encodeInteger(intv: Int, forKey key: String) {
NSRequiresConcreteImplementation()
}
public func decodeIntegerForKey(key: String) -> Int {
NSRequiresConcreteImplementation()
}
public var requiresSecureCoding: Bool {
get {
return false
}
}
public func decodePropertyListForKey(key: String) -> AnyObject? {
NSUnimplemented()
}
public var allowedClasses: Set<NSObject>? {
get {
NSUnimplemented()
}
}
public func failWithError(error: NSError) {
NSUnimplemented()
}
}