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    #[encoding_name = "__CFData"]
21    unsafe impl CFData {}
22);
23
24/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutabledata?language=objc)
25#[repr(C)]
26pub struct CFMutableData {
27    inner: [u8; 0],
28    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
29}
30
31cf_type!(
32    #[encoding_name = "__CFData"]
33    unsafe impl CFMutableData: CFData {}
34);
35
36#[cfg(feature = "CFBase")]
37unsafe impl ConcreteType for CFData {
38    #[doc(alias = "CFDataGetTypeID")]
39    #[inline]
40    fn type_id() -> CFTypeID {
41        extern "C-unwind" {
42            fn CFDataGetTypeID() -> CFTypeID;
43        }
44        unsafe { CFDataGetTypeID() }
45    }
46}
47
48#[cfg(feature = "CFBase")]
49#[inline]
50pub unsafe extern "C-unwind" fn CFDataCreate(
51    allocator: Option<&CFAllocator>,
52    bytes: *const u8,
53    length: CFIndex,
54) -> Option<CFRetained<CFData>> {
55    extern "C-unwind" {
56        fn CFDataCreate(
57            allocator: Option<&CFAllocator>,
58            bytes: *const u8,
59            length: CFIndex,
60        ) -> Option<NonNull<CFData>>;
61    }
62    let ret = unsafe { CFDataCreate(allocator, bytes, length) };
63    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
64}
65
66#[cfg(feature = "CFBase")]
67#[inline]
68pub unsafe extern "C-unwind" fn CFDataCreateWithBytesNoCopy(
69    allocator: Option<&CFAllocator>,
70    bytes: *const u8,
71    length: CFIndex,
72    bytes_deallocator: Option<&CFAllocator>,
73) -> Option<CFRetained<CFData>> {
74    extern "C-unwind" {
75        fn CFDataCreateWithBytesNoCopy(
76            allocator: Option<&CFAllocator>,
77            bytes: *const u8,
78            length: CFIndex,
79            bytes_deallocator: Option<&CFAllocator>,
80        ) -> Option<NonNull<CFData>>;
81    }
82    let ret = unsafe { CFDataCreateWithBytesNoCopy(allocator, bytes, length, bytes_deallocator) };
83    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
84}
85
86#[cfg(feature = "CFBase")]
87#[inline]
88pub unsafe extern "C-unwind" fn CFDataCreateCopy(
89    allocator: Option<&CFAllocator>,
90    the_data: Option<&CFData>,
91) -> Option<CFRetained<CFData>> {
92    extern "C-unwind" {
93        fn CFDataCreateCopy(
94            allocator: Option<&CFAllocator>,
95            the_data: Option<&CFData>,
96        ) -> Option<NonNull<CFData>>;
97    }
98    let ret = unsafe { CFDataCreateCopy(allocator, the_data) };
99    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
100}
101
102#[cfg(feature = "CFBase")]
103#[inline]
104pub unsafe extern "C-unwind" fn CFDataCreateMutable(
105    allocator: Option<&CFAllocator>,
106    capacity: CFIndex,
107) -> Option<CFRetained<CFMutableData>> {
108    extern "C-unwind" {
109        fn CFDataCreateMutable(
110            allocator: Option<&CFAllocator>,
111            capacity: CFIndex,
112        ) -> Option<NonNull<CFMutableData>>;
113    }
114    let ret = unsafe { CFDataCreateMutable(allocator, capacity) };
115    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
116}
117
118#[cfg(feature = "CFBase")]
119#[inline]
120pub unsafe extern "C-unwind" fn CFDataCreateMutableCopy(
121    allocator: Option<&CFAllocator>,
122    capacity: CFIndex,
123    the_data: Option<&CFData>,
124) -> Option<CFRetained<CFMutableData>> {
125    extern "C-unwind" {
126        fn CFDataCreateMutableCopy(
127            allocator: Option<&CFAllocator>,
128            capacity: CFIndex,
129            the_data: Option<&CFData>,
130        ) -> Option<NonNull<CFMutableData>>;
131    }
132    let ret = unsafe { CFDataCreateMutableCopy(allocator, capacity, the_data) };
133    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
134}
135
136extern "C-unwind" {
137    #[cfg(feature = "CFBase")]
138    pub fn CFDataGetLength(the_data: &CFData) -> CFIndex;
139}
140
141extern "C-unwind" {
142    pub fn CFDataGetBytePtr(the_data: &CFData) -> *const u8;
143}
144
145extern "C-unwind" {
146    pub fn CFDataGetMutableBytePtr(the_data: Option<&CFMutableData>) -> *mut u8;
147}
148
149extern "C-unwind" {
150    #[cfg(feature = "CFBase")]
151    pub fn CFDataGetBytes(the_data: &CFData, range: CFRange, buffer: *mut u8);
152}
153
154extern "C-unwind" {
155    #[cfg(feature = "CFBase")]
156    pub fn CFDataSetLength(the_data: Option<&CFMutableData>, length: CFIndex);
157}
158
159extern "C-unwind" {
160    #[cfg(feature = "CFBase")]
161    pub fn CFDataIncreaseLength(the_data: Option<&CFMutableData>, extra_length: CFIndex);
162}
163
164extern "C-unwind" {
165    #[cfg(feature = "CFBase")]
166    pub fn CFDataAppendBytes(the_data: Option<&CFMutableData>, bytes: *const u8, length: CFIndex);
167}
168
169extern "C-unwind" {
170    #[cfg(feature = "CFBase")]
171    pub fn CFDataReplaceBytes(
172        the_data: Option<&CFMutableData>,
173        range: CFRange,
174        new_bytes: *const u8,
175        new_length: CFIndex,
176    );
177}
178
179extern "C-unwind" {
180    #[cfg(feature = "CFBase")]
181    pub fn CFDataDeleteBytes(the_data: Option<&CFMutableData>, range: CFRange);
182}
183
184/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfdatasearchflags?language=objc)
185// NS_OPTIONS
186#[cfg(feature = "CFBase")]
187#[repr(transparent)]
188#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
189pub struct CFDataSearchFlags(pub CFOptionFlags);
190#[cfg(feature = "CFBase")]
191bitflags::bitflags! {
192    impl CFDataSearchFlags: CFOptionFlags {
193        #[doc(alias = "kCFDataSearchBackwards")]
194        const Backwards = 1<<0;
195        #[doc(alias = "kCFDataSearchAnchored")]
196        const Anchored = 1<<1;
197    }
198}
199
200#[cfg(all(feature = "CFBase", feature = "objc2"))]
201unsafe impl Encode for CFDataSearchFlags {
202    const ENCODING: Encoding = CFOptionFlags::ENCODING;
203}
204
205#[cfg(all(feature = "CFBase", feature = "objc2"))]
206unsafe impl RefEncode for CFDataSearchFlags {
207    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
208}
209
210extern "C-unwind" {
211    #[cfg(feature = "CFBase")]
212    pub fn CFDataFind(
213        the_data: &CFData,
214        data_to_find: Option<&CFData>,
215        search_range: CFRange,
216        compare_options: CFDataSearchFlags,
217    ) -> CFRange;
218}