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