objc2_core_foundation/generated/
CFData.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdata?language=objc)
13///
14/// This is toll-free bridged with `NSData`.
15#[doc(alias = "CFDataRef")]
16#[repr(C)]
17pub struct CFData {
18    inner: [u8; 0],
19    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
20}
21
22cf_type!(
23    unsafe impl CFData {}
24);
25#[cfg(feature = "objc2")]
26cf_objc2_type!(
27    unsafe impl RefEncode<"__CFData"> for CFData {}
28);
29
30/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutabledata?language=objc)
31///
32/// This is toll-free bridged with `NSMutableData`.
33#[doc(alias = "CFMutableDataRef")]
34#[repr(C)]
35pub struct CFMutableData {
36    inner: [u8; 0],
37    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
38}
39
40cf_type!(
41    unsafe impl CFMutableData: CFData {}
42);
43#[cfg(feature = "objc2")]
44cf_objc2_type!(
45    unsafe impl RefEncode<"__CFData"> for CFMutableData {}
46);
47
48unsafe impl ConcreteType for CFData {
49    #[doc(alias = "CFDataGetTypeID")]
50    #[inline]
51    fn type_id() -> CFTypeID {
52        extern "C-unwind" {
53            fn CFDataGetTypeID() -> CFTypeID;
54        }
55        unsafe { CFDataGetTypeID() }
56    }
57}
58
59impl CFData {
60    /// # Safety
61    ///
62    /// - `allocator` might not allow `None`.
63    /// - `bytes` must be a valid pointer.
64    #[doc(alias = "CFDataCreate")]
65    #[inline]
66    pub unsafe fn new(
67        allocator: Option<&CFAllocator>,
68        bytes: *const u8,
69        length: CFIndex,
70    ) -> Option<CFRetained<CFData>> {
71        extern "C-unwind" {
72            fn CFDataCreate(
73                allocator: Option<&CFAllocator>,
74                bytes: *const u8,
75                length: CFIndex,
76            ) -> Option<NonNull<CFData>>;
77        }
78        let ret = unsafe { CFDataCreate(allocator, bytes, length) };
79        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
80    }
81
82    /// # Safety
83    ///
84    /// - `allocator` might not allow `None`.
85    /// - `bytes` must be a valid pointer.
86    /// - `bytes_deallocator` might not allow `None`.
87    #[doc(alias = "CFDataCreateWithBytesNoCopy")]
88    #[inline]
89    pub unsafe fn with_bytes_no_copy(
90        allocator: Option<&CFAllocator>,
91        bytes: *const u8,
92        length: CFIndex,
93        bytes_deallocator: Option<&CFAllocator>,
94    ) -> Option<CFRetained<CFData>> {
95        extern "C-unwind" {
96            fn CFDataCreateWithBytesNoCopy(
97                allocator: Option<&CFAllocator>,
98                bytes: *const u8,
99                length: CFIndex,
100                bytes_deallocator: Option<&CFAllocator>,
101            ) -> Option<NonNull<CFData>>;
102        }
103        let ret =
104            unsafe { CFDataCreateWithBytesNoCopy(allocator, bytes, length, bytes_deallocator) };
105        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
106    }
107
108    #[doc(alias = "CFDataCreateCopy")]
109    #[inline]
110    pub fn new_copy(
111        allocator: Option<&CFAllocator>,
112        the_data: Option<&CFData>,
113    ) -> Option<CFRetained<CFData>> {
114        extern "C-unwind" {
115            fn CFDataCreateCopy(
116                allocator: Option<&CFAllocator>,
117                the_data: Option<&CFData>,
118            ) -> Option<NonNull<CFData>>;
119        }
120        let ret = unsafe { CFDataCreateCopy(allocator, the_data) };
121        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
122    }
123}
124
125impl CFMutableData {
126    #[doc(alias = "CFDataCreateMutable")]
127    #[inline]
128    pub fn new(
129        allocator: Option<&CFAllocator>,
130        capacity: CFIndex,
131    ) -> Option<CFRetained<CFMutableData>> {
132        extern "C-unwind" {
133            fn CFDataCreateMutable(
134                allocator: Option<&CFAllocator>,
135                capacity: CFIndex,
136            ) -> Option<NonNull<CFMutableData>>;
137        }
138        let ret = unsafe { CFDataCreateMutable(allocator, capacity) };
139        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
140    }
141
142    /// # Safety
143    ///
144    /// - `allocator` might not allow `None`.
145    /// - `the_data` might not allow `None`.
146    #[doc(alias = "CFDataCreateMutableCopy")]
147    #[inline]
148    pub unsafe fn new_copy(
149        allocator: Option<&CFAllocator>,
150        capacity: CFIndex,
151        the_data: Option<&CFData>,
152    ) -> Option<CFRetained<CFMutableData>> {
153        extern "C-unwind" {
154            fn CFDataCreateMutableCopy(
155                allocator: Option<&CFAllocator>,
156                capacity: CFIndex,
157                the_data: Option<&CFData>,
158            ) -> Option<NonNull<CFMutableData>>;
159        }
160        let ret = unsafe { CFDataCreateMutableCopy(allocator, capacity, the_data) };
161        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
162    }
163}
164
165impl CFData {
166    #[doc(alias = "CFDataGetLength")]
167    #[inline]
168    pub fn length(&self) -> CFIndex {
169        extern "C-unwind" {
170            fn CFDataGetLength(the_data: &CFData) -> CFIndex;
171        }
172        unsafe { CFDataGetLength(self) }
173    }
174
175    #[doc(alias = "CFDataGetBytePtr")]
176    #[inline]
177    pub fn byte_ptr(&self) -> *const u8 {
178        extern "C-unwind" {
179            fn CFDataGetBytePtr(the_data: &CFData) -> *const u8;
180        }
181        unsafe { CFDataGetBytePtr(self) }
182    }
183}
184
185impl CFMutableData {
186    #[doc(alias = "CFDataGetMutableBytePtr")]
187    #[inline]
188    pub fn mutable_byte_ptr(the_data: Option<&CFMutableData>) -> *mut u8 {
189        extern "C-unwind" {
190            fn CFDataGetMutableBytePtr(the_data: Option<&CFMutableData>) -> *mut u8;
191        }
192        unsafe { CFDataGetMutableBytePtr(the_data) }
193    }
194}
195
196impl CFData {
197    /// # Safety
198    ///
199    /// `buffer` must be a valid pointer.
200    #[doc(alias = "CFDataGetBytes")]
201    #[inline]
202    pub unsafe fn bytes(&self, range: CFRange, buffer: *mut u8) {
203        extern "C-unwind" {
204            fn CFDataGetBytes(the_data: &CFData, range: CFRange, buffer: *mut u8);
205        }
206        unsafe { CFDataGetBytes(self, range, buffer) }
207    }
208}
209
210impl CFMutableData {
211    #[doc(alias = "CFDataSetLength")]
212    #[inline]
213    pub fn set_length(the_data: Option<&CFMutableData>, length: CFIndex) {
214        extern "C-unwind" {
215            fn CFDataSetLength(the_data: Option<&CFMutableData>, length: CFIndex);
216        }
217        unsafe { CFDataSetLength(the_data, length) }
218    }
219
220    #[doc(alias = "CFDataIncreaseLength")]
221    #[inline]
222    pub fn increase_length(the_data: Option<&CFMutableData>, extra_length: CFIndex) {
223        extern "C-unwind" {
224            fn CFDataIncreaseLength(the_data: Option<&CFMutableData>, extra_length: CFIndex);
225        }
226        unsafe { CFDataIncreaseLength(the_data, extra_length) }
227    }
228
229    /// # Safety
230    ///
231    /// - `the_data` might not allow `None`.
232    /// - `bytes` must be a valid pointer.
233    #[doc(alias = "CFDataAppendBytes")]
234    #[inline]
235    pub unsafe fn append_bytes(
236        the_data: Option<&CFMutableData>,
237        bytes: *const u8,
238        length: CFIndex,
239    ) {
240        extern "C-unwind" {
241            fn CFDataAppendBytes(
242                the_data: Option<&CFMutableData>,
243                bytes: *const u8,
244                length: CFIndex,
245            );
246        }
247        unsafe { CFDataAppendBytes(the_data, bytes, length) }
248    }
249
250    /// # Safety
251    ///
252    /// - `the_data` might not allow `None`.
253    /// - `new_bytes` must be a valid pointer.
254    #[doc(alias = "CFDataReplaceBytes")]
255    #[inline]
256    pub unsafe fn replace_bytes(
257        the_data: Option<&CFMutableData>,
258        range: CFRange,
259        new_bytes: *const u8,
260        new_length: CFIndex,
261    ) {
262        extern "C-unwind" {
263            fn CFDataReplaceBytes(
264                the_data: Option<&CFMutableData>,
265                range: CFRange,
266                new_bytes: *const u8,
267                new_length: CFIndex,
268            );
269        }
270        unsafe { CFDataReplaceBytes(the_data, range, new_bytes, new_length) }
271    }
272
273    #[doc(alias = "CFDataDeleteBytes")]
274    #[inline]
275    pub fn delete_bytes(the_data: Option<&CFMutableData>, range: CFRange) {
276        extern "C-unwind" {
277            fn CFDataDeleteBytes(the_data: Option<&CFMutableData>, range: CFRange);
278        }
279        unsafe { CFDataDeleteBytes(the_data, range) }
280    }
281}
282
283/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdatasearchflags?language=objc)
284// NS_OPTIONS
285#[repr(transparent)]
286#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
287pub struct CFDataSearchFlags(pub CFOptionFlags);
288bitflags::bitflags! {
289    impl CFDataSearchFlags: CFOptionFlags {
290        #[doc(alias = "kCFDataSearchBackwards")]
291        const Backwards = 1<<0;
292        #[doc(alias = "kCFDataSearchAnchored")]
293        const Anchored = 1<<1;
294    }
295}
296
297#[cfg(feature = "objc2")]
298unsafe impl Encode for CFDataSearchFlags {
299    const ENCODING: Encoding = CFOptionFlags::ENCODING;
300}
301
302#[cfg(feature = "objc2")]
303unsafe impl RefEncode for CFDataSearchFlags {
304    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
305}
306
307impl CFData {
308    /// # Safety
309    ///
310    /// `data_to_find` might not allow `None`.
311    #[doc(alias = "CFDataFind")]
312    #[inline]
313    pub unsafe fn find(
314        &self,
315        data_to_find: Option<&CFData>,
316        search_range: CFRange,
317        compare_options: CFDataSearchFlags,
318    ) -> CFRange {
319        extern "C-unwind" {
320            fn CFDataFind(
321                the_data: &CFData,
322                data_to_find: Option<&CFData>,
323                search_range: CFRange,
324                compare_options: CFDataSearchFlags,
325            ) -> CFRange;
326        }
327        unsafe { CFDataFind(self, data_to_find, search_range, compare_options) }
328    }
329}
330
331#[deprecated = "renamed to `CFData::new`"]
332#[inline]
333pub unsafe extern "C-unwind" fn CFDataCreate(
334    allocator: Option<&CFAllocator>,
335    bytes: *const u8,
336    length: CFIndex,
337) -> Option<CFRetained<CFData>> {
338    extern "C-unwind" {
339        fn CFDataCreate(
340            allocator: Option<&CFAllocator>,
341            bytes: *const u8,
342            length: CFIndex,
343        ) -> Option<NonNull<CFData>>;
344    }
345    let ret = unsafe { CFDataCreate(allocator, bytes, length) };
346    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
347}
348
349#[deprecated = "renamed to `CFData::with_bytes_no_copy`"]
350#[inline]
351pub unsafe extern "C-unwind" fn CFDataCreateWithBytesNoCopy(
352    allocator: Option<&CFAllocator>,
353    bytes: *const u8,
354    length: CFIndex,
355    bytes_deallocator: Option<&CFAllocator>,
356) -> Option<CFRetained<CFData>> {
357    extern "C-unwind" {
358        fn CFDataCreateWithBytesNoCopy(
359            allocator: Option<&CFAllocator>,
360            bytes: *const u8,
361            length: CFIndex,
362            bytes_deallocator: Option<&CFAllocator>,
363        ) -> Option<NonNull<CFData>>;
364    }
365    let ret = unsafe { CFDataCreateWithBytesNoCopy(allocator, bytes, length, bytes_deallocator) };
366    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
367}
368
369#[deprecated = "renamed to `CFData::new_copy`"]
370#[inline]
371pub extern "C-unwind" fn CFDataCreateCopy(
372    allocator: Option<&CFAllocator>,
373    the_data: Option<&CFData>,
374) -> Option<CFRetained<CFData>> {
375    extern "C-unwind" {
376        fn CFDataCreateCopy(
377            allocator: Option<&CFAllocator>,
378            the_data: Option<&CFData>,
379        ) -> Option<NonNull<CFData>>;
380    }
381    let ret = unsafe { CFDataCreateCopy(allocator, the_data) };
382    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
383}
384
385#[deprecated = "renamed to `CFMutableData::new`"]
386#[inline]
387pub extern "C-unwind" fn CFDataCreateMutable(
388    allocator: Option<&CFAllocator>,
389    capacity: CFIndex,
390) -> Option<CFRetained<CFMutableData>> {
391    extern "C-unwind" {
392        fn CFDataCreateMutable(
393            allocator: Option<&CFAllocator>,
394            capacity: CFIndex,
395        ) -> Option<NonNull<CFMutableData>>;
396    }
397    let ret = unsafe { CFDataCreateMutable(allocator, capacity) };
398    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
399}
400
401#[deprecated = "renamed to `CFMutableData::new_copy`"]
402#[inline]
403pub unsafe extern "C-unwind" fn CFDataCreateMutableCopy(
404    allocator: Option<&CFAllocator>,
405    capacity: CFIndex,
406    the_data: Option<&CFData>,
407) -> Option<CFRetained<CFMutableData>> {
408    extern "C-unwind" {
409        fn CFDataCreateMutableCopy(
410            allocator: Option<&CFAllocator>,
411            capacity: CFIndex,
412            the_data: Option<&CFData>,
413        ) -> Option<NonNull<CFMutableData>>;
414    }
415    let ret = unsafe { CFDataCreateMutableCopy(allocator, capacity, the_data) };
416    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
417}
418
419#[deprecated = "renamed to `CFData::length`"]
420#[inline]
421pub extern "C-unwind" fn CFDataGetLength(the_data: &CFData) -> CFIndex {
422    extern "C-unwind" {
423        fn CFDataGetLength(the_data: &CFData) -> CFIndex;
424    }
425    unsafe { CFDataGetLength(the_data) }
426}
427
428#[deprecated = "renamed to `CFData::byte_ptr`"]
429#[inline]
430pub extern "C-unwind" fn CFDataGetBytePtr(the_data: &CFData) -> *const u8 {
431    extern "C-unwind" {
432        fn CFDataGetBytePtr(the_data: &CFData) -> *const u8;
433    }
434    unsafe { CFDataGetBytePtr(the_data) }
435}
436
437#[deprecated = "renamed to `CFMutableData::mutable_byte_ptr`"]
438#[inline]
439pub extern "C-unwind" fn CFDataGetMutableBytePtr(the_data: Option<&CFMutableData>) -> *mut u8 {
440    extern "C-unwind" {
441        fn CFDataGetMutableBytePtr(the_data: Option<&CFMutableData>) -> *mut u8;
442    }
443    unsafe { CFDataGetMutableBytePtr(the_data) }
444}
445
446extern "C-unwind" {
447    #[deprecated = "renamed to `CFData::bytes`"]
448    pub fn CFDataGetBytes(the_data: &CFData, range: CFRange, buffer: *mut u8);
449}
450
451#[deprecated = "renamed to `CFMutableData::set_length`"]
452#[inline]
453pub extern "C-unwind" fn CFDataSetLength(the_data: Option<&CFMutableData>, length: CFIndex) {
454    extern "C-unwind" {
455        fn CFDataSetLength(the_data: Option<&CFMutableData>, length: CFIndex);
456    }
457    unsafe { CFDataSetLength(the_data, length) }
458}
459
460#[deprecated = "renamed to `CFMutableData::increase_length`"]
461#[inline]
462pub extern "C-unwind" fn CFDataIncreaseLength(
463    the_data: Option<&CFMutableData>,
464    extra_length: CFIndex,
465) {
466    extern "C-unwind" {
467        fn CFDataIncreaseLength(the_data: Option<&CFMutableData>, extra_length: CFIndex);
468    }
469    unsafe { CFDataIncreaseLength(the_data, extra_length) }
470}
471
472extern "C-unwind" {
473    #[deprecated = "renamed to `CFMutableData::append_bytes`"]
474    pub fn CFDataAppendBytes(the_data: Option<&CFMutableData>, bytes: *const u8, length: CFIndex);
475}
476
477extern "C-unwind" {
478    #[deprecated = "renamed to `CFMutableData::replace_bytes`"]
479    pub fn CFDataReplaceBytes(
480        the_data: Option<&CFMutableData>,
481        range: CFRange,
482        new_bytes: *const u8,
483        new_length: CFIndex,
484    );
485}
486
487#[deprecated = "renamed to `CFMutableData::delete_bytes`"]
488#[inline]
489pub extern "C-unwind" fn CFDataDeleteBytes(the_data: Option<&CFMutableData>, range: CFRange) {
490    extern "C-unwind" {
491        fn CFDataDeleteBytes(the_data: Option<&CFMutableData>, range: CFRange);
492    }
493    unsafe { CFDataDeleteBytes(the_data, range) }
494}
495
496extern "C-unwind" {
497    #[deprecated = "renamed to `CFData::find`"]
498    pub fn CFDataFind(
499        the_data: &CFData,
500        data_to_find: Option<&CFData>,
501        search_range: CFRange,
502        compare_options: CFDataSearchFlags,
503    ) -> CFRange;
504}