IOBluetoothSDPDataElement

Struct IOBluetoothSDPDataElement 

Source
pub struct IOBluetoothSDPDataElement { /* private fields */ }
Available on crate feature 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

Source

pub unsafe fn withElementValue( element: Option<&NSObject>, ) -> Option<Retained<Self>>

Available on crate feature 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
  • element should be of the correct type.
  • element might not allow None.
Source

pub 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.

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_value should be of the correct type.
  • new_value might not allow None.
Source

pub unsafe fn withSDPDataElementRef( sdp_data_element_ref: Option<&IOBluetoothSDPDataElementRef>, ) -> Option<Retained<Self>>

Available on crate features 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.

Source

pub unsafe fn initWithElementValue( this: Allocated<Self>, element: Option<&NSObject>, ) -> Option<Retained<Self>>

Available on crate feature 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
  • element should be of the correct type.
  • element might not allow None.
Source

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>>

Available on crate features 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_value should be of the correct type.
  • new_value might not allow None.
Source

pub unsafe fn getSDPDataElementRef( &self, ) -> Option<Retained<IOBluetoothSDPDataElementRef>>

Available on crate features objc2 and IOBluetoothUserLib only.

Returns an IOBluetoothSDPDataElementRef representation of the target IOBluetoothSDPDataElement object.

Returns: Returns an IOBluetoothSDPDataElementRef representation of the target IOBluetoothSDPDataElement object.

Source

pub unsafe fn getTypeDescriptor(&self) -> BluetoothSDPDataElementTypeDescriptor

Available on crate features 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.

Source

pub unsafe fn getSizeDescriptor(&self) -> BluetoothSDPDataElementSizeDescriptor

Available on crate features 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.

Source

pub unsafe fn getSize(&self) -> u32

Available on crate feature 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.

Source

pub unsafe fn getNumberValue(&self) -> Option<Retained<NSNumber>>

Available on crate features 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.

Source

pub unsafe fn getDataValue(&self) -> Option<Retained<NSData>>

Available on crate features 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.

Source

pub unsafe fn getStringValue(&self) -> Option<Retained<NSString>>

Available on crate features 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.

Source

pub unsafe fn getArrayValue(&self) -> Option<Retained<NSArray>>

Available on crate features 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.

Source

pub unsafe fn getUUIDValue(&self) -> Option<Retained<IOBluetoothSDPUUID>>

Available on crate features 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.

Source

pub unsafe fn getValue(&self) -> Option<Retained<NSObject>>

Available on crate feature 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.

Source

pub unsafe fn containsDataElement( &self, data_element: Option<&IOBluetoothSDPDataElement>, ) -> bool

Available on crate feature 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.

Source

pub unsafe fn containsValue(&self, cmp_value: Option<&NSObject>) -> bool

Available on crate feature 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_value should be of the correct type.
  • cmp_value might not allow None.
Source§

impl IOBluetoothSDPDataElement

Methods declared on superclass NSObject.

Source

pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>

Available on crate feature objc2 only.
Source

pub unsafe fn new() -> Retained<Self>

Available on crate feature objc2 only.

Methods from Deref<Target = NSObject>§

Source

pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !

Handle messages the object doesn’t recognize.

See Apple’s documentation for details.

Methods from Deref<Target = AnyObject>§

Source

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());
Source

pub unsafe fn get_ivar<T>(&self, name: &str) -> &T
where T: Encode,

👎Deprecated: this is difficult to use correctly, use 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.

Source

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.
Source§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<IOBluetoothSDPDataElement> for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<NSObject> for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn as_ref(&self) -> &NSObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<AnyObject> for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn borrow(&self) -> &AnyObject

Immutably borrows from an owned value. Read more
Source§

impl Borrow<NSObject> for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn borrow(&self) -> &NSObject

Immutably borrows from an owned value. Read more
Source§

impl ClassType for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

const NAME: &'static str = "IOBluetoothSDPDataElement"

The name of the Objective-C class that this type represents. Read more
Source§

type Super = NSObject

The superclass of this class. Read more
Source§

type ThreadKind = <<IOBluetoothSDPDataElement as ClassType>::Super as ClassType>::ThreadKind

Whether the type can be used from any thread, or from only the main thread. Read more
Source§

fn class() -> &'static AnyClass

Get a reference to the Objective-C class that this type represents. Read more
Source§

fn as_super(&self) -> &Self::Super

Get an immutable reference to the superclass.
Source§

impl Debug for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

type Target = NSObject

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Hash for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Message for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn retain(&self) -> Retained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

impl NSObjectProtocol for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn isEqual(&self, other: Option<&AnyObject>) -> bool
where Self: Sized + Message,

Check whether the object is equal to an arbitrary other object. Read more
Source§

fn hash(&self) -> usize
where Self: Sized + Message,

An integer that can be used as a table address in a hash table structure. Read more
Source§

fn isKindOfClass(&self, cls: &AnyClass) -> bool
where Self: Sized + Message,

Check if the object is an instance of the class, or one of its subclasses. Read more
Source§

fn is_kind_of<T>(&self) -> bool
where T: ClassType, Self: Sized + Message,

👎Deprecated: use isKindOfClass directly, or cast your objects with AnyObject::downcast_ref
Check if the object is an instance of the class type, or one of its subclasses. Read more
Source§

fn isMemberOfClass(&self, cls: &AnyClass) -> bool
where Self: Sized + Message,

Check if the object is an instance of a specific class, without checking subclasses. Read more
Source§

fn respondsToSelector(&self, aSelector: Sel) -> bool
where Self: Sized + Message,

Check whether the object implements or inherits a method with the given selector. Read more
Source§

fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
where Self: Sized + Message,

Check whether the object conforms to a given protocol. Read more
Source§

fn description(&self) -> Retained<NSObject>
where Self: Sized + Message,

A textual representation of the object. Read more
Source§

fn debugDescription(&self) -> Retained<NSObject>
where Self: Sized + Message,

A textual representation of the object to use when debugging. Read more
Source§

fn isProxy(&self) -> bool
where Self: Sized + Message,

Check whether the receiver is a subclass of the NSProxy root class instead of the usual NSObject. Read more
Source§

fn retainCount(&self) -> usize
where Self: Sized + Message,

The reference count of the object. Read more
Source§

impl NSSecureCoding for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

impl PartialEq for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RefEncode for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF

The Objective-C type-encoding for a reference of this type. Read more
Source§

impl DowncastTarget for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

impl Eq for IOBluetoothSDPDataElement

Available on crate feature objc2 only.
Source§

impl NSCoding for IOBluetoothSDPDataElement

Available on crate feature objc2 only.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T> AnyThread for T
where T: ClassType<ThreadKind = dyn AnyThread + 'a> + ?Sized,

Source§

fn alloc() -> Allocated<Self>
where Self: Sized + ClassType,

Allocate a new instance of the class. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,