Re: Question about getBytes:length:
Re: Question about getBytes:length:
- Subject: Re: Question about getBytes:length:
- From: Charles Srstka <email@hidden>
- Date: Tue, 24 Nov 2015 13:27:57 -0600
> On Nov 24, 2015, at 12:58 PM, Wim Lewis <email@hidden> wrote:
>
> On Nov 23, 2015, at 8:57 PM, Charles Srstka <email@hidden <mailto:email@hidden>> wrote:
>> Is there a possible typo here? It looks like you’re reading in 16 *bytes* of data, and then comparing it against an integer that is 16 *bits* in size. Is that what you meant to do?
>
> Bluetooth has a number of "short form" UUIDs where most of the UUID is fixed and the remainder is assigned by a central authority.
>
> https://www.bluetooth.org/en-us/specification/assigned-numbers/service-discovery <https://www.bluetooth.org/en-us/specification/assigned-numbers/service-discovery>
>
> (I'd argue that -compareCBUUIDToInt:UUID2: should probably be making sure that the remaining fourteen bytes have the expected value, and OSReadBigInt16() is probably less likely to break in the future than swap-and-memcmp, but that's all by-the-way.)
The issue is that if CBUUID is initialized with only two bytes, its “data” property is an NSData with only two bytes in it. The portion that is assigned is presented as not being part of the UUID by the API.
@import Foundation;
@import CoreBluetooth;
int main(int argc, char *argv[]) {
@autoreleasepool {
CBUUID *uuid = [CBUUID UUIDWithString:@"1234"];
NSLog(@"data: %@ length: %lu", uuid.data, (unsigned long)uuid.data.length);
}
}
outputs:
data: <1234> length: 2
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden