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

# IOBluetoothPackData

Packs a variable amount of parameters into a buffer according to a printf-style format string.

```
extern long IOBluetoothPackData(void *ioBuffer, const char *inFormat, ...);
```

## Parameters

`ioBuffer`

Ptr to buffer to receive packed data.

`inFormat`

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

## Return Value

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

## Discussion

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

Supported format characters:

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

Example usage:

```objc
 
   	bytesPacked = PackData( buffer, "bts", 'U', 'XYZ', "This is a C-style string" );
 
```

**Warning:** *Raw values packed with ‘b’, ‘h’, ‘t’, and ‘w’ have their bytes packed into the buffer from left to right even on little-endian systems. For example, the value 0x12345678 would be sent out as 0x12 0x34 0x56 0x78. This needs to be taken into consideration if the value is expected to be in little-endian format in the buffer. This case requires you byte swap the value on all systems before sending it to this routine.*

---

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)