objc2_io_bluetooth/generated/objc2/
IOBluetoothSDPDataElement.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5#[cfg(feature = "objc2-foundation")]
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// An instance of this class represents a single SDP data element as defined by the Bluetooth SDP spec.
12    ///
13    /// The data types described by the spec have been mapped onto the base Foundation classes NSNumber,
14    /// NSArray, NSData as well as IOBluetoothSDPUUID.  The number and boolean types (type descriptor 1, 2
15    /// and 5) are represented as NSNumber objects with the exception of 128-bit numbers which are
16    /// represented as NSData objects in their raw format.  The UUID type (type descriptor 3) is
17    /// represented by IOBluetoothSDPUUID.  The string and URL types (type descriptor 4 and 8) are
18    /// represented by NSString.  The sequence types (type descriptor 6 and 7) are represented by NSArray.
19    ///
20    /// Typically, you will not need to create an IOBluetoothSDPDataElement directly, the system will
21    /// do that automatically for both client and server operations.  However, the current API for adding
22    /// SDP services to the system does allow the use of an NSDictionary based format for creating new
23    /// services.  The purpose for that is to allow a service to be built up completely in a text file
24    /// (a plist for example) and then easily imported into an app and added to the system without a
25    /// lot of tedious code to build up the entire SDP service record.
26    ///
27    /// The basis for that NSDictionary structure comes from the IOBluetoothSDPDataElement.  At its
28    /// simplest, a data element is made up of three parts: the type descriptor, the size (from which
29    /// the size descriptor is generated) and the actual value.  To provide a complete representation
30    /// of a data element, an NSDictionary with three entries can be used.  Each of the three entries
31    /// has a key/value pair representing one of the three attributes of a data element.  The first
32    /// key/value pair has a key 'DataElementType' that contains a number value with the actual
33    /// type descriptor for the data element.  The second pair has a key 'DataElementSize' that
34    /// contains the actual size of the element in bytes.  The size descriptor will be calculated
35    /// based on the size and type of the element.  The third pair is the value itself whose key is
36    /// 'DataElementValue' and whose type corresponds to the type mapping above.
37    ///
38    /// In addition to this complete description of a data element, their are some shortcuts that
39    /// can be used for some of the common types and sizes.
40    ///
41    /// If the 'DataElementType' value is one of the numeric types (1, 2), the 'DataElementValue'
42    /// can be an NSData instead of an NSNumber.  In that case, the numeric data is taken in network
43    /// byte order (MSB first).  Additionally, the 'DataElementSize' parameter may be omitted and the
44    /// size will be taken from the length of the data object.
45    ///
46    /// If the 'DataElementType' value is the nil type (0), no 'DataElementSize' or 'DataElementValue'
47    /// entries are needed.
48    ///
49    /// If the 'DataElementType' value is any of the other types, the 'DataElementSize' entry is not
50    /// needed since the size will be taken directly from the value (data, array, string).
51    ///
52    /// In the case where the element is an unsigned, 32-bit integer (type descriptor 1, size descriptor
53    /// 4), the value itself may simply be a number (instead of a dictionary as in the previous examples).
54    ///
55    /// In the case where the element is a UUID (type descriptor 3), the value itself may be a data object.
56    /// The UUID type will be inferred and the size taken from the length of the data object.
57    ///
58    /// In the case where the element is a text string (type descriptor 4), the value may be a string object.
59    /// The text string type will be inferred and the size taken from the length of the string.
60    ///
61    /// In the case where the element is a data element sequence, the value may be an array object.  The
62    /// type will be inferred and the size taken from the length of the array.  Additionally, the array
63    /// must contain sub-elements that will be parsed out individually.
64    ///
65    /// See also [Apple's documentation](https://developer.apple.com/documentation/iobluetooth/iobluetoothsdpdataelement?language=objc)
66    #[unsafe(super(NSObject))]
67    #[derive(Debug, PartialEq, Eq, Hash)]
68    pub struct IOBluetoothSDPDataElement;
69);
70
71#[cfg(feature = "objc2-foundation")]
72extern_conformance!(
73    unsafe impl NSCoding for IOBluetoothSDPDataElement {}
74);
75
76extern_conformance!(
77    unsafe impl NSObjectProtocol for IOBluetoothSDPDataElement {}
78);
79
80#[cfg(feature = "objc2-foundation")]
81extern_conformance!(
82    unsafe impl NSSecureCoding for IOBluetoothSDPDataElement {}
83);
84
85impl IOBluetoothSDPDataElement {
86    extern_methods!(
87        /// Creates a new IOBluetoothSDPDataElement with the given value.
88        ///
89        /// The value must follow the format listed above and must be an instance of NSData, NSString, NSNumber,
90        /// NSArray, NSDictionary, IOBluetoothSDPUUID.
91        ///
92        /// Parameter `element`: The data element value of one of the specified types.
93        ///
94        /// Returns: Returns the newly allocated data element object.  Returns nil if there was an error parsing the element
95        /// value.  The returned IOBluetoothSDPDataElement object has been autoreleased, so it is not necessary
96        /// for the caller to release it.  If the object is to be referenced and kept around, retain should be
97        /// called.
98        ///
99        /// # Safety
100        ///
101        /// - `element` should be of the correct type.
102        /// - `element` might not allow `None`.
103        #[unsafe(method(withElementValue:))]
104        #[unsafe(method_family = none)]
105        pub unsafe fn withElementValue(element: Option<&NSObject>) -> Option<Retained<Self>>;
106
107        #[cfg(feature = "Bluetooth")]
108        /// Creates a new IOBluetoothSDPDataElement with the given attributes.
109        ///
110        /// Warning - be careful using this method.  There is next to no error checking done on the
111        /// attributes.  It is entirely possible to construct an invalid data element.  It is recommended
112        /// that +withElementValue: be used instead of this one.
113        ///
114        /// Parameter `typeDescriptor`: The type descriptor for the data element.
115        ///
116        /// Parameter `sizeDescriptor`: The size descriptor for the data element (verify it matches the size parameter).
117        ///
118        /// Parameter `size`: The size of the data element in bytes (make sure it is a valid size for the given size descriptor).
119        ///
120        /// Parameter `value`: The raw value itself.  This must be the base NSString, NSNumber, NSArray or NSData objects.  It
121        /// may not be NSDictionary.  If a dictionary format is present, use +withElementValue:.
122        ///
123        /// Returns: Returns the newly allocated data element object.  Returns nil if an error is encountered (not likely
124        /// due to the limited error checking currently done).  The returned IOBluetoothSDPDataElement
125        /// object has been autoreleased, so it is not necessary for the caller to release it.  If the
126        /// object is to be referenced and kept around, retain should be called.
127        ///
128        /// # Safety
129        ///
130        /// - `new_value` should be of the correct type.
131        /// - `new_value` might not allow `None`.
132        #[unsafe(method(withType:sizeDescriptor:size:value:))]
133        #[unsafe(method_family = none)]
134        pub unsafe fn withType_sizeDescriptor_size_value(
135            r#type: BluetoothSDPDataElementTypeDescriptor,
136            new_size_descriptor: BluetoothSDPDataElementSizeDescriptor,
137            new_size: u32,
138            new_value: Option<&NSObject>,
139        ) -> Option<Retained<Self>>;
140
141        #[cfg(feature = "IOBluetoothUserLib")]
142        /// Method call to convert an IOBluetoothSDPDataElementRef into an IOBluetoothSDPDataElement *.
143        ///
144        /// Parameter `sdpDataElementRef`: IOBluetoothSDPDataElementRef for which an IOBluetoothSDPDataElement * is desired.
145        ///
146        /// Returns: Returns the IOBluetoothSDPDataElement * for the given IOBluetoothSDPDataElementRef.
147        ///
148        /// # Safety
149        ///
150        /// `sdp_data_element_ref` might not allow `None`.
151        #[unsafe(method(withSDPDataElementRef:))]
152        #[unsafe(method_family = none)]
153        pub unsafe fn withSDPDataElementRef(
154            sdp_data_element_ref: Option<&IOBluetoothSDPDataElementRef>,
155        ) -> Option<Retained<Self>>;
156
157        /// Initializes a new IOBluetoothSDPDataElement with the given value.
158        ///
159        /// The value must follow the format listed above and must be an instance of NSData, NSString, NSNumber,
160        /// NSArray, NSDictionary, IOBluetoothSDPUUID.
161        ///
162        /// Parameter `element`: The data element value of one of the specified types.
163        ///
164        /// Returns: Returns self if successful.  Returns nil if there was an error parsing the element value.
165        ///
166        /// # Safety
167        ///
168        /// - `element` should be of the correct type.
169        /// - `element` might not allow `None`.
170        #[unsafe(method(initWithElementValue:))]
171        #[unsafe(method_family = init)]
172        pub unsafe fn initWithElementValue(
173            this: Allocated<Self>,
174            element: Option<&NSObject>,
175        ) -> Option<Retained<Self>>;
176
177        #[cfg(feature = "Bluetooth")]
178        /// Initializes a new IOBluetoothSDPDataElement with the given attributes.
179        ///
180        /// Warning - be careful using this method.  There is next to no error checking done on the
181        /// attributes.  It is entirely possible to construct an invalid data element.  It is recommended
182        /// that +withElementValue: be used instead of this one.
183        ///
184        /// Parameter `typeDescriptor`: The type descriptor for the data element.
185        ///
186        /// Parameter `sizeDescriptor`: The size descriptor for the data element (verify it matches the size parameter).
187        ///
188        /// Parameter `size`: The size of the data element in bytes (make sure it is a valid size for the given size descriptor).
189        ///
190        /// Parameter `value`: The raw value itself.  This must be the base NSString, NSNumber, NSArray or NSData objects.  It
191        /// may not be NSDictionary.  If a dictionary format is present, use +withElementValue:.
192        ///
193        /// Returns: Returns self if successful.  Returns nil if an error is encountered (not likely
194        /// due to the limited error checking currently done).
195        ///
196        /// # Safety
197        ///
198        /// - `new_value` should be of the correct type.
199        /// - `new_value` might not allow `None`.
200        #[unsafe(method(initWithType:sizeDescriptor:size:value:))]
201        #[unsafe(method_family = init)]
202        pub unsafe fn initWithType_sizeDescriptor_size_value(
203            this: Allocated<Self>,
204            new_type: BluetoothSDPDataElementTypeDescriptor,
205            new_size_descriptor: BluetoothSDPDataElementSizeDescriptor,
206            new_size: u32,
207            new_value: Option<&NSObject>,
208        ) -> Option<Retained<Self>>;
209
210        #[cfg(feature = "IOBluetoothUserLib")]
211        /// Returns an IOBluetoothSDPDataElementRef representation of the target IOBluetoothSDPDataElement object.
212        ///
213        /// Returns: Returns an IOBluetoothSDPDataElementRef representation of the target IOBluetoothSDPDataElement object.
214        #[unsafe(method(getSDPDataElementRef))]
215        #[unsafe(method_family = none)]
216        pub unsafe fn getSDPDataElementRef(&self)
217            -> Option<Retained<IOBluetoothSDPDataElementRef>>;
218
219        #[cfg(feature = "Bluetooth")]
220        /// Returns the SDP spec defined data element type descriptor for the target data element.
221        ///
222        /// Returns: Returns the type descriptor for the target data element.
223        #[unsafe(method(getTypeDescriptor))]
224        #[unsafe(method_family = none)]
225        pub unsafe fn getTypeDescriptor(&self) -> BluetoothSDPDataElementTypeDescriptor;
226
227        #[cfg(feature = "Bluetooth")]
228        /// Returns the SDP spec defined data element size descriptor for the target data element.
229        ///
230        /// Returns: Returns the size descriptor for the target data element.
231        #[unsafe(method(getSizeDescriptor))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn getSizeDescriptor(&self) -> BluetoothSDPDataElementSizeDescriptor;
234
235        /// Returns the size in bytes of the target data element.
236        ///
237        /// The size is valid whether the data element has a fixed or variable size descriptor.
238        ///
239        /// Returns: Returns the size in bytes of the target data element.
240        #[unsafe(method(getSize))]
241        #[unsafe(method_family = none)]
242        pub unsafe fn getSize(&self) -> u32;
243
244        #[cfg(feature = "objc2-foundation")]
245        /// If the data element is represented by a number, it returns the value as an NSNumber.
246        ///
247        /// The data types represented by a number are 1 (unsigned int), 2 (signed int) and 5 (boolean)
248        /// except for 128-bit versions of 1 and 2.
249        ///
250        /// Returns: Returns an NSNumber representation of the data element if it is a numeric type.
251        #[unsafe(method(getNumberValue))]
252        #[unsafe(method_family = none)]
253        pub unsafe fn getNumberValue(&self) -> Option<Retained<NSNumber>>;
254
255        #[cfg(feature = "objc2-foundation")]
256        /// If the data element is represented by a data object, it returns the value as an NSData.
257        ///
258        /// The data types represented by a data object are 128-bit versions of 1 (unsigned int) and
259        /// 2 (signed int).
260        ///
261        /// Returns: Returns an NSData representation of the data element if it is a 128-bit number.
262        #[unsafe(method(getDataValue))]
263        #[unsafe(method_family = none)]
264        pub unsafe fn getDataValue(&self) -> Option<Retained<NSData>>;
265
266        #[cfg(feature = "objc2-foundation")]
267        /// If the data element is represented by a string object, it returns the value as an NSString.
268        ///
269        /// The data types represented by a string object are 4 (text string) and 8 (URL).
270        ///
271        /// Returns: Returns an NSString representation of the data element if it is a text or URL type.
272        #[unsafe(method(getStringValue))]
273        #[unsafe(method_family = none)]
274        pub unsafe fn getStringValue(&self) -> Option<Retained<NSString>>;
275
276        #[cfg(feature = "objc2-foundation")]
277        /// If the data element is represented by an array object, it returns the value as an NSArray.
278        ///
279        /// The data types represented by an array object are 6 (data element sequence) and 7 (data
280        /// element alternative).
281        ///
282        /// Returns: Returns an NSArray representation of the data element if it is a sequence type.
283        #[unsafe(method(getArrayValue))]
284        #[unsafe(method_family = none)]
285        pub unsafe fn getArrayValue(&self) -> Option<Retained<NSArray>>;
286
287        #[cfg(all(feature = "IOBluetoothSDPUUID", feature = "objc2-foundation"))]
288        /// If the data element is a UUID (type 3), it returns the value as an IOBluetoothSDPUUID.
289        ///
290        /// Returns: Returns an IOBluetoothSDPUUID representation of the data element if it is a UUID.
291        #[unsafe(method(getUUIDValue))]
292        #[unsafe(method_family = none)]
293        pub unsafe fn getUUIDValue(&self) -> Option<Retained<IOBluetoothSDPUUID>>;
294
295        /// Returns the object value of the data element.
296        ///
297        /// The value returned may be an NSNumber, NSString, NSData, NSArray or IOBluetoothSDPDataElement
298        /// depending on the type of the data element.
299        ///
300        /// Returns: Returns the object value of the target data element.
301        #[unsafe(method(getValue))]
302        #[unsafe(method_family = none)]
303        pub unsafe fn getValue(&self) -> Option<Retained<NSObject>>;
304
305        /// Checks to see if the target data element is the same as the dataElement parameter or if it contains
306        /// the dataElement parameter (if its a sequence type).
307        ///
308        /// If the target data element is not a sequence type, this method simply compares the two data elements.  If
309        /// it is a sequence type, it will search through the sequence (and sub-sequences) for the dataElement
310        /// parameter.
311        ///
312        /// Parameter `dataElement`: The data element to compare with (and search for).
313        ///
314        /// Returns: Returns TRUE if the target either matches the given data element or if it contains the given data element.
315        ///
316        /// # Safety
317        ///
318        /// `data_element` might not allow `None`.
319        #[unsafe(method(containsDataElement:))]
320        #[unsafe(method_family = none)]
321        pub unsafe fn containsDataElement(
322            &self,
323            data_element: Option<&IOBluetoothSDPDataElement>,
324        ) -> bool;
325
326        /// Checks to see if the target data element's value is the same as the value parameter or if it contains
327        /// the value parameter.
328        ///
329        /// This method works just like -containsDataElement: except that it is comparing the value objects directly.
330        ///
331        /// Parameter `cmpValue`: The value to compare with (and search for).
332        ///
333        /// Returns: Returns TRUE if the target's value either matches the given value or if it contains the given value.
334        ///
335        /// # Safety
336        ///
337        /// - `cmp_value` should be of the correct type.
338        /// - `cmp_value` might not allow `None`.
339        #[unsafe(method(containsValue:))]
340        #[unsafe(method_family = none)]
341        pub unsafe fn containsValue(&self, cmp_value: Option<&NSObject>) -> bool;
342    );
343}
344
345/// Methods declared on superclass `NSObject`.
346impl IOBluetoothSDPDataElement {
347    extern_methods!(
348        #[unsafe(method(init))]
349        #[unsafe(method_family = init)]
350        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
351
352        #[unsafe(method(new))]
353        #[unsafe(method_family = new)]
354        pub unsafe fn new() -> Retained<Self>;
355    );
356}