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:))]
49 #[unsafe(method_family = none)]
50 pub unsafe fn encodeValueOfObjCType_at(
51 &self,
52 r#type: NonNull<c_char>,
53 addr: NonNull<c_void>,
54 );
55
56 #[cfg(feature = "NSData")]
57 #[unsafe(method(encodeDataObject:))]
58 #[unsafe(method_family = none)]
59 pub unsafe fn encodeDataObject(&self, data: &NSData);
60
61 #[cfg(feature = "NSData")]
62 #[unsafe(method(decodeDataObject))]
63 #[unsafe(method_family = none)]
64 pub unsafe fn decodeDataObject(&self) -> Option<Retained<NSData>>;
65
66 #[unsafe(method(decodeValueOfObjCType:at:size:))]
71 #[unsafe(method_family = none)]
72 pub unsafe fn decodeValueOfObjCType_at_size(
73 &self,
74 r#type: NonNull<c_char>,
75 data: NonNull<c_void>,
76 size: NSUInteger,
77 );
78
79 #[cfg(feature = "NSString")]
80 #[unsafe(method(versionForClassName:))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn versionForClassName(&self, class_name: &NSString) -> NSInteger;
83 );
84}
85
86impl NSCoder {
88 extern_methods!(
89 #[unsafe(method(init))]
90 #[unsafe(method_family = init)]
91 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
92
93 #[unsafe(method(new))]
94 #[unsafe(method_family = new)]
95 pub unsafe fn new() -> Retained<Self>;
96 );
97}
98
99impl NSCoder {
101 extern_methods!(
102 #[unsafe(method(encodeObject:))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn encodeObject(&self, object: Option<&AnyObject>);
108
109 #[unsafe(method(encodeRootObject:))]
113 #[unsafe(method_family = none)]
114 pub unsafe fn encodeRootObject(&self, root_object: &AnyObject);
115
116 #[unsafe(method(encodeBycopyObject:))]
120 #[unsafe(method_family = none)]
121 pub unsafe fn encodeBycopyObject(&self, an_object: Option<&AnyObject>);
122
123 #[unsafe(method(encodeByrefObject:))]
127 #[unsafe(method_family = none)]
128 pub unsafe fn encodeByrefObject(&self, an_object: Option<&AnyObject>);
129
130 #[unsafe(method(encodeConditionalObject:))]
134 #[unsafe(method_family = none)]
135 pub unsafe fn encodeConditionalObject(&self, object: Option<&AnyObject>);
136
137 #[unsafe(method(encodeArrayOfObjCType:count:at:))]
142 #[unsafe(method_family = none)]
143 pub unsafe fn encodeArrayOfObjCType_count_at(
144 &self,
145 r#type: NonNull<c_char>,
146 count: NSUInteger,
147 array: NonNull<c_void>,
148 );
149
150 #[unsafe(method(encodeBytes:length:))]
154 #[unsafe(method_family = none)]
155 pub unsafe fn encodeBytes_length(&self, byteaddr: *const c_void, length: NSUInteger);
156
157 #[unsafe(method(decodeObject))]
158 #[unsafe(method_family = none)]
159 pub unsafe fn decodeObject(&self) -> Option<Retained<AnyObject>>;
160
161 #[cfg(feature = "NSError")]
162 #[unsafe(method(decodeTopLevelObjectAndReturnError:_))]
163 #[unsafe(method_family = none)]
164 pub unsafe fn decodeTopLevelObjectAndReturnError(
165 &self,
166 ) -> Result<Retained<AnyObject>, Retained<NSError>>;
167
168 #[unsafe(method(decodeArrayOfObjCType:count:at:))]
173 #[unsafe(method_family = none)]
174 pub unsafe fn decodeArrayOfObjCType_count_at(
175 &self,
176 item_type: NonNull<c_char>,
177 count: NSUInteger,
178 array: NonNull<c_void>,
179 );
180
181 #[unsafe(method(decodeBytesWithReturnedLength:))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn decodeBytesWithReturnedLength(
187 &self,
188 lengthp: NonNull<NSUInteger>,
189 ) -> *mut c_void;
190
191 #[unsafe(method(encodePropertyList:))]
195 #[unsafe(method_family = none)]
196 pub unsafe fn encodePropertyList(&self, a_property_list: &AnyObject);
197
198 #[unsafe(method(decodePropertyList))]
199 #[unsafe(method_family = none)]
200 pub unsafe fn decodePropertyList(&self) -> Option<Retained<AnyObject>>;
201
202 #[cfg(feature = "NSZone")]
203 #[unsafe(method(setObjectZone:))]
207 #[unsafe(method_family = none)]
208 pub unsafe fn setObjectZone(&self, zone: *mut NSZone);
209
210 #[cfg(feature = "NSZone")]
211 #[unsafe(method(objectZone))]
212 #[unsafe(method_family = none)]
213 pub unsafe fn objectZone(&self) -> *mut NSZone;
214
215 #[unsafe(method(systemVersion))]
216 #[unsafe(method_family = none)]
217 pub unsafe fn systemVersion(&self) -> c_uint;
218
219 #[unsafe(method(allowsKeyedCoding))]
220 #[unsafe(method_family = none)]
221 pub unsafe fn allowsKeyedCoding(&self) -> bool;
222
223 #[cfg(feature = "NSString")]
224 #[unsafe(method(encodeObject:forKey:))]
228 #[unsafe(method_family = none)]
229 pub unsafe fn encodeObject_forKey(&self, object: Option<&AnyObject>, key: &NSString);
230
231 #[cfg(feature = "NSString")]
232 #[unsafe(method(encodeConditionalObject:forKey:))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn encodeConditionalObject_forKey(
238 &self,
239 object: Option<&AnyObject>,
240 key: &NSString,
241 );
242
243 #[cfg(feature = "NSString")]
244 #[unsafe(method(encodeBool:forKey:))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn encodeBool_forKey(&self, value: bool, key: &NSString);
247
248 #[cfg(feature = "NSString")]
249 #[unsafe(method(encodeInt:forKey:))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn encodeInt_forKey(&self, value: c_int, key: &NSString);
252
253 #[cfg(feature = "NSString")]
254 #[unsafe(method(encodeInt32:forKey:))]
255 #[unsafe(method_family = none)]
256 pub unsafe fn encodeInt32_forKey(&self, value: i32, key: &NSString);
257
258 #[cfg(feature = "NSString")]
259 #[unsafe(method(encodeInt64:forKey:))]
260 #[unsafe(method_family = none)]
261 pub unsafe fn encodeInt64_forKey(&self, value: i64, key: &NSString);
262
263 #[cfg(feature = "NSString")]
264 #[unsafe(method(encodeFloat:forKey:))]
265 #[unsafe(method_family = none)]
266 pub unsafe fn encodeFloat_forKey(&self, value: c_float, key: &NSString);
267
268 #[cfg(feature = "NSString")]
269 #[unsafe(method(encodeDouble:forKey:))]
270 #[unsafe(method_family = none)]
271 pub unsafe fn encodeDouble_forKey(&self, value: c_double, key: &NSString);
272
273 #[cfg(feature = "NSString")]
274 #[unsafe(method(encodeBytes:length:forKey:))]
278 #[unsafe(method_family = none)]
279 pub unsafe fn encodeBytes_length_forKey(
280 &self,
281 bytes: *const u8,
282 length: NSUInteger,
283 key: &NSString,
284 );
285
286 #[cfg(feature = "NSString")]
287 #[unsafe(method(containsValueForKey:))]
288 #[unsafe(method_family = none)]
289 pub unsafe fn containsValueForKey(&self, key: &NSString) -> bool;
290
291 #[cfg(feature = "NSString")]
292 #[unsafe(method(decodeObjectForKey:))]
293 #[unsafe(method_family = none)]
294 pub unsafe fn decodeObjectForKey(&self, key: &NSString) -> Option<Retained<AnyObject>>;
295
296 #[cfg(all(feature = "NSError", feature = "NSString"))]
297 #[unsafe(method(decodeTopLevelObjectForKey:error:_))]
298 #[unsafe(method_family = none)]
299 pub unsafe fn decodeTopLevelObjectForKey_error(
300 &self,
301 key: &NSString,
302 ) -> Result<Retained<AnyObject>, Retained<NSError>>;
303
304 #[cfg(feature = "NSString")]
305 #[unsafe(method(decodeBoolForKey:))]
306 #[unsafe(method_family = none)]
307 pub unsafe fn decodeBoolForKey(&self, key: &NSString) -> bool;
308
309 #[cfg(feature = "NSString")]
310 #[unsafe(method(decodeIntForKey:))]
311 #[unsafe(method_family = none)]
312 pub unsafe fn decodeIntForKey(&self, key: &NSString) -> c_int;
313
314 #[cfg(feature = "NSString")]
315 #[unsafe(method(decodeInt32ForKey:))]
316 #[unsafe(method_family = none)]
317 pub unsafe fn decodeInt32ForKey(&self, key: &NSString) -> i32;
318
319 #[cfg(feature = "NSString")]
320 #[unsafe(method(decodeInt64ForKey:))]
321 #[unsafe(method_family = none)]
322 pub unsafe fn decodeInt64ForKey(&self, key: &NSString) -> i64;
323
324 #[cfg(feature = "NSString")]
325 #[unsafe(method(decodeFloatForKey:))]
326 #[unsafe(method_family = none)]
327 pub unsafe fn decodeFloatForKey(&self, key: &NSString) -> c_float;
328
329 #[cfg(feature = "NSString")]
330 #[unsafe(method(decodeDoubleForKey:))]
331 #[unsafe(method_family = none)]
332 pub unsafe fn decodeDoubleForKey(&self, key: &NSString) -> c_double;
333
334 #[cfg(feature = "NSString")]
335 #[unsafe(method(decodeBytesForKey:returnedLength:))]
339 #[unsafe(method_family = none)]
340 pub unsafe fn decodeBytesForKey_returnedLength(
341 &self,
342 key: &NSString,
343 lengthp: *mut NSUInteger,
344 ) -> *const u8;
345
346 #[unsafe(method(decodeBytesWithMinimumLength:))]
349 #[unsafe(method_family = none)]
350 pub unsafe fn decodeBytesWithMinimumLength(&self, length: NSUInteger) -> *mut c_void;
351
352 #[cfg(feature = "NSString")]
353 #[unsafe(method(decodeBytesForKey:minimumLength:))]
356 #[unsafe(method_family = none)]
357 pub unsafe fn decodeBytesForKey_minimumLength(
358 &self,
359 key: &NSString,
360 length: NSUInteger,
361 ) -> *const u8;
362
363 #[cfg(feature = "NSString")]
364 #[unsafe(method(encodeInteger:forKey:))]
365 #[unsafe(method_family = none)]
366 pub unsafe fn encodeInteger_forKey(&self, value: NSInteger, key: &NSString);
367
368 #[cfg(feature = "NSString")]
369 #[unsafe(method(decodeIntegerForKey:))]
370 #[unsafe(method_family = none)]
371 pub unsafe fn decodeIntegerForKey(&self, key: &NSString) -> NSInteger;
372
373 #[unsafe(method(requiresSecureCoding))]
374 #[unsafe(method_family = none)]
375 pub unsafe fn requiresSecureCoding(&self) -> bool;
376
377 #[cfg(feature = "NSString")]
378 #[unsafe(method(decodeObjectOfClass:forKey:))]
382 #[unsafe(method_family = none)]
383 pub unsafe fn decodeObjectOfClass_forKey(
384 &self,
385 a_class: &AnyClass,
386 key: &NSString,
387 ) -> Option<Retained<AnyObject>>;
388
389 #[cfg(all(feature = "NSError", feature = "NSString"))]
390 #[unsafe(method(decodeTopLevelObjectOfClass:forKey:error:_))]
394 #[unsafe(method_family = none)]
395 pub unsafe fn decodeTopLevelObjectOfClass_forKey_error(
396 &self,
397 a_class: &AnyClass,
398 key: &NSString,
399 ) -> Result<Retained<AnyObject>, Retained<NSError>>;
400
401 #[cfg(all(feature = "NSArray", feature = "NSString"))]
402 #[unsafe(method(decodeArrayOfObjectsOfClass:forKey:))]
420 #[unsafe(method_family = none)]
421 pub unsafe fn decodeArrayOfObjectsOfClass_forKey(
422 &self,
423 cls: &AnyClass,
424 key: &NSString,
425 ) -> Option<Retained<NSArray>>;
426
427 #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
428 #[unsafe(method(decodeDictionaryWithKeysOfClass:objectsOfClass:forKey:))]
449 #[unsafe(method_family = none)]
450 pub unsafe fn decodeDictionaryWithKeysOfClass_objectsOfClass_forKey(
451 &self,
452 key_cls: &AnyClass,
453 object_cls: &AnyClass,
454 key: &NSString,
455 ) -> Option<Retained<NSDictionary>>;
456
457 #[cfg(all(feature = "NSSet", feature = "NSString"))]
458 #[unsafe(method(decodeObjectOfClasses:forKey:))]
462 #[unsafe(method_family = none)]
463 pub unsafe fn decodeObjectOfClasses_forKey(
464 &self,
465 classes: Option<&NSSet<AnyClass>>,
466 key: &NSString,
467 ) -> Option<Retained<AnyObject>>;
468
469 #[cfg(all(feature = "NSError", feature = "NSSet", feature = "NSString"))]
470 #[unsafe(method(decodeTopLevelObjectOfClasses:forKey:error:_))]
474 #[unsafe(method_family = none)]
475 pub unsafe fn decodeTopLevelObjectOfClasses_forKey_error(
476 &self,
477 classes: Option<&NSSet<AnyClass>>,
478 key: &NSString,
479 ) -> Result<Retained<AnyObject>, Retained<NSError>>;
480
481 #[cfg(all(feature = "NSArray", feature = "NSSet", feature = "NSString"))]
482 #[unsafe(method(decodeArrayOfObjectsOfClasses:forKey:))]
500 #[unsafe(method_family = none)]
501 pub unsafe fn decodeArrayOfObjectsOfClasses_forKey(
502 &self,
503 classes: &NSSet<AnyClass>,
504 key: &NSString,
505 ) -> Option<Retained<NSArray>>;
506
507 #[cfg(all(feature = "NSDictionary", feature = "NSSet", feature = "NSString"))]
508 #[unsafe(method(decodeDictionaryWithKeysOfClasses:objectsOfClasses:forKey:))]
529 #[unsafe(method_family = none)]
530 pub unsafe fn decodeDictionaryWithKeysOfClasses_objectsOfClasses_forKey(
531 &self,
532 key_classes: &NSSet<AnyClass>,
533 object_classes: &NSSet<AnyClass>,
534 key: &NSString,
535 ) -> Option<Retained<NSDictionary>>;
536
537 #[cfg(feature = "NSString")]
538 #[unsafe(method(decodePropertyListForKey:))]
539 #[unsafe(method_family = none)]
540 pub unsafe fn decodePropertyListForKey(
541 &self,
542 key: &NSString,
543 ) -> Option<Retained<AnyObject>>;
544
545 #[cfg(feature = "NSSet")]
546 #[unsafe(method(allowedClasses))]
547 #[unsafe(method_family = none)]
548 pub unsafe fn allowedClasses(&self) -> Option<Retained<NSSet<AnyClass>>>;
549
550 #[cfg(feature = "NSError")]
551 #[unsafe(method(failWithError:))]
581 #[unsafe(method_family = none)]
582 pub unsafe fn failWithError(&self, error: &NSError);
583
584 #[unsafe(method(decodingFailurePolicy))]
588 #[unsafe(method_family = none)]
589 pub unsafe fn decodingFailurePolicy(&self) -> NSDecodingFailurePolicy;
590
591 #[cfg(feature = "NSError")]
592 #[unsafe(method(error))]
602 #[unsafe(method_family = none)]
603 pub unsafe fn error(&self) -> Option<Retained<NSError>>;
604 );
605}
606
607#[deprecated = "Not supported"]
611#[inline]
612pub unsafe extern "C-unwind" fn NXReadNSObjectFromCoder(
613 decoder: &NSCoder,
614) -> Option<Retained<NSObject>> {
615 extern "C-unwind" {
616 fn NXReadNSObjectFromCoder(decoder: &NSCoder) -> *mut NSObject;
617 }
618 let ret = unsafe { NXReadNSObjectFromCoder(decoder) };
619 unsafe { Retained::retain_autoreleased(ret) }
620}
621
622impl NSCoder {
624 extern_methods!(
625 #[deprecated = "Not supported"]
629 #[unsafe(method(encodeNXObject:))]
630 #[unsafe(method_family = none)]
631 pub unsafe fn encodeNXObject(&self, object: &AnyObject);
632
633 #[deprecated = "Not supported"]
634 #[unsafe(method(decodeNXObject))]
635 #[unsafe(method_family = none)]
636 pub unsafe fn decodeNXObject(&self) -> Option<Retained<AnyObject>>;
637 );
638}
639
640impl NSCoder {
642 extern_methods!(
643 #[deprecated]
648 #[unsafe(method(decodeValueOfObjCType:at:))]
649 #[unsafe(method_family = none)]
650 pub unsafe fn decodeValueOfObjCType_at(
651 &self,
652 r#type: NonNull<c_char>,
653 data: NonNull<c_void>,
654 );
655 );
656}