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