pub struct IOBluetoothSDPDataElement { /* private fields */ }IOBluetoothSDPDataElement only.Expand description
An instance of this class represents a single SDP data element as defined by the Bluetooth SDP spec.
The data types described by the spec have been mapped onto the base Foundation classes NSNumber, NSArray, NSData as well as IOBluetoothSDPUUID. The number and boolean types (type descriptor 1, 2 and 5) are represented as NSNumber objects with the exception of 128-bit numbers which are represented as NSData objects in their raw format. The UUID type (type descriptor 3) is represented by IOBluetoothSDPUUID. The string and URL types (type descriptor 4 and 8) are represented by NSString. The sequence types (type descriptor 6 and 7) are represented by NSArray.
Typically, you will not need to create an IOBluetoothSDPDataElement directly, the system will do that automatically for both client and server operations. However, the current API for adding SDP services to the system does allow the use of an NSDictionary based format for creating new services. The purpose for that is to allow a service to be built up completely in a text file (a plist for example) and then easily imported into an app and added to the system without a lot of tedious code to build up the entire SDP service record.
The basis for that NSDictionary structure comes from the IOBluetoothSDPDataElement. At its simplest, a data element is made up of three parts: the type descriptor, the size (from which the size descriptor is generated) and the actual value. To provide a complete representation of a data element, an NSDictionary with three entries can be used. Each of the three entries has a key/value pair representing one of the three attributes of a data element. The first key/value pair has a key ‘DataElementType’ that contains a number value with the actual type descriptor for the data element. The second pair has a key ‘DataElementSize’ that contains the actual size of the element in bytes. The size descriptor will be calculated based on the size and type of the element. The third pair is the value itself whose key is ‘DataElementValue’ and whose type corresponds to the type mapping above.
In addition to this complete description of a data element, their are some shortcuts that can be used for some of the common types and sizes.
If the ‘DataElementType’ value is one of the numeric types (1, 2), the ‘DataElementValue’ can be an NSData instead of an NSNumber. In that case, the numeric data is taken in network byte order (MSB first). Additionally, the ‘DataElementSize’ parameter may be omitted and the size will be taken from the length of the data object.
If the ‘DataElementType’ value is the nil type (0), no ‘DataElementSize’ or ‘DataElementValue’ entries are needed.
If the ‘DataElementType’ value is any of the other types, the ‘DataElementSize’ entry is not needed since the size will be taken directly from the value (data, array, string).
In the case where the element is an unsigned, 32-bit integer (type descriptor 1, size descriptor 4), the value itself may simply be a number (instead of a dictionary as in the previous examples).
In the case where the element is a UUID (type descriptor 3), the value itself may be a data object. The UUID type will be inferred and the size taken from the length of the data object.
In the case where the element is a text string (type descriptor 4), the value may be a string object. The text string type will be inferred and the size taken from the length of the string.
In the case where the element is a data element sequence, the value may be an array object. The type will be inferred and the size taken from the length of the array. Additionally, the array must contain sub-elements that will be parsed out individually.
See also Apple’s documentation
Implementations§
Source§impl IOBluetoothSDPDataElement
impl IOBluetoothSDPDataElement
Sourcepub unsafe fn withElementValue(
element: Option<&NSObject>,
) -> Option<Retained<Self>>
Available on crate feature objc2 only.
pub unsafe fn withElementValue( element: Option<&NSObject>, ) -> Option<Retained<Self>>
objc2 only.Creates a new IOBluetoothSDPDataElement with the given value.
The value must follow the format listed above and must be an instance of NSData, NSString, NSNumber, NSArray, NSDictionary, IOBluetoothSDPUUID.
Parameter element: The data element value of one of the specified types.
Returns: Returns the newly allocated data element object. Returns nil if there was an error parsing the element value. The returned IOBluetoothSDPDataElement object has been autoreleased, so it is not necessary for the caller to release it. If the object is to be referenced and kept around, retain should be called.
§Safety
elementshould be of the correct type.elementmight not allowNone.
Sourcepub unsafe fn withType_sizeDescriptor_size_value(
type: BluetoothSDPDataElementTypeDescriptor,
new_size_descriptor: BluetoothSDPDataElementSizeDescriptor,
new_size: u32,
new_value: Option<&NSObject>,
) -> Option<Retained<Self>>
Available on crate features objc2 and Bluetooth only.
pub unsafe fn withType_sizeDescriptor_size_value( type: BluetoothSDPDataElementTypeDescriptor, new_size_descriptor: BluetoothSDPDataElementSizeDescriptor, new_size: u32, new_value: Option<&NSObject>, ) -> Option<Retained<Self>>
objc2 and Bluetooth only.Creates a new IOBluetoothSDPDataElement with the given attributes.
Warning - be careful using this method. There is next to no error checking done on the attributes. It is entirely possible to construct an invalid data element. It is recommended that +withElementValue: be used instead of this one.
Parameter typeDescriptor: The type descriptor for the data element.
Parameter sizeDescriptor: The size descriptor for the data element (verify it matches the size parameter).
Parameter size: The size of the data element in bytes (make sure it is a valid size for the given size descriptor).
Parameter value: The raw value itself. This must be the base NSString, NSNumber, NSArray or NSData objects. It
may not be NSDictionary. If a dictionary format is present, use +withElementValue:.
Returns: Returns the newly allocated data element object. Returns nil if an error is encountered (not likely due to the limited error checking currently done). The returned IOBluetoothSDPDataElement object has been autoreleased, so it is not necessary for the caller to release it. If the object is to be referenced and kept around, retain should be called.
§Safety
new_valueshould be of the correct type.new_valuemight not allowNone.
Sourcepub unsafe fn withSDPDataElementRef(
sdp_data_element_ref: Option<&IOBluetoothSDPDataElementRef>,
) -> Option<Retained<Self>>
Available on crate features objc2 and IOBluetoothUserLib only.
pub unsafe fn withSDPDataElementRef( sdp_data_element_ref: Option<&IOBluetoothSDPDataElementRef>, ) -> Option<Retained<Self>>
objc2 and IOBluetoothUserLib only.Method call to convert an IOBluetoothSDPDataElementRef into an IOBluetoothSDPDataElement *.
Parameter sdpDataElementRef: IOBluetoothSDPDataElementRef for which an IOBluetoothSDPDataElement * is desired.
Returns: Returns the IOBluetoothSDPDataElement * for the given IOBluetoothSDPDataElementRef.
§Safety
sdp_data_element_ref might not allow None.
Sourcepub unsafe fn initWithElementValue(
this: Allocated<Self>,
element: Option<&NSObject>,
) -> Option<Retained<Self>>
Available on crate feature objc2 only.
pub unsafe fn initWithElementValue( this: Allocated<Self>, element: Option<&NSObject>, ) -> Option<Retained<Self>>
objc2 only.Initializes a new IOBluetoothSDPDataElement with the given value.
The value must follow the format listed above and must be an instance of NSData, NSString, NSNumber, NSArray, NSDictionary, IOBluetoothSDPUUID.
Parameter element: The data element value of one of the specified types.
Returns: Returns self if successful. Returns nil if there was an error parsing the element value.
§Safety
elementshould be of the correct type.elementmight not allowNone.
Sourcepub unsafe fn initWithType_sizeDescriptor_size_value(
this: Allocated<Self>,
new_type: BluetoothSDPDataElementTypeDescriptor,
new_size_descriptor: BluetoothSDPDataElementSizeDescriptor,
new_size: u32,
new_value: Option<&NSObject>,
) -> Option<Retained<Self>>
Available on crate features objc2 and Bluetooth only.
pub unsafe fn initWithType_sizeDescriptor_size_value( this: Allocated<Self>, new_type: BluetoothSDPDataElementTypeDescriptor, new_size_descriptor: BluetoothSDPDataElementSizeDescriptor, new_size: u32, new_value: Option<&NSObject>, ) -> Option<Retained<Self>>
objc2 and Bluetooth only.Initializes a new IOBluetoothSDPDataElement with the given attributes.
Warning - be careful using this method. There is next to no error checking done on the attributes. It is entirely possible to construct an invalid data element. It is recommended that +withElementValue: be used instead of this one.
Parameter typeDescriptor: The type descriptor for the data element.
Parameter sizeDescriptor: The size descriptor for the data element (verify it matches the size parameter).
Parameter size: The size of the data element in bytes (make sure it is a valid size for the given size descriptor).
Parameter value: The raw value itself. This must be the base NSString, NSNumber, NSArray or NSData objects. It
may not be NSDictionary. If a dictionary format is present, use +withElementValue:.
Returns: Returns self if successful. Returns nil if an error is encountered (not likely due to the limited error checking currently done).
§Safety
new_valueshould be of the correct type.new_valuemight not allowNone.
Sourcepub unsafe fn getSDPDataElementRef(
&self,
) -> Option<Retained<IOBluetoothSDPDataElementRef>>
Available on crate features objc2 and IOBluetoothUserLib only.
pub unsafe fn getSDPDataElementRef( &self, ) -> Option<Retained<IOBluetoothSDPDataElementRef>>
objc2 and IOBluetoothUserLib only.Returns an IOBluetoothSDPDataElementRef representation of the target IOBluetoothSDPDataElement object.
Returns: Returns an IOBluetoothSDPDataElementRef representation of the target IOBluetoothSDPDataElement object.
Sourcepub unsafe fn getTypeDescriptor(&self) -> BluetoothSDPDataElementTypeDescriptor
Available on crate features objc2 and Bluetooth only.
pub unsafe fn getTypeDescriptor(&self) -> BluetoothSDPDataElementTypeDescriptor
objc2 and Bluetooth only.Returns the SDP spec defined data element type descriptor for the target data element.
Returns: Returns the type descriptor for the target data element.
Sourcepub unsafe fn getSizeDescriptor(&self) -> BluetoothSDPDataElementSizeDescriptor
Available on crate features objc2 and Bluetooth only.
pub unsafe fn getSizeDescriptor(&self) -> BluetoothSDPDataElementSizeDescriptor
objc2 and Bluetooth only.Returns the SDP spec defined data element size descriptor for the target data element.
Returns: Returns the size descriptor for the target data element.
Sourcepub unsafe fn getSize(&self) -> u32
Available on crate feature objc2 only.
pub unsafe fn getSize(&self) -> u32
objc2 only.Returns the size in bytes of the target data element.
The size is valid whether the data element has a fixed or variable size descriptor.
Returns: Returns the size in bytes of the target data element.
Sourcepub unsafe fn getNumberValue(&self) -> Option<Retained<NSNumber>>
Available on crate features objc2 and objc2-foundation only.
pub unsafe fn getNumberValue(&self) -> Option<Retained<NSNumber>>
objc2 and objc2-foundation only.If the data element is represented by a number, it returns the value as an NSNumber.
The data types represented by a number are 1 (unsigned int), 2 (signed int) and 5 (boolean) except for 128-bit versions of 1 and 2.
Returns: Returns an NSNumber representation of the data element if it is a numeric type.
Sourcepub unsafe fn getDataValue(&self) -> Option<Retained<NSData>>
Available on crate features objc2 and objc2-foundation only.
pub unsafe fn getDataValue(&self) -> Option<Retained<NSData>>
objc2 and objc2-foundation only.If the data element is represented by a data object, it returns the value as an NSData.
The data types represented by a data object are 128-bit versions of 1 (unsigned int) and 2 (signed int).
Returns: Returns an NSData representation of the data element if it is a 128-bit number.
Sourcepub unsafe fn getStringValue(&self) -> Option<Retained<NSString>>
Available on crate features objc2 and objc2-foundation only.
pub unsafe fn getStringValue(&self) -> Option<Retained<NSString>>
objc2 and objc2-foundation only.If the data element is represented by a string object, it returns the value as an NSString.
The data types represented by a string object are 4 (text string) and 8 (URL).
Returns: Returns an NSString representation of the data element if it is a text or URL type.
Sourcepub unsafe fn getArrayValue(&self) -> Option<Retained<NSArray>>
Available on crate features objc2 and objc2-foundation only.
pub unsafe fn getArrayValue(&self) -> Option<Retained<NSArray>>
objc2 and objc2-foundation only.If the data element is represented by an array object, it returns the value as an NSArray.
The data types represented by an array object are 6 (data element sequence) and 7 (data element alternative).
Returns: Returns an NSArray representation of the data element if it is a sequence type.
Sourcepub unsafe fn getUUIDValue(&self) -> Option<Retained<IOBluetoothSDPUUID>>
Available on crate features objc2 and IOBluetoothSDPUUID and objc2-foundation only.
pub unsafe fn getUUIDValue(&self) -> Option<Retained<IOBluetoothSDPUUID>>
objc2 and IOBluetoothSDPUUID and objc2-foundation only.If the data element is a UUID (type 3), it returns the value as an IOBluetoothSDPUUID.
Returns: Returns an IOBluetoothSDPUUID representation of the data element if it is a UUID.
Sourcepub unsafe fn getValue(&self) -> Option<Retained<NSObject>>
Available on crate feature objc2 only.
pub unsafe fn getValue(&self) -> Option<Retained<NSObject>>
objc2 only.Returns the object value of the data element.
The value returned may be an NSNumber, NSString, NSData, NSArray or IOBluetoothSDPDataElement depending on the type of the data element.
Returns: Returns the object value of the target data element.
Sourcepub unsafe fn containsDataElement(
&self,
data_element: Option<&IOBluetoothSDPDataElement>,
) -> bool
Available on crate feature objc2 only.
pub unsafe fn containsDataElement( &self, data_element: Option<&IOBluetoothSDPDataElement>, ) -> bool
objc2 only.Checks to see if the target data element is the same as the dataElement parameter or if it contains the dataElement parameter (if its a sequence type).
If the target data element is not a sequence type, this method simply compares the two data elements. If it is a sequence type, it will search through the sequence (and sub-sequences) for the dataElement parameter.
Parameter dataElement: The data element to compare with (and search for).
Returns: Returns TRUE if the target either matches the given data element or if it contains the given data element.
§Safety
data_element might not allow None.
Sourcepub unsafe fn containsValue(&self, cmp_value: Option<&NSObject>) -> bool
Available on crate feature objc2 only.
pub unsafe fn containsValue(&self, cmp_value: Option<&NSObject>) -> bool
objc2 only.Checks to see if the target data element’s value is the same as the value parameter or if it contains the value parameter.
This method works just like -containsDataElement: except that it is comparing the value objects directly.
Parameter cmpValue: The value to compare with (and search for).
Returns: Returns TRUE if the target’s value either matches the given value or if it contains the given value.
§Safety
cmp_valueshould be of the correct type.cmp_valuemight not allowNone.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AnyObject> for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl AsRef<AnyObject> for IOBluetoothSDPDataElement
objc2 only.Source§impl AsRef<IOBluetoothSDPDataElement> for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl AsRef<IOBluetoothSDPDataElement> for IOBluetoothSDPDataElement
objc2 only.Source§impl AsRef<NSObject> for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl AsRef<NSObject> for IOBluetoothSDPDataElement
objc2 only.Source§impl Borrow<AnyObject> for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl Borrow<AnyObject> for IOBluetoothSDPDataElement
objc2 only.Source§impl Borrow<NSObject> for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl Borrow<NSObject> for IOBluetoothSDPDataElement
objc2 only.Source§impl ClassType for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl ClassType for IOBluetoothSDPDataElement
objc2 only.Source§const NAME: &'static str = "IOBluetoothSDPDataElement"
const NAME: &'static str = "IOBluetoothSDPDataElement"
Source§type ThreadKind = <<IOBluetoothSDPDataElement as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<IOBluetoothSDPDataElement as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl Debug for IOBluetoothSDPDataElement
objc2 only.Source§impl Deref for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl Deref for IOBluetoothSDPDataElement
objc2 only.Source§impl Hash for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl Hash for IOBluetoothSDPDataElement
objc2 only.Source§impl Message for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl Message for IOBluetoothSDPDataElement
objc2 only.Source§impl NSObjectProtocol for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl NSObjectProtocol for IOBluetoothSDPDataElement
objc2 only.Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_refSource§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
Source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
Source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
Source§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
Source§impl NSSecureCoding for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl NSSecureCoding for IOBluetoothSDPDataElement
objc2 only.Source§impl PartialEq for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl PartialEq for IOBluetoothSDPDataElement
objc2 only.Source§impl RefEncode for IOBluetoothSDPDataElement
Available on crate feature objc2 only.
impl RefEncode for IOBluetoothSDPDataElement
objc2 only.Source§const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
impl DowncastTarget for IOBluetoothSDPDataElement
objc2 only.impl Eq for IOBluetoothSDPDataElement
objc2 only.impl NSCoding for IOBluetoothSDPDataElement
objc2 only.