<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "IOBluetooth",
  "identifier" : "/documentation/IOBluetooth/IOBluetoothUnpackData",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "IOBluetooth"
    ],
    "preciseIdentifier" : "c:@F@IOBluetoothUnpackData"
  },
  "title" : "IOBluetoothUnpackData"
}
-->

# IOBluetoothUnpackData

Unpacks a variable amount of data from a buffer into a variable number of parameters according to a printf-style format string.

```
extern long IOBluetoothUnpackData(ByteCount inBufferSize, const void *inBuffer, const char *inFormat, ...);
```

## Parameters

`inBufferSize`

Size of buffer to unpack data from.

`inBuffer`

Ptr to buffer to unpack data from.

`inFormat`

printf-style format string controlling how the data is unpacked.

## Return Value

Number of bytes unpacked or -1 if an error occurred.

## Discussion

Pass the parameters to receive data as the remaining arguments after the format string.

Supported format characters:

```objc
 
   	'b' Ptr to receive 1 byte of data ('b'yte).
   	'h' Ptr to receive 2 bytes of data ('h'alf-word).
   	'H' Ptr to receive 2 bytes of byte-reversed data ('h'alf-word).
   	't' Ptr to receive 3 bytes of data ('t'riple byte, least significant 24-bits).
   	'T' Ptr to receive 3 bytes of byte-reversed data ('t'riple byte, least significant 24-bits).
   	'w' Ptr to receive 4 bytes of data ('w'ord).
   	'W' Ptr to receive 4 bytes of byte-reversed data ('w'ord).
   	'1' Ptr to receive 1 byte of data.
   	'2' Ptr to receive 2 bytes of data.
   	'@'	(shift-2) Ptr to 2 bytes of data, byte reversed.
   	'3' Ptr to receive 3 bytes of data.
   	'#'	(shift-3) Ptr to receive 3 bytes of data, byte reversed.
   	'4' Ptr to receive 4 bytes of data.
   	'$'	(shift-4) Ptr to receive 4 bytes of data, byte reversed.
   	'5' Ptr to receive 5 bytes of data.
   	'%'	(shift-5) Ptr to receive 5 bytes of data, byte reversed.
   	'6' Ptr to receive 6 bytes of data.
   	'^'	(shift-6) Ptr to receive 6 bytes of data, byte reversed.
   	'7' Ptr to receive 7 bytes of data.
   	'&'	(shift-7) Ptr to receive 7 bytes of data, byte reversed.
   	'8' Ptr to receive 8 bytes of data.
   	'*'	(shift-8) Ptr to receive 8 bytes of data, byte reversed.
   	'9' Ptr to receive 9 bytes of data.
   	'('	(shift-9) Ptr to receive 9 bytes of data, byte reversed.
   	'n' Ptr to receive n bytes of data (first param is size, second is ptr to receive data).
   	'N' Ptr to receive n bytes of data to byte reverse (first param is size, second is ptr to receive data).
   	's' Ptr to receive C-string (first param is max size, second is ptr to receive data).
   	'p' Ptr to receive Pascal-string (first param is max size including length-byte, second is ptr to receive data).
 
```

Example usage:

```objc
 
   	bytesUnpacked = UnpackData( 100, buffer, "bwnsp", &myByte1, &myWord, 50, buffer1, 128, buffer2, 255, pString );
 
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)