objc2_foundation/generated/
NSCoder.rs1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct NSDecodingFailurePolicy(pub NSInteger);
16impl NSDecodingFailurePolicy {
17 #[doc(alias = "NSDecodingFailurePolicyRaiseException")]
18 pub const RaiseException: Self = Self(0);
19 #[doc(alias = "NSDecodingFailurePolicySetErrorAndReturn")]
20 pub const SetErrorAndReturn: Self = Self(1);
21}
22
23unsafe impl Encode for NSDecodingFailurePolicy {
24 const ENCODING: Encoding = NSInteger::ENCODING;
25}
26
27unsafe impl RefEncode for NSDecodingFailurePolicy {
28 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
29}
30
31extern_class!(
32 #[unsafe(super(NSObject))]
34 #[derive(Debug, PartialEq, Eq, Hash)]
35 pub struct NSCoder;
36);
37
38extern_conformance!(
39 unsafe impl NSObjectProtocol for NSCoder {}
40);
41
42impl NSCoder {
43 extern_methods!(
44 #[unsafe(method(encodeValueOfObjCType:at:))]
45 #[unsafe(method_family = none)]
46 pub unsafe fn encodeValueOfObjCType_at(
47 &self,
48 r#type: NonNull<c_char>,
49 addr: NonNull<c_void>,
50 );
51
52 #[cfg(feature = "NSData")]
53 #[unsafe(method(encodeDataObject:))]
54 #[unsafe(method_family = none)]
55 pub unsafe fn encodeDataObject(&self, data: &NSData);
56
57 #[cfg(feature = "NSData")]
58 #[unsafe(method(decodeDataObject))]
59 #[unsafe(method_family = none)]
60 pub unsafe fn decodeDataObject(&self) -> Option<Retained<NSData>>;
61
62 #[unsafe(method(decodeValueOfObjCType:at:size:))]
63 #[unsafe(method_family = none)]
64 pub unsafe fn decodeValueOfObjCType_at_size(
65 &self,
66 r#type: NonNull<c_char>,
67 data: NonNull<c_void>,
68 size: NSUInteger,
69 );
70
71 #[cfg(feature = "NSString")]
72 #[unsafe(method(versionForClassName:))]
73 #[unsafe(method_family = none)]
74 pub unsafe fn versionForClassName(&self, class_name: &NSString) -> NSInteger;
75 );
76}
77
78impl NSCoder {
80 extern_methods!(
81 #[unsafe(method(init))]
82 #[unsafe(method_family = init)]
83 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
84
85 #[unsafe(method(new))]
86 #[unsafe(method_family = new)]
87 pub unsafe fn new() -> Retained<Self>;
88 );
89}
90
91impl NSCoder {
93 extern_methods!(
94 #[unsafe(method(encodeObject:))]
95 #[unsafe(method_family = none)]
96 pub unsafe fn encodeObject(&self, object: Option<&AnyObject>);
97
98 #[unsafe(method(encodeRootObject:))]
99 #[unsafe(method_family = none)]
100 pub unsafe fn encodeRootObject(&self, root_object: &AnyObject);
101
102 #[unsafe(method(encodeBycopyObject:))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn encodeBycopyObject(&self, an_object: Option<&AnyObject>);
105
106 #[unsafe(method(encodeByrefObject:))]
107 #[unsafe(method_family = none)]
108 pub unsafe fn encodeByrefObject(&self, an_object: Option<&AnyObject>);
109
110 #[unsafe(method(encodeConditionalObject:))]
111 #[unsafe(method_family = none)]
112 pub unsafe fn encodeConditionalObject(&self, object: Option<&AnyObject>);
113
114 #[unsafe(method(encodeArrayOfObjCType:count:at:))]
115 #[unsafe(method_family = none)]
116 pub unsafe fn encodeArrayOfObjCType_count_at(
117 &self,
118 r#type: NonNull<c_char>,
119 count: NSUInteger,
120 array: NonNull<c_void>,
121 );
122
123 #[unsafe(method(encodeBytes:length:))]
124 #[unsafe(method_family = none)]
125 pub unsafe fn encodeBytes_length(&self, byteaddr: *const c_void, length: NSUInteger);
126
127 #[unsafe(method(decodeObject))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn decodeObject(&self) -> Option<Retained<AnyObject>>;
130
131 #[cfg(feature = "NSError")]
132 #[unsafe(method(decodeTopLevelObjectAndReturnError:_))]
133 #[unsafe(method_family = none)]
134 pub unsafe fn decodeTopLevelObjectAndReturnError(
135 &self,
136 ) -> Result<Retained<AnyObject>, Retained<NSError>>;
137
138 #[unsafe(method(decodeArrayOfObjCType:count:at:))]
139 #[unsafe(method_family = none)]
140 pub unsafe fn decodeArrayOfObjCType_count_at(
141 &self,
142 item_type: NonNull<c_char>,
143 count: NSUInteger,
144 array: NonNull<c_void>,
145 );
146
147 #[unsafe(method(decodeBytesWithReturnedLength:))]
148 #[unsafe(method_family = none)]
149 pub unsafe fn decodeBytesWithReturnedLength(
150 &self,
151 lengthp: NonNull<NSUInteger>,
152 ) -> *mut c_void;
153
154 #[unsafe(method(encodePropertyList:))]
155 #[unsafe(method_family = none)]
156 pub unsafe fn encodePropertyList(&self, a_property_list: &AnyObject);
157
158 #[unsafe(method(decodePropertyList))]
159 #[unsafe(method_family = none)]
160 pub unsafe fn decodePropertyList(&self) -> Option<Retained<AnyObject>>;
161
162 #[cfg(feature = "NSZone")]
163 #[unsafe(method(setObjectZone:))]
164 #[unsafe(method_family = none)]
165 pub unsafe fn setObjectZone(&self, zone: *mut NSZone);
166
167 #[cfg(feature = "NSZone")]
168 #[unsafe(method(objectZone))]
169 #[unsafe(method_family = none)]
170 pub unsafe fn objectZone(&self) -> *mut NSZone;
171
172 #[unsafe(method(systemVersion))]
173 #[unsafe(method_family = none)]
174 pub unsafe fn systemVersion(&self) -> c_uint;
175
176 #[unsafe(method(allowsKeyedCoding))]
177 #[unsafe(method_family = none)]
178 pub unsafe fn allowsKeyedCoding(&self) -> bool;
179
180 #[cfg(feature = "NSString")]
181 #[unsafe(method(encodeObject:forKey:))]
182 #[unsafe(method_family = none)]
183 pub unsafe fn encodeObject_forKey(&self, object: Option<&AnyObject>, key: &NSString);
184
185 #[cfg(feature = "NSString")]
186 #[unsafe(method(encodeConditionalObject:forKey:))]
187 #[unsafe(method_family = none)]
188 pub unsafe fn encodeConditionalObject_forKey(
189 &self,
190 object: Option<&AnyObject>,
191 key: &NSString,
192 );
193
194 #[cfg(feature = "NSString")]
195 #[unsafe(method(encodeBool:forKey:))]
196 #[unsafe(method_family = none)]
197 pub unsafe fn encodeBool_forKey(&self, value: bool, key: &NSString);
198
199 #[cfg(feature = "NSString")]
200 #[unsafe(method(encodeInt:forKey:))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn encodeInt_forKey(&self, value: c_int, key: &NSString);
203
204 #[cfg(feature = "NSString")]
205 #[unsafe(method(encodeInt32:forKey:))]
206 #[unsafe(method_family = none)]
207 pub unsafe fn encodeInt32_forKey(&self, value: i32, key: &NSString);
208
209 #[cfg(feature = "NSString")]
210 #[unsafe(method(encodeInt64:forKey:))]
211 #[unsafe(method_family = none)]
212 pub unsafe fn encodeInt64_forKey(&self, value: i64, key: &NSString);
213
214 #[cfg(feature = "NSString")]
215 #[unsafe(method(encodeFloat:forKey:))]
216 #[unsafe(method_family = none)]
217 pub unsafe fn encodeFloat_forKey(&self, value: c_float, key: &NSString);
218
219 #[cfg(feature = "NSString")]
220 #[unsafe(method(encodeDouble:forKey:))]
221 #[unsafe(method_family = none)]
222 pub unsafe fn encodeDouble_forKey(&self, value: c_double, key: &NSString);
223
224 #[cfg(feature = "NSString")]
225 #[unsafe(method(encodeBytes:length:forKey:))]
226 #[unsafe(method_family = none)]
227 pub unsafe fn encodeBytes_length_forKey(
228 &self,
229 bytes: *const u8,
230 length: NSUInteger,
231 key: &NSString,
232 );
233
234 #[cfg(feature = "NSString")]
235 #[unsafe(method(containsValueForKey:))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn containsValueForKey(&self, key: &NSString) -> bool;
238
239 #[cfg(feature = "NSString")]
240 #[unsafe(method(decodeObjectForKey:))]
241 #[unsafe(method_family = none)]
242 pub unsafe fn decodeObjectForKey(&self, key: &NSString) -> Option<Retained<AnyObject>>;
243
244 #[cfg(all(feature = "NSError", feature = "NSString"))]
245 #[unsafe(method(decodeTopLevelObjectForKey:error:_))]
246 #[unsafe(method_family = none)]
247 pub unsafe fn decodeTopLevelObjectForKey_error(
248 &self,
249 key: &NSString,
250 ) -> Result<Retained<AnyObject>, Retained<NSError>>;
251
252 #[cfg(feature = "NSString")]
253 #[unsafe(method(decodeBoolForKey:))]
254 #[unsafe(method_family = none)]
255 pub unsafe fn decodeBoolForKey(&self, key: &NSString) -> bool;
256
257 #[cfg(feature = "NSString")]
258 #[unsafe(method(decodeIntForKey:))]
259 #[unsafe(method_family = none)]
260 pub unsafe fn decodeIntForKey(&self, key: &NSString) -> c_int;
261
262 #[cfg(feature = "NSString")]
263 #[unsafe(method(decodeInt32ForKey:))]
264 #[unsafe(method_family = none)]
265 pub unsafe fn decodeInt32ForKey(&self, key: &NSString) -> i32;
266
267 #[cfg(feature = "NSString")]
268 #[unsafe(method(decodeInt64ForKey:))]
269 #[unsafe(method_family = none)]
270 pub unsafe fn decodeInt64ForKey(&self, key: &NSString) -> i64;
271
272 #[cfg(feature = "NSString")]
273 #[unsafe(method(decodeFloatForKey:))]
274 #[unsafe(method_family = none)]
275 pub unsafe fn decodeFloatForKey(&self, key: &NSString) -> c_float;
276
277 #[cfg(feature = "NSString")]
278 #[unsafe(method(decodeDoubleForKey:))]
279 #[unsafe(method_family = none)]
280 pub unsafe fn decodeDoubleForKey(&self, key: &NSString) -> c_double;
281
282 #[cfg(feature = "NSString")]
283 #[unsafe(method(decodeBytesForKey:returnedLength:))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn decodeBytesForKey_returnedLength(
286 &self,
287 key: &NSString,
288 lengthp: *mut NSUInteger,
289 ) -> *const u8;
290
291 #[unsafe(method(decodeBytesWithMinimumLength:))]
294 #[unsafe(method_family = none)]
295 pub unsafe fn decodeBytesWithMinimumLength(&self, length: NSUInteger) -> *mut c_void;
296
297 #[cfg(feature = "NSString")]
298 #[unsafe(method(decodeBytesForKey:minimumLength:))]
301 #[unsafe(method_family = none)]
302 pub unsafe fn decodeBytesForKey_minimumLength(
303 &self,
304 key: &NSString,
305 length: NSUInteger,
306 ) -> *const u8;
307
308 #[cfg(feature = "NSString")]
309 #[unsafe(method(encodeInteger:forKey:))]
310 #[unsafe(method_family = none)]
311 pub unsafe fn encodeInteger_forKey(&self, value: NSInteger, key: &NSString);
312
313 #[cfg(feature = "NSString")]
314 #[unsafe(method(decodeIntegerForKey:))]
315 #[unsafe(method_family = none)]
316 pub unsafe fn decodeIntegerForKey(&self, key: &NSString) -> NSInteger;
317
318 #[unsafe(method(requiresSecureCoding))]
319 #[unsafe(method_family = none)]
320 pub unsafe fn requiresSecureCoding(&self) -> bool;
321
322 #[cfg(feature = "NSString")]
323 #[unsafe(method(decodeObjectOfClass:forKey:))]
324 #[unsafe(method_family = none)]
325 pub unsafe fn decodeObjectOfClass_forKey(
326 &self,
327 a_class: &AnyClass,
328 key: &NSString,
329 ) -> Option<Retained<AnyObject>>;
330
331 #[cfg(all(feature = "NSError", feature = "NSString"))]
332 #[unsafe(method(decodeTopLevelObjectOfClass:forKey:error:_))]
333 #[unsafe(method_family = none)]
334 pub unsafe fn decodeTopLevelObjectOfClass_forKey_error(
335 &self,
336 a_class: &AnyClass,
337 key: &NSString,
338 ) -> Result<Retained<AnyObject>, Retained<NSError>>;
339
340 #[cfg(all(feature = "NSArray", feature = "NSString"))]
341 #[unsafe(method(decodeArrayOfObjectsOfClass:forKey:))]
355 #[unsafe(method_family = none)]
356 pub unsafe fn decodeArrayOfObjectsOfClass_forKey(
357 &self,
358 cls: &AnyClass,
359 key: &NSString,
360 ) -> Option<Retained<NSArray>>;
361
362 #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
363 #[unsafe(method(decodeDictionaryWithKeysOfClass:objectsOfClass:forKey:))]
379 #[unsafe(method_family = none)]
380 pub unsafe fn decodeDictionaryWithKeysOfClass_objectsOfClass_forKey(
381 &self,
382 key_cls: &AnyClass,
383 object_cls: &AnyClass,
384 key: &NSString,
385 ) -> Option<Retained<NSDictionary>>;
386
387 #[cfg(all(feature = "NSSet", feature = "NSString"))]
388 #[unsafe(method(decodeObjectOfClasses:forKey:))]
389 #[unsafe(method_family = none)]
390 pub unsafe fn decodeObjectOfClasses_forKey(
391 &self,
392 classes: Option<&NSSet<AnyClass>>,
393 key: &NSString,
394 ) -> Option<Retained<AnyObject>>;
395
396 #[cfg(all(feature = "NSError", feature = "NSSet", feature = "NSString"))]
397 #[unsafe(method(decodeTopLevelObjectOfClasses:forKey:error:_))]
398 #[unsafe(method_family = none)]
399 pub unsafe fn decodeTopLevelObjectOfClasses_forKey_error(
400 &self,
401 classes: Option<&NSSet<AnyClass>>,
402 key: &NSString,
403 ) -> Result<Retained<AnyObject>, Retained<NSError>>;
404
405 #[cfg(all(feature = "NSArray", feature = "NSSet", feature = "NSString"))]
406 #[unsafe(method(decodeArrayOfObjectsOfClasses:forKey:))]
420 #[unsafe(method_family = none)]
421 pub unsafe fn decodeArrayOfObjectsOfClasses_forKey(
422 &self,
423 classes: &NSSet<AnyClass>,
424 key: &NSString,
425 ) -> Option<Retained<NSArray>>;
426
427 #[cfg(all(feature = "NSDictionary", feature = "NSSet", feature = "NSString"))]
428 #[unsafe(method(decodeDictionaryWithKeysOfClasses:objectsOfClasses:forKey:))]
444 #[unsafe(method_family = none)]
445 pub unsafe fn decodeDictionaryWithKeysOfClasses_objectsOfClasses_forKey(
446 &self,
447 key_classes: &NSSet<AnyClass>,
448 object_classes: &NSSet<AnyClass>,
449 key: &NSString,
450 ) -> Option<Retained<NSDictionary>>;
451
452 #[cfg(feature = "NSString")]
453 #[unsafe(method(decodePropertyListForKey:))]
454 #[unsafe(method_family = none)]
455 pub unsafe fn decodePropertyListForKey(
456 &self,
457 key: &NSString,
458 ) -> Option<Retained<AnyObject>>;
459
460 #[cfg(feature = "NSSet")]
461 #[unsafe(method(allowedClasses))]
462 #[unsafe(method_family = none)]
463 pub unsafe fn allowedClasses(&self) -> Option<Retained<NSSet<AnyClass>>>;
464
465 #[cfg(feature = "NSError")]
466 #[unsafe(method(failWithError:))]
496 #[unsafe(method_family = none)]
497 pub unsafe fn failWithError(&self, error: &NSError);
498
499 #[unsafe(method(decodingFailurePolicy))]
503 #[unsafe(method_family = none)]
504 pub unsafe fn decodingFailurePolicy(&self) -> NSDecodingFailurePolicy;
505
506 #[cfg(feature = "NSError")]
507 #[unsafe(method(error))]
517 #[unsafe(method_family = none)]
518 pub unsafe fn error(&self) -> Option<Retained<NSError>>;
519 );
520}
521
522#[deprecated = "Not supported"]
523#[inline]
524pub unsafe extern "C-unwind" fn NXReadNSObjectFromCoder(
525 decoder: &NSCoder,
526) -> Option<Retained<NSObject>> {
527 extern "C-unwind" {
528 fn NXReadNSObjectFromCoder(decoder: &NSCoder) -> *mut NSObject;
529 }
530 let ret = unsafe { NXReadNSObjectFromCoder(decoder) };
531 unsafe { Retained::retain_autoreleased(ret) }
532}
533
534impl NSCoder {
536 extern_methods!(
537 #[deprecated = "Not supported"]
538 #[unsafe(method(encodeNXObject:))]
539 #[unsafe(method_family = none)]
540 pub unsafe fn encodeNXObject(&self, object: &AnyObject);
541
542 #[deprecated = "Not supported"]
543 #[unsafe(method(decodeNXObject))]
544 #[unsafe(method_family = none)]
545 pub unsafe fn decodeNXObject(&self) -> Option<Retained<AnyObject>>;
546 );
547}
548
549impl NSCoder {
551 extern_methods!(
552 #[deprecated]
553 #[unsafe(method(decodeValueOfObjCType:at:))]
554 #[unsafe(method_family = none)]
555 pub unsafe fn decodeValueOfObjCType_at(
556 &self,
557 r#type: NonNull<c_char>,
558 data: NonNull<c_void>,
559 );
560 );
561}