objc2_foundation/generated/
NSData.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9/// **************    Read/Write Options    ***************
10///
11/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdatareadingoptions?language=objc)
12// NS_OPTIONS
13#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct NSDataReadingOptions(pub NSUInteger);
16bitflags::bitflags! {
17    impl NSDataReadingOptions: NSUInteger {
18        #[doc(alias = "NSDataReadingMappedIfSafe")]
19        const MappedIfSafe = 1<<0;
20        #[doc(alias = "NSDataReadingUncached")]
21        const Uncached = 1<<1;
22        #[doc(alias = "NSDataReadingMappedAlways")]
23        const MappedAlways = 1<<3;
24        #[doc(alias = "NSDataReadingMapped")]
25#[deprecated]
26        const Mapped = NSDataReadingOptions::MappedIfSafe.0;
27#[deprecated]
28        const NSMappedRead = NSDataReadingOptions::Mapped.0;
29#[deprecated]
30        const NSUncachedRead = NSDataReadingOptions::Uncached.0;
31    }
32}
33
34unsafe impl Encode for NSDataReadingOptions {
35    const ENCODING: Encoding = NSUInteger::ENCODING;
36}
37
38unsafe impl RefEncode for NSDataReadingOptions {
39    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
40}
41
42/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdatawritingoptions?language=objc)
43// NS_OPTIONS
44#[repr(transparent)]
45#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
46pub struct NSDataWritingOptions(pub NSUInteger);
47bitflags::bitflags! {
48    impl NSDataWritingOptions: NSUInteger {
49        #[doc(alias = "NSDataWritingAtomic")]
50        const Atomic = 1<<0;
51        #[doc(alias = "NSDataWritingWithoutOverwriting")]
52        const WithoutOverwriting = 1<<1;
53        #[doc(alias = "NSDataWritingFileProtectionNone")]
54        const FileProtectionNone = 0x10000000;
55        #[doc(alias = "NSDataWritingFileProtectionComplete")]
56        const FileProtectionComplete = 0x20000000;
57        #[doc(alias = "NSDataWritingFileProtectionCompleteUnlessOpen")]
58        const FileProtectionCompleteUnlessOpen = 0x30000000;
59        #[doc(alias = "NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication")]
60        const FileProtectionCompleteUntilFirstUserAuthentication = 0x40000000;
61        #[doc(alias = "NSDataWritingFileProtectionCompleteWhenUserInactive")]
62        const FileProtectionCompleteWhenUserInactive = 0x50000000;
63        #[doc(alias = "NSDataWritingFileProtectionMask")]
64        const FileProtectionMask = 0xf0000000;
65#[deprecated]
66        const NSAtomicWrite = NSDataWritingOptions::Atomic.0;
67    }
68}
69
70unsafe impl Encode for NSDataWritingOptions {
71    const ENCODING: Encoding = NSUInteger::ENCODING;
72}
73
74unsafe impl RefEncode for NSDataWritingOptions {
75    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
76}
77
78/// **************    Data Search Options    ***************
79///
80/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdatasearchoptions?language=objc)
81// NS_OPTIONS
82#[repr(transparent)]
83#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
84pub struct NSDataSearchOptions(pub NSUInteger);
85bitflags::bitflags! {
86    impl NSDataSearchOptions: NSUInteger {
87        #[doc(alias = "NSDataSearchBackwards")]
88        const Backwards = 1<<0;
89        #[doc(alias = "NSDataSearchAnchored")]
90        const Anchored = 1<<1;
91    }
92}
93
94unsafe impl Encode for NSDataSearchOptions {
95    const ENCODING: Encoding = NSUInteger::ENCODING;
96}
97
98unsafe impl RefEncode for NSDataSearchOptions {
99    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
100}
101
102/// **************        Base 64 Options    ***************
103///
104/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdatabase64encodingoptions?language=objc)
105// NS_OPTIONS
106#[repr(transparent)]
107#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
108pub struct NSDataBase64EncodingOptions(pub NSUInteger);
109bitflags::bitflags! {
110    impl NSDataBase64EncodingOptions: NSUInteger {
111        #[doc(alias = "NSDataBase64Encoding64CharacterLineLength")]
112        const Encoding64CharacterLineLength = 1<<0;
113        #[doc(alias = "NSDataBase64Encoding76CharacterLineLength")]
114        const Encoding76CharacterLineLength = 1<<1;
115        #[doc(alias = "NSDataBase64EncodingEndLineWithCarriageReturn")]
116        const EncodingEndLineWithCarriageReturn = 1<<4;
117        #[doc(alias = "NSDataBase64EncodingEndLineWithLineFeed")]
118        const EncodingEndLineWithLineFeed = 1<<5;
119    }
120}
121
122unsafe impl Encode for NSDataBase64EncodingOptions {
123    const ENCODING: Encoding = NSUInteger::ENCODING;
124}
125
126unsafe impl RefEncode for NSDataBase64EncodingOptions {
127    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
128}
129
130/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdatabase64decodingoptions?language=objc)
131// NS_OPTIONS
132#[repr(transparent)]
133#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
134pub struct NSDataBase64DecodingOptions(pub NSUInteger);
135bitflags::bitflags! {
136    impl NSDataBase64DecodingOptions: NSUInteger {
137        #[doc(alias = "NSDataBase64DecodingIgnoreUnknownCharacters")]
138        const IgnoreUnknownCharacters = 1<<0;
139    }
140}
141
142unsafe impl Encode for NSDataBase64DecodingOptions {
143    const ENCODING: Encoding = NSUInteger::ENCODING;
144}
145
146unsafe impl RefEncode for NSDataBase64DecodingOptions {
147    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
148}
149
150extern_class!(
151    /// **************    Immutable Data        ***************
152    ///
153    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdata?language=objc)
154    #[unsafe(super(NSObject))]
155    #[derive(PartialEq, Eq, Hash)]
156    pub struct NSData;
157);
158
159#[cfg(feature = "NSObject")]
160extern_conformance!(
161    unsafe impl NSCoding for NSData {}
162);
163
164#[cfg(feature = "NSObject")]
165extern_conformance!(
166    unsafe impl NSCopying for NSData {}
167);
168
169#[cfg(feature = "NSObject")]
170unsafe impl CopyingHelper for NSData {
171    type Result = Self;
172}
173
174#[cfg(feature = "NSObject")]
175extern_conformance!(
176    unsafe impl NSMutableCopying for NSData {}
177);
178
179#[cfg(feature = "NSObject")]
180unsafe impl MutableCopyingHelper for NSData {
181    type Result = NSMutableData;
182}
183
184extern_conformance!(
185    unsafe impl NSObjectProtocol for NSData {}
186);
187
188#[cfg(feature = "NSObject")]
189extern_conformance!(
190    unsafe impl NSSecureCoding for NSData {}
191);
192
193impl NSData {
194    extern_methods!(
195        #[unsafe(method(length))]
196        #[unsafe(method_family = none)]
197        pub fn length(&self) -> NSUInteger;
198    );
199}
200
201/// Methods declared on superclass `NSObject`.
202impl NSData {
203    extern_methods!(
204        #[unsafe(method(init))]
205        #[unsafe(method_family = init)]
206        pub fn init(this: Allocated<Self>) -> Retained<Self>;
207
208        #[unsafe(method(new))]
209        #[unsafe(method_family = new)]
210        pub fn new() -> Retained<Self>;
211    );
212}
213
214impl DefaultRetained for NSData {
215    #[inline]
216    fn default_retained() -> Retained<Self> {
217        Self::new()
218    }
219}
220
221/// NSExtendedData.
222impl NSData {
223    extern_methods!(
224        #[cfg(feature = "NSString")]
225        #[unsafe(method(description))]
226        #[unsafe(method_family = none)]
227        pub unsafe fn description(&self) -> Retained<NSString>;
228
229        #[unsafe(method(getBytes:length:))]
230        #[unsafe(method_family = none)]
231        pub unsafe fn getBytes_length(&self, buffer: NonNull<c_void>, length: NSUInteger);
232
233        #[cfg(feature = "NSRange")]
234        #[unsafe(method(getBytes:range:))]
235        #[unsafe(method_family = none)]
236        pub unsafe fn getBytes_range(&self, buffer: NonNull<c_void>, range: NSRange);
237
238        #[unsafe(method(isEqualToData:))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn isEqualToData(&self, other: &NSData) -> bool;
241
242        #[cfg(feature = "NSRange")]
243        #[unsafe(method(subdataWithRange:))]
244        #[unsafe(method_family = none)]
245        pub unsafe fn subdataWithRange(&self, range: NSRange) -> Retained<NSData>;
246
247        #[cfg(feature = "NSString")]
248        #[unsafe(method(writeToFile:atomically:))]
249        #[unsafe(method_family = none)]
250        pub unsafe fn writeToFile_atomically(
251            &self,
252            path: &NSString,
253            use_auxiliary_file: bool,
254        ) -> bool;
255
256        #[cfg(feature = "NSURL")]
257        #[unsafe(method(writeToURL:atomically:))]
258        #[unsafe(method_family = none)]
259        pub unsafe fn writeToURL_atomically(&self, url: &NSURL, atomically: bool) -> bool;
260
261        #[cfg(all(feature = "NSError", feature = "NSString"))]
262        #[unsafe(method(writeToFile:options:error:_))]
263        #[unsafe(method_family = none)]
264        pub unsafe fn writeToFile_options_error(
265            &self,
266            path: &NSString,
267            write_options_mask: NSDataWritingOptions,
268        ) -> Result<(), Retained<NSError>>;
269
270        #[cfg(all(feature = "NSError", feature = "NSURL"))]
271        #[unsafe(method(writeToURL:options:error:_))]
272        #[unsafe(method_family = none)]
273        pub unsafe fn writeToURL_options_error(
274            &self,
275            url: &NSURL,
276            write_options_mask: NSDataWritingOptions,
277        ) -> Result<(), Retained<NSError>>;
278
279        #[cfg(feature = "NSRange")]
280        #[unsafe(method(rangeOfData:options:range:))]
281        #[unsafe(method_family = none)]
282        pub unsafe fn rangeOfData_options_range(
283            &self,
284            data_to_find: &NSData,
285            mask: NSDataSearchOptions,
286            search_range: NSRange,
287        ) -> NSRange;
288
289        #[cfg(all(feature = "NSRange", feature = "block2"))]
290        #[unsafe(method(enumerateByteRangesUsingBlock:))]
291        #[unsafe(method_family = none)]
292        pub unsafe fn enumerateByteRangesUsingBlock(
293            &self,
294            block: &block2::DynBlock<dyn Fn(NonNull<c_void>, NSRange, NonNull<Bool>) + '_>,
295        );
296    );
297}
298
299/// NSDataCreation.
300impl NSData {
301    extern_methods!(
302        #[unsafe(method(data))]
303        #[unsafe(method_family = none)]
304        pub unsafe fn data() -> Retained<Self>;
305
306        #[unsafe(method(dataWithBytes:length:))]
307        #[unsafe(method_family = none)]
308        pub unsafe fn dataWithBytes_length(
309            bytes: *const c_void,
310            length: NSUInteger,
311        ) -> Retained<Self>;
312
313        #[unsafe(method(dataWithBytesNoCopy:length:))]
314        #[unsafe(method_family = none)]
315        pub unsafe fn dataWithBytesNoCopy_length(
316            bytes: NonNull<c_void>,
317            length: NSUInteger,
318        ) -> Retained<Self>;
319
320        #[unsafe(method(dataWithBytesNoCopy:length:freeWhenDone:))]
321        #[unsafe(method_family = none)]
322        pub unsafe fn dataWithBytesNoCopy_length_freeWhenDone(
323            bytes: NonNull<c_void>,
324            length: NSUInteger,
325            b: bool,
326        ) -> Retained<Self>;
327
328        #[cfg(all(feature = "NSError", feature = "NSString"))]
329        #[unsafe(method(dataWithContentsOfFile:options:error:_))]
330        #[unsafe(method_family = none)]
331        pub unsafe fn dataWithContentsOfFile_options_error(
332            path: &NSString,
333            read_options_mask: NSDataReadingOptions,
334        ) -> Result<Retained<Self>, Retained<NSError>>;
335
336        #[cfg(all(feature = "NSError", feature = "NSURL"))]
337        #[unsafe(method(dataWithContentsOfURL:options:error:_))]
338        #[unsafe(method_family = none)]
339        pub unsafe fn dataWithContentsOfURL_options_error(
340            url: &NSURL,
341            read_options_mask: NSDataReadingOptions,
342        ) -> Result<Retained<Self>, Retained<NSError>>;
343
344        #[cfg(feature = "NSString")]
345        #[unsafe(method(dataWithContentsOfFile:))]
346        #[unsafe(method_family = none)]
347        pub unsafe fn dataWithContentsOfFile(path: &NSString) -> Option<Retained<Self>>;
348
349        #[cfg(feature = "NSURL")]
350        #[unsafe(method(dataWithContentsOfURL:))]
351        #[unsafe(method_family = none)]
352        pub unsafe fn dataWithContentsOfURL(url: &NSURL) -> Option<Retained<Self>>;
353
354        #[unsafe(method(initWithBytes:length:))]
355        #[unsafe(method_family = init)]
356        pub unsafe fn initWithBytes_length(
357            this: Allocated<Self>,
358            bytes: *const c_void,
359            length: NSUInteger,
360        ) -> Retained<Self>;
361
362        #[unsafe(method(initWithBytesNoCopy:length:))]
363        #[unsafe(method_family = init)]
364        pub unsafe fn initWithBytesNoCopy_length(
365            this: Allocated<Self>,
366            bytes: NonNull<c_void>,
367            length: NSUInteger,
368        ) -> Retained<Self>;
369
370        #[unsafe(method(initWithBytesNoCopy:length:freeWhenDone:))]
371        #[unsafe(method_family = init)]
372        pub unsafe fn initWithBytesNoCopy_length_freeWhenDone(
373            this: Allocated<Self>,
374            bytes: NonNull<c_void>,
375            length: NSUInteger,
376            b: bool,
377        ) -> Retained<Self>;
378
379        #[cfg(feature = "block2")]
380        #[unsafe(method(initWithBytesNoCopy:length:deallocator:))]
381        #[unsafe(method_family = init)]
382        pub unsafe fn initWithBytesNoCopy_length_deallocator(
383            this: Allocated<Self>,
384            bytes: NonNull<c_void>,
385            length: NSUInteger,
386            deallocator: Option<&block2::DynBlock<dyn Fn(NonNull<c_void>, NSUInteger)>>,
387        ) -> Retained<Self>;
388
389        #[cfg(all(feature = "NSError", feature = "NSString"))]
390        #[unsafe(method(initWithContentsOfFile:options:error:_))]
391        #[unsafe(method_family = init)]
392        pub unsafe fn initWithContentsOfFile_options_error(
393            this: Allocated<Self>,
394            path: &NSString,
395            read_options_mask: NSDataReadingOptions,
396        ) -> Result<Retained<Self>, Retained<NSError>>;
397
398        #[cfg(all(feature = "NSError", feature = "NSURL"))]
399        #[unsafe(method(initWithContentsOfURL:options:error:_))]
400        #[unsafe(method_family = init)]
401        pub unsafe fn initWithContentsOfURL_options_error(
402            this: Allocated<Self>,
403            url: &NSURL,
404            read_options_mask: NSDataReadingOptions,
405        ) -> Result<Retained<Self>, Retained<NSError>>;
406
407        #[cfg(feature = "NSString")]
408        #[unsafe(method(initWithContentsOfFile:))]
409        #[unsafe(method_family = init)]
410        pub unsafe fn initWithContentsOfFile(
411            this: Allocated<Self>,
412            path: &NSString,
413        ) -> Option<Retained<Self>>;
414
415        #[cfg(feature = "NSURL")]
416        #[unsafe(method(initWithContentsOfURL:))]
417        #[unsafe(method_family = init)]
418        pub unsafe fn initWithContentsOfURL(
419            this: Allocated<Self>,
420            url: &NSURL,
421        ) -> Option<Retained<Self>>;
422
423        #[unsafe(method(initWithData:))]
424        #[unsafe(method_family = init)]
425        pub fn initWithData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
426
427        #[unsafe(method(dataWithData:))]
428        #[unsafe(method_family = none)]
429        pub fn dataWithData(data: &NSData) -> Retained<Self>;
430    );
431}
432
433/// Methods declared on superclass `NSData`.
434///
435/// NSDataCreation.
436impl NSMutableData {
437    extern_methods!(
438        #[unsafe(method(data))]
439        #[unsafe(method_family = none)]
440        pub unsafe fn data() -> Retained<Self>;
441
442        #[unsafe(method(dataWithBytes:length:))]
443        #[unsafe(method_family = none)]
444        pub unsafe fn dataWithBytes_length(
445            bytes: *const c_void,
446            length: NSUInteger,
447        ) -> Retained<Self>;
448
449        #[unsafe(method(dataWithBytesNoCopy:length:))]
450        #[unsafe(method_family = none)]
451        pub unsafe fn dataWithBytesNoCopy_length(
452            bytes: NonNull<c_void>,
453            length: NSUInteger,
454        ) -> Retained<Self>;
455
456        #[unsafe(method(dataWithBytesNoCopy:length:freeWhenDone:))]
457        #[unsafe(method_family = none)]
458        pub unsafe fn dataWithBytesNoCopy_length_freeWhenDone(
459            bytes: NonNull<c_void>,
460            length: NSUInteger,
461            b: bool,
462        ) -> Retained<Self>;
463
464        #[cfg(all(feature = "NSError", feature = "NSString"))]
465        #[unsafe(method(dataWithContentsOfFile:options:error:_))]
466        #[unsafe(method_family = none)]
467        pub unsafe fn dataWithContentsOfFile_options_error(
468            path: &NSString,
469            read_options_mask: NSDataReadingOptions,
470        ) -> Result<Retained<Self>, Retained<NSError>>;
471
472        #[cfg(all(feature = "NSError", feature = "NSURL"))]
473        #[unsafe(method(dataWithContentsOfURL:options:error:_))]
474        #[unsafe(method_family = none)]
475        pub unsafe fn dataWithContentsOfURL_options_error(
476            url: &NSURL,
477            read_options_mask: NSDataReadingOptions,
478        ) -> Result<Retained<Self>, Retained<NSError>>;
479
480        #[cfg(feature = "NSString")]
481        #[unsafe(method(dataWithContentsOfFile:))]
482        #[unsafe(method_family = none)]
483        pub unsafe fn dataWithContentsOfFile(path: &NSString) -> Option<Retained<Self>>;
484
485        #[cfg(feature = "NSURL")]
486        #[unsafe(method(dataWithContentsOfURL:))]
487        #[unsafe(method_family = none)]
488        pub unsafe fn dataWithContentsOfURL(url: &NSURL) -> Option<Retained<Self>>;
489
490        #[unsafe(method(initWithBytes:length:))]
491        #[unsafe(method_family = init)]
492        pub unsafe fn initWithBytes_length(
493            this: Allocated<Self>,
494            bytes: *const c_void,
495            length: NSUInteger,
496        ) -> Retained<Self>;
497
498        #[unsafe(method(initWithBytesNoCopy:length:))]
499        #[unsafe(method_family = init)]
500        pub unsafe fn initWithBytesNoCopy_length(
501            this: Allocated<Self>,
502            bytes: NonNull<c_void>,
503            length: NSUInteger,
504        ) -> Retained<Self>;
505
506        #[unsafe(method(initWithBytesNoCopy:length:freeWhenDone:))]
507        #[unsafe(method_family = init)]
508        pub unsafe fn initWithBytesNoCopy_length_freeWhenDone(
509            this: Allocated<Self>,
510            bytes: NonNull<c_void>,
511            length: NSUInteger,
512            b: bool,
513        ) -> Retained<Self>;
514
515        #[cfg(feature = "block2")]
516        #[unsafe(method(initWithBytesNoCopy:length:deallocator:))]
517        #[unsafe(method_family = init)]
518        pub unsafe fn initWithBytesNoCopy_length_deallocator(
519            this: Allocated<Self>,
520            bytes: NonNull<c_void>,
521            length: NSUInteger,
522            deallocator: Option<&block2::DynBlock<dyn Fn(NonNull<c_void>, NSUInteger)>>,
523        ) -> Retained<Self>;
524
525        #[cfg(all(feature = "NSError", feature = "NSString"))]
526        #[unsafe(method(initWithContentsOfFile:options:error:_))]
527        #[unsafe(method_family = init)]
528        pub unsafe fn initWithContentsOfFile_options_error(
529            this: Allocated<Self>,
530            path: &NSString,
531            read_options_mask: NSDataReadingOptions,
532        ) -> Result<Retained<Self>, Retained<NSError>>;
533
534        #[cfg(all(feature = "NSError", feature = "NSURL"))]
535        #[unsafe(method(initWithContentsOfURL:options:error:_))]
536        #[unsafe(method_family = init)]
537        pub unsafe fn initWithContentsOfURL_options_error(
538            this: Allocated<Self>,
539            url: &NSURL,
540            read_options_mask: NSDataReadingOptions,
541        ) -> Result<Retained<Self>, Retained<NSError>>;
542
543        #[cfg(feature = "NSString")]
544        #[unsafe(method(initWithContentsOfFile:))]
545        #[unsafe(method_family = init)]
546        pub unsafe fn initWithContentsOfFile(
547            this: Allocated<Self>,
548            path: &NSString,
549        ) -> Option<Retained<Self>>;
550
551        #[cfg(feature = "NSURL")]
552        #[unsafe(method(initWithContentsOfURL:))]
553        #[unsafe(method_family = init)]
554        pub unsafe fn initWithContentsOfURL(
555            this: Allocated<Self>,
556            url: &NSURL,
557        ) -> Option<Retained<Self>>;
558
559        #[unsafe(method(initWithData:))]
560        #[unsafe(method_family = init)]
561        pub unsafe fn initWithData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
562
563        #[unsafe(method(dataWithData:))]
564        #[unsafe(method_family = none)]
565        pub fn dataWithData(data: &NSData) -> Retained<Self>;
566    );
567}
568
569/// NSDataBase64Encoding.
570impl NSData {
571    extern_methods!(
572        #[cfg(feature = "NSString")]
573        #[unsafe(method(initWithBase64EncodedString:options:))]
574        #[unsafe(method_family = init)]
575        pub unsafe fn initWithBase64EncodedString_options(
576            this: Allocated<Self>,
577            base64_string: &NSString,
578            options: NSDataBase64DecodingOptions,
579        ) -> Option<Retained<Self>>;
580
581        #[cfg(feature = "NSString")]
582        #[unsafe(method(base64EncodedStringWithOptions:))]
583        #[unsafe(method_family = none)]
584        pub unsafe fn base64EncodedStringWithOptions(
585            &self,
586            options: NSDataBase64EncodingOptions,
587        ) -> Retained<NSString>;
588
589        #[unsafe(method(initWithBase64EncodedData:options:))]
590        #[unsafe(method_family = init)]
591        pub unsafe fn initWithBase64EncodedData_options(
592            this: Allocated<Self>,
593            base64_data: &NSData,
594            options: NSDataBase64DecodingOptions,
595        ) -> Option<Retained<Self>>;
596
597        #[unsafe(method(base64EncodedDataWithOptions:))]
598        #[unsafe(method_family = none)]
599        pub unsafe fn base64EncodedDataWithOptions(
600            &self,
601            options: NSDataBase64EncodingOptions,
602        ) -> Retained<NSData>;
603    );
604}
605
606/// Methods declared on superclass `NSData`.
607///
608/// NSDataBase64Encoding.
609impl NSMutableData {
610    extern_methods!(
611        #[cfg(feature = "NSString")]
612        #[unsafe(method(initWithBase64EncodedString:options:))]
613        #[unsafe(method_family = init)]
614        pub unsafe fn initWithBase64EncodedString_options(
615            this: Allocated<Self>,
616            base64_string: &NSString,
617            options: NSDataBase64DecodingOptions,
618        ) -> Option<Retained<Self>>;
619
620        #[unsafe(method(initWithBase64EncodedData:options:))]
621        #[unsafe(method_family = init)]
622        pub unsafe fn initWithBase64EncodedData_options(
623            this: Allocated<Self>,
624            base64_data: &NSData,
625            options: NSDataBase64DecodingOptions,
626        ) -> Option<Retained<Self>>;
627    );
628}
629
630/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdatacompressionalgorithm?language=objc)
631// NS_ENUM
632#[repr(transparent)]
633#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
634pub struct NSDataCompressionAlgorithm(pub NSInteger);
635impl NSDataCompressionAlgorithm {
636    #[doc(alias = "NSDataCompressionAlgorithmLZFSE")]
637    pub const LZFSE: Self = Self(0);
638    #[doc(alias = "NSDataCompressionAlgorithmLZ4")]
639    pub const LZ4: Self = Self(1);
640    #[doc(alias = "NSDataCompressionAlgorithmLZMA")]
641    pub const LZMA: Self = Self(2);
642    #[doc(alias = "NSDataCompressionAlgorithmZlib")]
643    pub const Zlib: Self = Self(3);
644}
645
646unsafe impl Encode for NSDataCompressionAlgorithm {
647    const ENCODING: Encoding = NSInteger::ENCODING;
648}
649
650unsafe impl RefEncode for NSDataCompressionAlgorithm {
651    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
652}
653
654/// NSDataCompression.
655impl NSData {
656    extern_methods!(
657        #[cfg(feature = "NSError")]
658        #[unsafe(method(decompressedDataUsingAlgorithm:error:_))]
659        #[unsafe(method_family = none)]
660        pub unsafe fn decompressedDataUsingAlgorithm_error(
661            &self,
662            algorithm: NSDataCompressionAlgorithm,
663        ) -> Result<Retained<Self>, Retained<NSError>>;
664
665        #[cfg(feature = "NSError")]
666        #[unsafe(method(compressedDataUsingAlgorithm:error:_))]
667        #[unsafe(method_family = none)]
668        pub unsafe fn compressedDataUsingAlgorithm_error(
669            &self,
670            algorithm: NSDataCompressionAlgorithm,
671        ) -> Result<Retained<Self>, Retained<NSError>>;
672    );
673}
674
675/// NSDeprecated.
676impl NSData {
677    extern_methods!(
678        #[deprecated = "This method is unsafe because it could potentially cause buffer overruns. Use -getBytes:length: instead."]
679        #[unsafe(method(getBytes:))]
680        #[unsafe(method_family = none)]
681        pub unsafe fn getBytes(&self, buffer: NonNull<c_void>);
682
683        #[cfg(feature = "NSString")]
684        #[deprecated = "Use +dataWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead."]
685        #[unsafe(method(dataWithContentsOfMappedFile:))]
686        #[unsafe(method_family = none)]
687        pub unsafe fn dataWithContentsOfMappedFile(path: &NSString) -> Option<Retained<AnyObject>>;
688
689        #[cfg(feature = "NSString")]
690        #[deprecated = "Use -initWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead."]
691        #[unsafe(method(initWithContentsOfMappedFile:))]
692        #[unsafe(method_family = init)]
693        pub unsafe fn initWithContentsOfMappedFile(
694            this: Allocated<Self>,
695            path: &NSString,
696        ) -> Option<Retained<Self>>;
697
698        #[cfg(feature = "NSString")]
699        #[deprecated = "Use initWithBase64EncodedString:options: instead"]
700        #[unsafe(method(initWithBase64Encoding:))]
701        #[unsafe(method_family = init)]
702        pub unsafe fn initWithBase64Encoding(
703            this: Allocated<Self>,
704            base64_string: &NSString,
705        ) -> Option<Retained<Self>>;
706
707        #[cfg(feature = "NSString")]
708        #[deprecated = "Use base64EncodedStringWithOptions: instead"]
709        #[unsafe(method(base64Encoding))]
710        #[unsafe(method_family = none)]
711        pub unsafe fn base64Encoding(&self) -> Retained<NSString>;
712    );
713}
714
715/// Methods declared on superclass `NSData`.
716///
717/// NSDeprecated.
718impl NSMutableData {
719    extern_methods!(
720        #[cfg(feature = "NSString")]
721        #[deprecated = "Use -initWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead."]
722        #[unsafe(method(initWithContentsOfMappedFile:))]
723        #[unsafe(method_family = init)]
724        pub unsafe fn initWithContentsOfMappedFile(
725            this: Allocated<Self>,
726            path: &NSString,
727        ) -> Option<Retained<Self>>;
728
729        #[cfg(feature = "NSString")]
730        #[deprecated = "Use initWithBase64EncodedString:options: instead"]
731        #[unsafe(method(initWithBase64Encoding:))]
732        #[unsafe(method_family = init)]
733        pub unsafe fn initWithBase64Encoding(
734            this: Allocated<Self>,
735            base64_string: &NSString,
736        ) -> Option<Retained<Self>>;
737    );
738}
739
740extern_class!(
741    /// **************    Mutable Data        ***************
742    ///
743    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmutabledata?language=objc)
744    #[unsafe(super(NSData, NSObject))]
745    #[derive(Debug, PartialEq, Eq, Hash)]
746    pub struct NSMutableData;
747);
748
749#[cfg(feature = "NSObject")]
750extern_conformance!(
751    unsafe impl NSCoding for NSMutableData {}
752);
753
754#[cfg(feature = "NSObject")]
755extern_conformance!(
756    unsafe impl NSCopying for NSMutableData {}
757);
758
759#[cfg(feature = "NSObject")]
760unsafe impl CopyingHelper for NSMutableData {
761    type Result = NSData;
762}
763
764#[cfg(feature = "NSObject")]
765extern_conformance!(
766    unsafe impl NSMutableCopying for NSMutableData {}
767);
768
769#[cfg(feature = "NSObject")]
770unsafe impl MutableCopyingHelper for NSMutableData {
771    type Result = Self;
772}
773
774extern_conformance!(
775    unsafe impl NSObjectProtocol for NSMutableData {}
776);
777
778#[cfg(feature = "NSObject")]
779extern_conformance!(
780    unsafe impl NSSecureCoding for NSMutableData {}
781);
782
783impl NSMutableData {
784    extern_methods!(
785        /// Setter for [`length`][Self::length].
786        #[unsafe(method(setLength:))]
787        #[unsafe(method_family = none)]
788        pub fn setLength(&self, length: NSUInteger);
789    );
790}
791
792/// Methods declared on superclass `NSObject`.
793impl NSMutableData {
794    extern_methods!(
795        #[unsafe(method(init))]
796        #[unsafe(method_family = init)]
797        pub fn init(this: Allocated<Self>) -> Retained<Self>;
798
799        #[unsafe(method(new))]
800        #[unsafe(method_family = new)]
801        pub fn new() -> Retained<Self>;
802    );
803}
804
805impl DefaultRetained for NSMutableData {
806    #[inline]
807    fn default_retained() -> Retained<Self> {
808        Self::new()
809    }
810}
811
812/// NSExtendedMutableData.
813impl NSMutableData {
814    extern_methods!(
815        #[unsafe(method(appendBytes:length:))]
816        #[unsafe(method_family = none)]
817        pub unsafe fn appendBytes_length(&self, bytes: NonNull<c_void>, length: NSUInteger);
818
819        #[unsafe(method(appendData:))]
820        #[unsafe(method_family = none)]
821        pub unsafe fn appendData(&self, other: &NSData);
822
823        #[unsafe(method(increaseLengthBy:))]
824        #[unsafe(method_family = none)]
825        pub unsafe fn increaseLengthBy(&self, extra_length: NSUInteger);
826
827        #[cfg(feature = "NSRange")]
828        #[unsafe(method(replaceBytesInRange:withBytes:))]
829        #[unsafe(method_family = none)]
830        pub unsafe fn replaceBytesInRange_withBytes(&self, range: NSRange, bytes: NonNull<c_void>);
831
832        #[cfg(feature = "NSRange")]
833        #[unsafe(method(resetBytesInRange:))]
834        #[unsafe(method_family = none)]
835        pub unsafe fn resetBytesInRange(&self, range: NSRange);
836
837        #[unsafe(method(setData:))]
838        #[unsafe(method_family = none)]
839        pub unsafe fn setData(&self, data: &NSData);
840
841        #[cfg(feature = "NSRange")]
842        #[unsafe(method(replaceBytesInRange:withBytes:length:))]
843        #[unsafe(method_family = none)]
844        pub unsafe fn replaceBytesInRange_withBytes_length(
845            &self,
846            range: NSRange,
847            replacement_bytes: *const c_void,
848            replacement_length: NSUInteger,
849        );
850    );
851}
852
853/// NSMutableDataCreation.
854impl NSMutableData {
855    extern_methods!(
856        #[unsafe(method(dataWithCapacity:))]
857        #[unsafe(method_family = none)]
858        pub fn dataWithCapacity(a_num_items: NSUInteger) -> Option<Retained<Self>>;
859
860        #[unsafe(method(dataWithLength:))]
861        #[unsafe(method_family = none)]
862        pub unsafe fn dataWithLength(length: NSUInteger) -> Option<Retained<Self>>;
863
864        #[unsafe(method(initWithCapacity:))]
865        #[unsafe(method_family = init)]
866        pub fn initWithCapacity(
867            this: Allocated<Self>,
868            capacity: NSUInteger,
869        ) -> Option<Retained<Self>>;
870
871        #[unsafe(method(initWithLength:))]
872        #[unsafe(method_family = init)]
873        pub unsafe fn initWithLength(
874            this: Allocated<Self>,
875            length: NSUInteger,
876        ) -> Option<Retained<Self>>;
877    );
878}
879
880/// NSMutableDataCompression.
881impl NSMutableData {
882    extern_methods!(
883        #[cfg(feature = "NSError")]
884        #[unsafe(method(decompressUsingAlgorithm:error:_))]
885        #[unsafe(method_family = none)]
886        pub unsafe fn decompressUsingAlgorithm_error(
887            &self,
888            algorithm: NSDataCompressionAlgorithm,
889        ) -> Result<(), Retained<NSError>>;
890
891        #[cfg(feature = "NSError")]
892        #[unsafe(method(compressUsingAlgorithm:error:_))]
893        #[unsafe(method_family = none)]
894        pub unsafe fn compressUsingAlgorithm_error(
895            &self,
896            algorithm: NSDataCompressionAlgorithm,
897        ) -> Result<(), Retained<NSError>>;
898    );
899}
900
901extern_class!(
902    /// **************        Purgeable Data    ***************
903    ///
904    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nspurgeabledata?language=objc)
905    #[unsafe(super(NSMutableData, NSData, NSObject))]
906    #[derive(Debug, PartialEq, Eq, Hash)]
907    pub struct NSPurgeableData;
908);
909
910#[cfg(feature = "NSObject")]
911extern_conformance!(
912    unsafe impl NSCoding for NSPurgeableData {}
913);
914
915#[cfg(feature = "NSObject")]
916extern_conformance!(
917    unsafe impl NSDiscardableContent for NSPurgeableData {}
918);
919
920extern_conformance!(
921    unsafe impl NSObjectProtocol for NSPurgeableData {}
922);
923
924#[cfg(feature = "NSObject")]
925extern_conformance!(
926    unsafe impl NSSecureCoding for NSPurgeableData {}
927);
928
929impl NSPurgeableData {
930    extern_methods!();
931}
932
933/// Methods declared on superclass `NSObject`.
934impl NSPurgeableData {
935    extern_methods!(
936        #[unsafe(method(init))]
937        #[unsafe(method_family = init)]
938        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
939
940        #[unsafe(method(new))]
941        #[unsafe(method_family = new)]
942        pub unsafe fn new() -> Retained<Self>;
943    );
944}