1use 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 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#[deprecated]
25 #[doc(alias = "NSDataReadingMapped")]
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#[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#[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#[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#[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 #[unsafe(super(NSObject))]
155 #[derive(PartialEq, Eq, Hash)]
156 pub struct NSData;
157);
158
159#[cfg(feature = "NSObject")]
160unsafe impl NSCoding for NSData {}
161
162#[cfg(feature = "NSObject")]
163unsafe impl NSCopying for NSData {}
164
165#[cfg(feature = "NSObject")]
166unsafe impl CopyingHelper for NSData {
167 type Result = Self;
168}
169
170#[cfg(feature = "NSObject")]
171unsafe impl NSMutableCopying for NSData {}
172
173#[cfg(feature = "NSObject")]
174unsafe impl MutableCopyingHelper for NSData {
175 type Result = NSMutableData;
176}
177
178unsafe impl NSObjectProtocol for NSData {}
179
180#[cfg(feature = "NSObject")]
181unsafe impl NSSecureCoding for NSData {}
182
183impl NSData {
184 extern_methods!(
185 #[unsafe(method(length))]
186 #[unsafe(method_family = none)]
187 pub fn length(&self) -> NSUInteger;
188 );
189}
190
191impl NSData {
193 extern_methods!(
194 #[unsafe(method(init))]
195 #[unsafe(method_family = init)]
196 pub fn init(this: Allocated<Self>) -> Retained<Self>;
197
198 #[unsafe(method(new))]
199 #[unsafe(method_family = new)]
200 pub fn new() -> Retained<Self>;
201 );
202}
203
204impl DefaultRetained for NSData {
205 #[inline]
206 fn default_retained() -> Retained<Self> {
207 Self::new()
208 }
209}
210
211impl NSData {
213 extern_methods!(
214 #[cfg(feature = "NSString")]
215 #[unsafe(method(description))]
216 #[unsafe(method_family = none)]
217 pub unsafe fn description(&self) -> Retained<NSString>;
218
219 #[unsafe(method(getBytes:length:))]
220 #[unsafe(method_family = none)]
221 pub unsafe fn getBytes_length(&self, buffer: NonNull<c_void>, length: NSUInteger);
222
223 #[cfg(feature = "NSRange")]
224 #[unsafe(method(getBytes:range:))]
225 #[unsafe(method_family = none)]
226 pub unsafe fn getBytes_range(&self, buffer: NonNull<c_void>, range: NSRange);
227
228 #[unsafe(method(isEqualToData:))]
229 #[unsafe(method_family = none)]
230 pub unsafe fn isEqualToData(&self, other: &NSData) -> bool;
231
232 #[cfg(feature = "NSRange")]
233 #[unsafe(method(subdataWithRange:))]
234 #[unsafe(method_family = none)]
235 pub unsafe fn subdataWithRange(&self, range: NSRange) -> Retained<NSData>;
236
237 #[cfg(feature = "NSString")]
238 #[unsafe(method(writeToFile:atomically:))]
239 #[unsafe(method_family = none)]
240 pub unsafe fn writeToFile_atomically(
241 &self,
242 path: &NSString,
243 use_auxiliary_file: bool,
244 ) -> bool;
245
246 #[cfg(feature = "NSURL")]
247 #[unsafe(method(writeToURL:atomically:))]
248 #[unsafe(method_family = none)]
249 pub unsafe fn writeToURL_atomically(&self, url: &NSURL, atomically: bool) -> bool;
250
251 #[cfg(all(feature = "NSError", feature = "NSString"))]
252 #[unsafe(method(writeToFile:options:error:_))]
253 #[unsafe(method_family = none)]
254 pub unsafe fn writeToFile_options_error(
255 &self,
256 path: &NSString,
257 write_options_mask: NSDataWritingOptions,
258 ) -> Result<(), Retained<NSError>>;
259
260 #[cfg(all(feature = "NSError", feature = "NSURL"))]
261 #[unsafe(method(writeToURL:options:error:_))]
262 #[unsafe(method_family = none)]
263 pub unsafe fn writeToURL_options_error(
264 &self,
265 url: &NSURL,
266 write_options_mask: NSDataWritingOptions,
267 ) -> Result<(), Retained<NSError>>;
268
269 #[cfg(feature = "NSRange")]
270 #[unsafe(method(rangeOfData:options:range:))]
271 #[unsafe(method_family = none)]
272 pub unsafe fn rangeOfData_options_range(
273 &self,
274 data_to_find: &NSData,
275 mask: NSDataSearchOptions,
276 search_range: NSRange,
277 ) -> NSRange;
278
279 #[cfg(all(feature = "NSRange", feature = "block2"))]
280 #[unsafe(method(enumerateByteRangesUsingBlock:))]
281 #[unsafe(method_family = none)]
282 pub unsafe fn enumerateByteRangesUsingBlock(
283 &self,
284 block: &block2::Block<dyn Fn(NonNull<c_void>, NSRange, NonNull<Bool>) + '_>,
285 );
286 );
287}
288
289impl NSData {
291 extern_methods!(
292 #[unsafe(method(data))]
293 #[unsafe(method_family = none)]
294 pub unsafe fn data() -> Retained<Self>;
295
296 #[unsafe(method(dataWithBytes:length:))]
297 #[unsafe(method_family = none)]
298 pub unsafe fn dataWithBytes_length(
299 bytes: *const c_void,
300 length: NSUInteger,
301 ) -> Retained<Self>;
302
303 #[unsafe(method(dataWithBytesNoCopy:length:))]
304 #[unsafe(method_family = none)]
305 pub unsafe fn dataWithBytesNoCopy_length(
306 bytes: NonNull<c_void>,
307 length: NSUInteger,
308 ) -> Retained<Self>;
309
310 #[unsafe(method(dataWithBytesNoCopy:length:freeWhenDone:))]
311 #[unsafe(method_family = none)]
312 pub unsafe fn dataWithBytesNoCopy_length_freeWhenDone(
313 bytes: NonNull<c_void>,
314 length: NSUInteger,
315 b: bool,
316 ) -> Retained<Self>;
317
318 #[cfg(all(feature = "NSError", feature = "NSString"))]
319 #[unsafe(method(dataWithContentsOfFile:options:error:_))]
320 #[unsafe(method_family = none)]
321 pub unsafe fn dataWithContentsOfFile_options_error(
322 path: &NSString,
323 read_options_mask: NSDataReadingOptions,
324 ) -> Result<Retained<Self>, Retained<NSError>>;
325
326 #[cfg(all(feature = "NSError", feature = "NSURL"))]
327 #[unsafe(method(dataWithContentsOfURL:options:error:_))]
328 #[unsafe(method_family = none)]
329 pub unsafe fn dataWithContentsOfURL_options_error(
330 url: &NSURL,
331 read_options_mask: NSDataReadingOptions,
332 ) -> Result<Retained<Self>, Retained<NSError>>;
333
334 #[cfg(feature = "NSString")]
335 #[unsafe(method(dataWithContentsOfFile:))]
336 #[unsafe(method_family = none)]
337 pub unsafe fn dataWithContentsOfFile(path: &NSString) -> Option<Retained<Self>>;
338
339 #[cfg(feature = "NSURL")]
340 #[unsafe(method(dataWithContentsOfURL:))]
341 #[unsafe(method_family = none)]
342 pub unsafe fn dataWithContentsOfURL(url: &NSURL) -> Option<Retained<Self>>;
343
344 #[unsafe(method(initWithBytes:length:))]
345 #[unsafe(method_family = init)]
346 pub unsafe fn initWithBytes_length(
347 this: Allocated<Self>,
348 bytes: *const c_void,
349 length: NSUInteger,
350 ) -> Retained<Self>;
351
352 #[unsafe(method(initWithBytesNoCopy:length:))]
353 #[unsafe(method_family = init)]
354 pub unsafe fn initWithBytesNoCopy_length(
355 this: Allocated<Self>,
356 bytes: NonNull<c_void>,
357 length: NSUInteger,
358 ) -> Retained<Self>;
359
360 #[unsafe(method(initWithBytesNoCopy:length:freeWhenDone:))]
361 #[unsafe(method_family = init)]
362 pub unsafe fn initWithBytesNoCopy_length_freeWhenDone(
363 this: Allocated<Self>,
364 bytes: NonNull<c_void>,
365 length: NSUInteger,
366 b: bool,
367 ) -> Retained<Self>;
368
369 #[cfg(feature = "block2")]
370 #[unsafe(method(initWithBytesNoCopy:length:deallocator:))]
371 #[unsafe(method_family = init)]
372 pub unsafe fn initWithBytesNoCopy_length_deallocator(
373 this: Allocated<Self>,
374 bytes: NonNull<c_void>,
375 length: NSUInteger,
376 deallocator: Option<&block2::Block<dyn Fn(NonNull<c_void>, NSUInteger)>>,
377 ) -> Retained<Self>;
378
379 #[cfg(all(feature = "NSError", feature = "NSString"))]
380 #[unsafe(method(initWithContentsOfFile:options:error:_))]
381 #[unsafe(method_family = init)]
382 pub unsafe fn initWithContentsOfFile_options_error(
383 this: Allocated<Self>,
384 path: &NSString,
385 read_options_mask: NSDataReadingOptions,
386 ) -> Result<Retained<Self>, Retained<NSError>>;
387
388 #[cfg(all(feature = "NSError", feature = "NSURL"))]
389 #[unsafe(method(initWithContentsOfURL:options:error:_))]
390 #[unsafe(method_family = init)]
391 pub unsafe fn initWithContentsOfURL_options_error(
392 this: Allocated<Self>,
393 url: &NSURL,
394 read_options_mask: NSDataReadingOptions,
395 ) -> Result<Retained<Self>, Retained<NSError>>;
396
397 #[cfg(feature = "NSString")]
398 #[unsafe(method(initWithContentsOfFile:))]
399 #[unsafe(method_family = init)]
400 pub unsafe fn initWithContentsOfFile(
401 this: Allocated<Self>,
402 path: &NSString,
403 ) -> Option<Retained<Self>>;
404
405 #[cfg(feature = "NSURL")]
406 #[unsafe(method(initWithContentsOfURL:))]
407 #[unsafe(method_family = init)]
408 pub unsafe fn initWithContentsOfURL(
409 this: Allocated<Self>,
410 url: &NSURL,
411 ) -> Option<Retained<Self>>;
412
413 #[unsafe(method(initWithData:))]
414 #[unsafe(method_family = init)]
415 pub fn initWithData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
416
417 #[unsafe(method(dataWithData:))]
418 #[unsafe(method_family = none)]
419 pub fn dataWithData(data: &NSData) -> Retained<Self>;
420 );
421}
422
423impl NSMutableData {
427 extern_methods!(
428 #[unsafe(method(data))]
429 #[unsafe(method_family = none)]
430 pub unsafe fn data() -> Retained<Self>;
431
432 #[unsafe(method(dataWithBytes:length:))]
433 #[unsafe(method_family = none)]
434 pub unsafe fn dataWithBytes_length(
435 bytes: *const c_void,
436 length: NSUInteger,
437 ) -> Retained<Self>;
438
439 #[unsafe(method(dataWithBytesNoCopy:length:))]
440 #[unsafe(method_family = none)]
441 pub unsafe fn dataWithBytesNoCopy_length(
442 bytes: NonNull<c_void>,
443 length: NSUInteger,
444 ) -> Retained<Self>;
445
446 #[unsafe(method(dataWithBytesNoCopy:length:freeWhenDone:))]
447 #[unsafe(method_family = none)]
448 pub unsafe fn dataWithBytesNoCopy_length_freeWhenDone(
449 bytes: NonNull<c_void>,
450 length: NSUInteger,
451 b: bool,
452 ) -> Retained<Self>;
453
454 #[cfg(all(feature = "NSError", feature = "NSString"))]
455 #[unsafe(method(dataWithContentsOfFile:options:error:_))]
456 #[unsafe(method_family = none)]
457 pub unsafe fn dataWithContentsOfFile_options_error(
458 path: &NSString,
459 read_options_mask: NSDataReadingOptions,
460 ) -> Result<Retained<Self>, Retained<NSError>>;
461
462 #[cfg(all(feature = "NSError", feature = "NSURL"))]
463 #[unsafe(method(dataWithContentsOfURL:options:error:_))]
464 #[unsafe(method_family = none)]
465 pub unsafe fn dataWithContentsOfURL_options_error(
466 url: &NSURL,
467 read_options_mask: NSDataReadingOptions,
468 ) -> Result<Retained<Self>, Retained<NSError>>;
469
470 #[cfg(feature = "NSString")]
471 #[unsafe(method(dataWithContentsOfFile:))]
472 #[unsafe(method_family = none)]
473 pub unsafe fn dataWithContentsOfFile(path: &NSString) -> Option<Retained<Self>>;
474
475 #[cfg(feature = "NSURL")]
476 #[unsafe(method(dataWithContentsOfURL:))]
477 #[unsafe(method_family = none)]
478 pub unsafe fn dataWithContentsOfURL(url: &NSURL) -> Option<Retained<Self>>;
479
480 #[unsafe(method(initWithBytes:length:))]
481 #[unsafe(method_family = init)]
482 pub unsafe fn initWithBytes_length(
483 this: Allocated<Self>,
484 bytes: *const c_void,
485 length: NSUInteger,
486 ) -> Retained<Self>;
487
488 #[unsafe(method(initWithBytesNoCopy:length:))]
489 #[unsafe(method_family = init)]
490 pub unsafe fn initWithBytesNoCopy_length(
491 this: Allocated<Self>,
492 bytes: NonNull<c_void>,
493 length: NSUInteger,
494 ) -> Retained<Self>;
495
496 #[unsafe(method(initWithBytesNoCopy:length:freeWhenDone:))]
497 #[unsafe(method_family = init)]
498 pub unsafe fn initWithBytesNoCopy_length_freeWhenDone(
499 this: Allocated<Self>,
500 bytes: NonNull<c_void>,
501 length: NSUInteger,
502 b: bool,
503 ) -> Retained<Self>;
504
505 #[cfg(feature = "block2")]
506 #[unsafe(method(initWithBytesNoCopy:length:deallocator:))]
507 #[unsafe(method_family = init)]
508 pub unsafe fn initWithBytesNoCopy_length_deallocator(
509 this: Allocated<Self>,
510 bytes: NonNull<c_void>,
511 length: NSUInteger,
512 deallocator: Option<&block2::Block<dyn Fn(NonNull<c_void>, NSUInteger)>>,
513 ) -> Retained<Self>;
514
515 #[cfg(all(feature = "NSError", feature = "NSString"))]
516 #[unsafe(method(initWithContentsOfFile:options:error:_))]
517 #[unsafe(method_family = init)]
518 pub unsafe fn initWithContentsOfFile_options_error(
519 this: Allocated<Self>,
520 path: &NSString,
521 read_options_mask: NSDataReadingOptions,
522 ) -> Result<Retained<Self>, Retained<NSError>>;
523
524 #[cfg(all(feature = "NSError", feature = "NSURL"))]
525 #[unsafe(method(initWithContentsOfURL:options:error:_))]
526 #[unsafe(method_family = init)]
527 pub unsafe fn initWithContentsOfURL_options_error(
528 this: Allocated<Self>,
529 url: &NSURL,
530 read_options_mask: NSDataReadingOptions,
531 ) -> Result<Retained<Self>, Retained<NSError>>;
532
533 #[cfg(feature = "NSString")]
534 #[unsafe(method(initWithContentsOfFile:))]
535 #[unsafe(method_family = init)]
536 pub unsafe fn initWithContentsOfFile(
537 this: Allocated<Self>,
538 path: &NSString,
539 ) -> Option<Retained<Self>>;
540
541 #[cfg(feature = "NSURL")]
542 #[unsafe(method(initWithContentsOfURL:))]
543 #[unsafe(method_family = init)]
544 pub unsafe fn initWithContentsOfURL(
545 this: Allocated<Self>,
546 url: &NSURL,
547 ) -> Option<Retained<Self>>;
548
549 #[unsafe(method(initWithData:))]
550 #[unsafe(method_family = init)]
551 pub unsafe fn initWithData(this: Allocated<Self>, data: &NSData) -> Retained<Self>;
552
553 #[unsafe(method(dataWithData:))]
554 #[unsafe(method_family = none)]
555 pub fn dataWithData(data: &NSData) -> Retained<Self>;
556 );
557}
558
559impl NSData {
561 extern_methods!(
562 #[cfg(feature = "NSString")]
563 #[unsafe(method(initWithBase64EncodedString:options:))]
564 #[unsafe(method_family = init)]
565 pub unsafe fn initWithBase64EncodedString_options(
566 this: Allocated<Self>,
567 base64_string: &NSString,
568 options: NSDataBase64DecodingOptions,
569 ) -> Option<Retained<Self>>;
570
571 #[cfg(feature = "NSString")]
572 #[unsafe(method(base64EncodedStringWithOptions:))]
573 #[unsafe(method_family = none)]
574 pub unsafe fn base64EncodedStringWithOptions(
575 &self,
576 options: NSDataBase64EncodingOptions,
577 ) -> Retained<NSString>;
578
579 #[unsafe(method(initWithBase64EncodedData:options:))]
580 #[unsafe(method_family = init)]
581 pub unsafe fn initWithBase64EncodedData_options(
582 this: Allocated<Self>,
583 base64_data: &NSData,
584 options: NSDataBase64DecodingOptions,
585 ) -> Option<Retained<Self>>;
586
587 #[unsafe(method(base64EncodedDataWithOptions:))]
588 #[unsafe(method_family = none)]
589 pub unsafe fn base64EncodedDataWithOptions(
590 &self,
591 options: NSDataBase64EncodingOptions,
592 ) -> Retained<NSData>;
593 );
594}
595
596impl NSMutableData {
600 extern_methods!(
601 #[cfg(feature = "NSString")]
602 #[unsafe(method(initWithBase64EncodedString:options:))]
603 #[unsafe(method_family = init)]
604 pub unsafe fn initWithBase64EncodedString_options(
605 this: Allocated<Self>,
606 base64_string: &NSString,
607 options: NSDataBase64DecodingOptions,
608 ) -> Option<Retained<Self>>;
609
610 #[unsafe(method(initWithBase64EncodedData:options:))]
611 #[unsafe(method_family = init)]
612 pub unsafe fn initWithBase64EncodedData_options(
613 this: Allocated<Self>,
614 base64_data: &NSData,
615 options: NSDataBase64DecodingOptions,
616 ) -> Option<Retained<Self>>;
617 );
618}
619
620#[repr(transparent)]
623#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
624pub struct NSDataCompressionAlgorithm(pub NSInteger);
625impl NSDataCompressionAlgorithm {
626 #[doc(alias = "NSDataCompressionAlgorithmLZFSE")]
627 pub const LZFSE: Self = Self(0);
628 #[doc(alias = "NSDataCompressionAlgorithmLZ4")]
629 pub const LZ4: Self = Self(1);
630 #[doc(alias = "NSDataCompressionAlgorithmLZMA")]
631 pub const LZMA: Self = Self(2);
632 #[doc(alias = "NSDataCompressionAlgorithmZlib")]
633 pub const Zlib: Self = Self(3);
634}
635
636unsafe impl Encode for NSDataCompressionAlgorithm {
637 const ENCODING: Encoding = NSInteger::ENCODING;
638}
639
640unsafe impl RefEncode for NSDataCompressionAlgorithm {
641 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
642}
643
644impl NSData {
646 extern_methods!(
647 #[cfg(feature = "NSError")]
648 #[unsafe(method(decompressedDataUsingAlgorithm:error:_))]
649 #[unsafe(method_family = none)]
650 pub unsafe fn decompressedDataUsingAlgorithm_error(
651 &self,
652 algorithm: NSDataCompressionAlgorithm,
653 ) -> Result<Retained<Self>, Retained<NSError>>;
654
655 #[cfg(feature = "NSError")]
656 #[unsafe(method(compressedDataUsingAlgorithm:error:_))]
657 #[unsafe(method_family = none)]
658 pub unsafe fn compressedDataUsingAlgorithm_error(
659 &self,
660 algorithm: NSDataCompressionAlgorithm,
661 ) -> Result<Retained<Self>, Retained<NSError>>;
662 );
663}
664
665impl NSData {
667 extern_methods!(
668 #[deprecated = "This method is unsafe because it could potentially cause buffer overruns. Use -getBytes:length: instead."]
669 #[unsafe(method(getBytes:))]
670 #[unsafe(method_family = none)]
671 pub unsafe fn getBytes(&self, buffer: NonNull<c_void>);
672
673 #[cfg(feature = "NSString")]
674 #[deprecated = "Use +dataWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead."]
675 #[unsafe(method(dataWithContentsOfMappedFile:))]
676 #[unsafe(method_family = none)]
677 pub unsafe fn dataWithContentsOfMappedFile(path: &NSString) -> Option<Retained<AnyObject>>;
678
679 #[cfg(feature = "NSString")]
680 #[deprecated = "Use -initWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead."]
681 #[unsafe(method(initWithContentsOfMappedFile:))]
682 #[unsafe(method_family = init)]
683 pub unsafe fn initWithContentsOfMappedFile(
684 this: Allocated<Self>,
685 path: &NSString,
686 ) -> Option<Retained<Self>>;
687
688 #[cfg(feature = "NSString")]
689 #[deprecated = "Use initWithBase64EncodedString:options: instead"]
690 #[unsafe(method(initWithBase64Encoding:))]
691 #[unsafe(method_family = init)]
692 pub unsafe fn initWithBase64Encoding(
693 this: Allocated<Self>,
694 base64_string: &NSString,
695 ) -> Option<Retained<Self>>;
696
697 #[cfg(feature = "NSString")]
698 #[deprecated = "Use base64EncodedStringWithOptions: instead"]
699 #[unsafe(method(base64Encoding))]
700 #[unsafe(method_family = none)]
701 pub unsafe fn base64Encoding(&self) -> Retained<NSString>;
702 );
703}
704
705impl NSMutableData {
709 extern_methods!(
710 #[cfg(feature = "NSString")]
711 #[deprecated = "Use -initWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead."]
712 #[unsafe(method(initWithContentsOfMappedFile:))]
713 #[unsafe(method_family = init)]
714 pub unsafe fn initWithContentsOfMappedFile(
715 this: Allocated<Self>,
716 path: &NSString,
717 ) -> Option<Retained<Self>>;
718
719 #[cfg(feature = "NSString")]
720 #[deprecated = "Use initWithBase64EncodedString:options: instead"]
721 #[unsafe(method(initWithBase64Encoding:))]
722 #[unsafe(method_family = init)]
723 pub unsafe fn initWithBase64Encoding(
724 this: Allocated<Self>,
725 base64_string: &NSString,
726 ) -> Option<Retained<Self>>;
727 );
728}
729
730extern_class!(
731 #[unsafe(super(NSData, NSObject))]
735 #[derive(Debug, PartialEq, Eq, Hash)]
736 pub struct NSMutableData;
737);
738
739#[cfg(feature = "NSObject")]
740unsafe impl NSCoding for NSMutableData {}
741
742#[cfg(feature = "NSObject")]
743unsafe impl NSCopying for NSMutableData {}
744
745#[cfg(feature = "NSObject")]
746unsafe impl CopyingHelper for NSMutableData {
747 type Result = NSData;
748}
749
750#[cfg(feature = "NSObject")]
751unsafe impl NSMutableCopying for NSMutableData {}
752
753#[cfg(feature = "NSObject")]
754unsafe impl MutableCopyingHelper for NSMutableData {
755 type Result = Self;
756}
757
758unsafe impl NSObjectProtocol for NSMutableData {}
759
760#[cfg(feature = "NSObject")]
761unsafe impl NSSecureCoding for NSMutableData {}
762
763impl NSMutableData {
764 extern_methods!(
765 #[unsafe(method(setLength:))]
767 #[unsafe(method_family = none)]
768 pub fn setLength(&self, length: NSUInteger);
769 );
770}
771
772impl NSMutableData {
774 extern_methods!(
775 #[unsafe(method(init))]
776 #[unsafe(method_family = init)]
777 pub fn init(this: Allocated<Self>) -> Retained<Self>;
778
779 #[unsafe(method(new))]
780 #[unsafe(method_family = new)]
781 pub fn new() -> Retained<Self>;
782 );
783}
784
785impl DefaultRetained for NSMutableData {
786 #[inline]
787 fn default_retained() -> Retained<Self> {
788 Self::new()
789 }
790}
791
792impl NSMutableData {
794 extern_methods!(
795 #[unsafe(method(appendBytes:length:))]
796 #[unsafe(method_family = none)]
797 pub unsafe fn appendBytes_length(&self, bytes: NonNull<c_void>, length: NSUInteger);
798
799 #[unsafe(method(appendData:))]
800 #[unsafe(method_family = none)]
801 pub unsafe fn appendData(&self, other: &NSData);
802
803 #[unsafe(method(increaseLengthBy:))]
804 #[unsafe(method_family = none)]
805 pub unsafe fn increaseLengthBy(&self, extra_length: NSUInteger);
806
807 #[cfg(feature = "NSRange")]
808 #[unsafe(method(replaceBytesInRange:withBytes:))]
809 #[unsafe(method_family = none)]
810 pub unsafe fn replaceBytesInRange_withBytes(&self, range: NSRange, bytes: NonNull<c_void>);
811
812 #[cfg(feature = "NSRange")]
813 #[unsafe(method(resetBytesInRange:))]
814 #[unsafe(method_family = none)]
815 pub unsafe fn resetBytesInRange(&self, range: NSRange);
816
817 #[unsafe(method(setData:))]
818 #[unsafe(method_family = none)]
819 pub unsafe fn setData(&self, data: &NSData);
820
821 #[cfg(feature = "NSRange")]
822 #[unsafe(method(replaceBytesInRange:withBytes:length:))]
823 #[unsafe(method_family = none)]
824 pub unsafe fn replaceBytesInRange_withBytes_length(
825 &self,
826 range: NSRange,
827 replacement_bytes: *const c_void,
828 replacement_length: NSUInteger,
829 );
830 );
831}
832
833impl NSMutableData {
835 extern_methods!(
836 #[unsafe(method(dataWithCapacity:))]
837 #[unsafe(method_family = none)]
838 pub fn dataWithCapacity(a_num_items: NSUInteger) -> Option<Retained<Self>>;
839
840 #[unsafe(method(dataWithLength:))]
841 #[unsafe(method_family = none)]
842 pub unsafe fn dataWithLength(length: NSUInteger) -> Option<Retained<Self>>;
843
844 #[unsafe(method(initWithCapacity:))]
845 #[unsafe(method_family = init)]
846 pub fn initWithCapacity(
847 this: Allocated<Self>,
848 capacity: NSUInteger,
849 ) -> Option<Retained<Self>>;
850
851 #[unsafe(method(initWithLength:))]
852 #[unsafe(method_family = init)]
853 pub unsafe fn initWithLength(
854 this: Allocated<Self>,
855 length: NSUInteger,
856 ) -> Option<Retained<Self>>;
857 );
858}
859
860impl NSMutableData {
862 extern_methods!(
863 #[cfg(feature = "NSError")]
864 #[unsafe(method(decompressUsingAlgorithm:error:_))]
865 #[unsafe(method_family = none)]
866 pub unsafe fn decompressUsingAlgorithm_error(
867 &self,
868 algorithm: NSDataCompressionAlgorithm,
869 ) -> Result<(), Retained<NSError>>;
870
871 #[cfg(feature = "NSError")]
872 #[unsafe(method(compressUsingAlgorithm:error:_))]
873 #[unsafe(method_family = none)]
874 pub unsafe fn compressUsingAlgorithm_error(
875 &self,
876 algorithm: NSDataCompressionAlgorithm,
877 ) -> Result<(), Retained<NSError>>;
878 );
879}
880
881extern_class!(
882 #[unsafe(super(NSMutableData, NSData, NSObject))]
886 #[derive(Debug, PartialEq, Eq, Hash)]
887 pub struct NSPurgeableData;
888);
889
890#[cfg(feature = "NSObject")]
891unsafe impl NSCoding for NSPurgeableData {}
892
893#[cfg(feature = "NSObject")]
894unsafe impl NSDiscardableContent for NSPurgeableData {}
895
896unsafe impl NSObjectProtocol for NSPurgeableData {}
897
898#[cfg(feature = "NSObject")]
899unsafe impl NSSecureCoding for NSPurgeableData {}
900
901impl NSPurgeableData {
902 extern_methods!();
903}
904
905impl NSPurgeableData {
907 extern_methods!(
908 #[unsafe(method(init))]
909 #[unsafe(method_family = init)]
910 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
911
912 #[unsafe(method(new))]
913 #[unsafe(method_family = new)]
914 pub unsafe fn new() -> Retained<Self>;
915 );
916}