1# ipc_cparcel.h 2<!--Kit: IPC Kit--> 3<!--Subsystem: Communication--> 4<!--Owner: @xdx19211@luodonghui0157--> 5<!--SE: @zhaopeng_gitee--> 6<!--TSE: @maxiaorong2--> 7 8## Overview 9 10Provides C APIs for IPC serialization and deserialization. 11 12**Library**: libipc_capi.so 13 14**System capability**: SystemCapability.Communication.IPC.Core 15 16**Since**: 12 17 18**Related module**: [OHIPCParcel](capi-ohipcparcel.md) 19 20## Summary 21 22### Structs 23 24| Name| typedef Keyword| Description| 25| ---- | ------------- | ---- | 26| [OHIPCParcel](capi-ohipcparcel.md) | OHIPCParcel | Defines an IPC serialized object.| 27| [OHIPCRemoteProxy](capi-ohipcparcel-ohipcremoteproxy.md) | OHIPCRemoteProxy | Defines an IPC remote proxy object.| 28| [OHIPCRemoteStub](capi-ohipcparcel-ohipcremotestub.md) | OHIPCRemoteStub | Defines an IPC remote service object.| 29 30### Function 31 32| Name| typedef Keyword| Description| 33| ---- | ------------- | ---- | 34| [typedef void* (\*OH_IPC_MemAllocator)(int32_t len)](#oh_ipc_memallocator) | OH_IPC_MemAllocator | Defines the type of a memory allocation function.| 35| [OHIPCParcel* OH_IPCParcel_Create(void)](#oh_ipcparcel_create) | - | Creates an **OHIPCParcel** object, which cannot exceed 204,800 bytes.| 36| [void OH_IPCParcel_Destroy(OHIPCParcel *parcel)](#oh_ipcparcel_destroy) | - | Destroys an **OHIPCParcel** object.| 37| [int OH_IPCParcel_GetDataSize(const OHIPCParcel *parcel)](#oh_ipcparcel_getdatasize) | - | Obtains the size of the data contained in an **OHIPCParcel** object.| 38| [int OH_IPCParcel_GetWritableBytes(const OHIPCParcel *parcel)](#oh_ipcparcel_getwritablebytes) | - | Obtains the number of bytes that can be written to an **OHIPCParcel** object.| 39| [int OH_IPCParcel_GetReadableBytes(const OHIPCParcel *parcel)](#oh_ipcparcel_getreadablebytes) | - | Obtains the number of bytes that can be read from an **OHIPCParcel** object.| 40| [int OH_IPCParcel_GetReadPosition(const OHIPCParcel *parcel)](#oh_ipcparcel_getreadposition) | - | Obtains the position where data is read in an **OHIPCParcel** object.| 41| [int OH_IPCParcel_GetWritePosition(const OHIPCParcel *parcel)](#oh_ipcparcel_getwriteposition) | - | Obtains the position where data is written in an **OHIPCParcel** object.| 42| [int OH_IPCParcel_RewindReadPosition(OHIPCParcel *parcel, uint32_t newReadPos)](#oh_ipcparcel_rewindreadposition) | - | Resets the position to read data in an **OHIPCParcel** object.| 43| [int OH_IPCParcel_RewindWritePosition(OHIPCParcel *parcel, uint32_t newWritePos)](#oh_ipcparcel_rewindwriteposition) | - | Resets the position to write data in an **OHIPCParcel** object.| 44| [int OH_IPCParcel_WriteInt8(OHIPCParcel *parcel, int8_t value)](#oh_ipcparcel_writeint8) | - | Writes an int8_t value to an **OHIPCParcel** object.| 45| [int OH_IPCParcel_ReadInt8(const OHIPCParcel *parcel, int8_t *value)](#oh_ipcparcel_readint8) | - | Reads an int8_t value from an **OHIPCParcel** object.| 46| [int OH_IPCParcel_WriteInt16(OHIPCParcel *parcel, int16_t value)](#oh_ipcparcel_writeint16) | - | Writes an int16_t value to an **OHIPCParcel** object.| 47| [int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int16_t *value)](#oh_ipcparcel_readint16) | - | Reads an int16_t value from an **OHIPCParcel** object.| 48| [int OH_IPCParcel_WriteInt32(OHIPCParcel *parcel, int32_t value)](#oh_ipcparcel_writeint32) | - | Writes an int32_t value to an **OHIPCParcel** object.| 49| [int OH_IPCParcel_ReadInt32(const OHIPCParcel *parcel, int32_t *value)](#oh_ipcparcel_readint32) | - | Reads an int32_t value from an **OHIPCParcel** object.| 50| [int OH_IPCParcel_WriteInt64(OHIPCParcel *parcel, int64_t value)](#oh_ipcparcel_writeint64) | - | Writes an int64_t value to an **OHIPCParcel** object.| 51| [int OH_IPCParcel_ReadInt64(const OHIPCParcel *parcel, int64_t *value)](#oh_ipcparcel_readint64) | - | Reads an int64_t value from an **OHIPCParcel** object.| 52| [int OH_IPCParcel_WriteFloat(OHIPCParcel *parcel, float value)](#oh_ipcparcel_writefloat) | - | Writes a float value to an **OHIPCParcel** object.| 53| [int OH_IPCParcel_ReadFloat(const OHIPCParcel *parcel, float *value)](#oh_ipcparcel_readfloat) | - | Reads a float value from an **OHIPCParcel** object.| 54| [int OH_IPCParcel_WriteDouble(OHIPCParcel *parcel, double value)](#oh_ipcparcel_writedouble) | - | Writes a double value to an **OHIPCParcel** object.| 55| [int OH_IPCParcel_ReadDouble(const OHIPCParcel *parcel, double *value)](#oh_ipcparcel_readdouble) | - | Reads a double value from an **OHIPCParcel** object.| 56| [int OH_IPCParcel_WriteString(OHIPCParcel *parcel, const char *str)](#oh_ipcparcel_writestring) | - | Writes a string including a string terminator to an **OHIPCParcel** object.| 57| [const char OH_IPCParcel_ReadString(const OHIPCParcel *parcel)](#oh_ipcparcel_readstring) | - | Reads a string from an **OHIPCParcel** object. You can obtain the length of the string from **strlen**.| 58| [int OH_IPCParcel_Writebuffer(OHIPCParcel *parcel, const uint8_t *buffer, size_t len)](#oh_ipcparcel_writebuffer) | - | Writes data of the specified length from the memory to an **OHIPCParcel** object.| 59| [const uint8_t *OH_IPCParcel_ReadBuffer(const OHIPCParcel *parcel, int32_t len)](#oh_ipcparcel_readbuffer) | - | Reads memory information of the specified length from an **OHIPCParcel** object.| 60| [int OH_IPCParcel_WriteRemoteStub(OHIPCParcel *parcel, const OHRemoteObject *stub)](#oh_ipcparcel_writeremotestub) | - | Writes an **OHRemoteObject** object to an **OHIPCParcel** object.| 61| [OHIPCRemoteStub* OH_IPCParcel_ReadRemoteStub(OHIPCParcel *parcel)](#oh_ipcparcel_readremotestub) | - | Reads the **OHRemoteObject** object from an **OHIPCParcel** object.| 62| [int OH_IPCParcel_WriteRemoteProxy(OHIPCParcel *parcel, const OHRemoteObject *proxy)](#oh_ipcparcel_writeremoteproxy) | - | Writes an **OHRemoteObject** object to an **OHIPCParcel** object.| 63| [OHIPCRemoteProxy* OH_IPCParcel_ReadRemoteProxy(OHIPCParcel *parcel)](#oh_ipcparcel_readremoteproxy) | - | Reads the **OHRemoteObject** object from an **OHIPCParcel** object.| 64| [int OH_IPCParcel_WriteFileDescriptor(OHIPCParcel *parcel, int32_t fd)](#oh_ipcparcel_writefiledescriptor) | - | Writes a file descriptor to an **OHIPCParcel** object.| 65| [int OH_IPCParcel_ReadFileDescriptor(OHIPCParcel *parcel int32_t *fd)](#oh_ipcparcel_readfiledescriptor) | - | Reads a file descriptor from an **OHIPCParcel** object.| 66| [int OH_IPCParcel_Append(OHIPCParcel *parcel, const OHIPCParcel *data)](#oh_ipcparcel_append) | - | Appends data to an **OHIPCParcel** object.| 67| [int OH_IPCParcel_WriteInterfaceToken(OHIPCParcel *parcel, const char *token)](#oh_ipcparcel_writeinterfacetoken) | - | Writes an interface token to an **OHIPCParcel** object for interface identity verification.| 68| [int OH_IPCParcel_ReadInterfaceToken(OHIPCParcel *parcel, char **token, int32_t *len)](#oh_ipcparcel_readinterfacetoken) | - | Reads an interface token from an **OHIPCParcel** object for interface identity verification.| 69 70## Function Description 71 72### OH_IPC_MemAllocator() 73 74```C 75typedef void* (OH_IPC_MemAllocator)(int32_t len) 76``` 77 78**Description** 79 80Defines the type of a memory allocation function. 81 82**System capability**: SystemCapability.Communication.IPC.Core 83 84**Since**: 12 85 86**Parameters** 87 88| Name| Description| 89| ------ | ---- | 90|int32_t len | Length of the memory to be allocated.| 91 92**Returns** 93 94| Type| Description| 95| ---- | ---- | 96| void* | Returns the address of the memory allocated if the operation is successful; returns NULL otherwise.| 97 98### OH_IPCParcel_Create() 99 100```C 101OHIPCParcel* OH_IPCParcel_Create(void) 102``` 103 104**Description** 105 106Creates an **OHIPCParcel** object, which cannot exceed 204,800 bytes. 107 108**System capability**: SystemCapability.Communication.IPC.Core 109 110**Since**: 12 111 112**Returns** 113 114| Type| Description| 115| ---- | ---- | 116| OHIPCParcel* | Returns the pointer to the **OHIPCParcel** object created if the operation is successful; returns NULL otherwise.| 117 118### OH_IPCParcel_Destroy() 119 120```C 121void OH_IPCParcel_Destroy(OHIPCParcel *parcel) 122``` 123 124**Description** 125 126Destroys an **OHIPCParcel** object. 127 128**System capability**: SystemCapability.Communication.IPC.Core 129 130**Since**: 12 131 132**Parameters** 133 134| Name| Description| 135| ------ | ---- | 136| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object to destroy.| 137 138### OH_IPCParcel_GetDataSize() 139 140``` C 141int OH_IPCParcel_GetDataSize(const OHIPCParcel *parcel) 142``` 143 144**Description** 145Obtains the size of the data contained in an **OHIPCParcel** object. 146 147**System capability**: SystemCapability.Communication.IPC.Core 148 149**Since**: 12 150 151**Parameters** 152 153| Name| Description| 154| ------ | ---- | 155| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 156 157**Returns** 158 159| Type| Description| 160| ---- | ---- | 161| int | Returns the data size obtained if the operation is successful; returns **-1** if invalid parameters are found.| 162 163### OH_IPCParcel_GetWritableBytes() 164 165```C 166int OH_IPCParcel_GetWritableBytes(const OHIPCParcel *parcel) 167``` 168 169**Description** 170 171Obtains the number of bytes that can be written to an **OHIPCParcel** object. 172 173**System capability**: SystemCapability.Ability.AbilityRuntime.Core 174 175**Since**: 12 176 177**Parameters** 178 179| Name| Description| 180| ------ | ---- | 181| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 182 183**Returns** 184 185| Type| Description| 186| ---- | ---- | 187| int | Returns the number of bytes that can be written to the **OHIPCParcel** object; returns **-1** if invalid parameters are found.| 188 189### OH_IPCParcel_GetReadableBytes() 190 191```C 192int OH_IPCParcel_GetReadableBytes(const OHIPCParcel *parcel) 193``` 194 195**Description** 196 197Obtains the number of bytes that can be read from an **OHIPCParcel** object. 198 199**System capability**: SystemCapability.Communication.IPC 200 201**Since**: 12 202 203**Parameters** 204 205| Name| Description| 206| ------ | ---- | 207| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 208 209**Returns** 210 211| Type| Description| 212| ---- | ---- | 213| int | Returns the number of bytes that can be read from the **OHIPCParcel** object; returns **-1** if invalid parameters are found.| 214 215### OH_IPCParcel_GetReadPosition() 216 217```C 218int OH_IPCParcel_GetReadPosition(const OH_IPCParcel *parcel) 219``` 220 221**Description** 222 223Obtains the position where data is read in an **OHIPCParcel** object. 224 225**Parameters** 226 227| Name| Description| 228| ---- | ---- | 229| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 230 231**Returns** 232 233| Type| Description| 234| ---- | ---- | 235| int | Returns the current read position obtained if the operation is successful; returns **-1** if invalid parameters are found.| 236 237### OH_IPCParcel_GetWritePosition() 238 239```C 240int OH_IPCParcel_GetWritePosition(const OHIPCParcel *parcel) 241``` 242 243**Description** 244 245Obtains the position where data is written in an **OHIPCParcel** object. 246 247**System capability**: SystemCapability.Communication.IPC 248 249**Since**: 12 250 251**Parameters** 252 253| Name| Description| 254| ----- | ---- | 255| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 256 257**Returns** 258 259| Type| Description| 260| ---- | ---- | 261| int | Returns the current write position obtained if the operation is successful; returns **-1** if invalid parameters are found.| 262 263### OH_IPCParcel_RewindReadPosition() 264 265```c 266int OH_IPCParcel_RewindReadPosition(OHIPCParcel *parcel, uint32_t newReadPos) 267``` 268 269**Description** 270 271Resets the position to read data in an **OHIPCParcel** object. 272 273**System capability**: SystemCapability.Communication.IPC.Core 274 275**Since**: 12 276 277**Parameters** 278 279| Name| Description| 280| ------ | ---- | 281| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 282| uint32_t newReadPos | New position to read data. The value ranges from **0** to the current data size.| 283 284**Returns** 285 286| Type| Description| 287| ---- | ---- | 288| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found.| 289 290### OH_IPCParcel_RewindWritePosition() 291 292```C 293int OH_IPCParcel_RewindWritePosition(OHIPCParcel *parcel, uint32_t newWritePos); 294``` 295 296**Description** 297 298Resets the position to write data in an **OHIPCParcel** object. 299 300**System capability**: SystemCapability.Communication.IPC.Core 301 302**Since**: 12 303 304**Parameters** 305 306| Name| Description| 307| ------ | ---- | 308| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 309| uint32_t newWritePos | New position to write data. The value ranges from **0** to the current data size.| 310 311**Returns** 312 313| Type| Description| 314| ---- | ---- | 315| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found.| 316 317### OH_IPCParcel_WriteInt8() 318 319```C 320int OH_IPCParcel_WriteInt8(OHIPCParcel *parcel, int8_t value) 321``` 322 323**Description** 324 325Writes an int8_t value to an **OHIPCParcel** object. 326 327**System capability**: SystemCapability.Communication.IPC.Core 328 329**Since**: 12 330 331**Parameters** 332 333| Name| Description| 334| ------ | ---- | 335| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 336| int8_t value | Value to write.| 337 338**Returns** 339 340| Type| Description| 341| -----| ---- | 342| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 343 344### OH_IPCParcel_ReadInt8() 345 346```C 347int OH_IPCParcel_ReadInt8(OHIPCParcel *parcel, int8_t *value) 348``` 349 350**Description** 351 352Reads an int8_t value from an **OHIPCParcel** object. 353 354**System capability**: SystemCapability.Communication.IPC 355 356**Since**: 12 357 358**Parameters** 359 360| Name| Description| 361| ------ | ---- | 362| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 363| int8_t *value | Pointer to the buffer for holding the read data. It cannot be NULL.| 364 365**Returns** 366 367| Type| Description| 368| ---- | ---- | 369| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md) if the read operation fails.| 370 371### OH_IPCParcel_WriteInt16() 372 373```C 374int OH_IPCParcel_WriteInt16(OHIPCParcel *parcel, int16_t value) 375``` 376 377**Description** 378Writes an int16_t value to an **OHIPCParcel** object. 379 380**System capability**: SystemCapability.Communication.IPC 381 382**Since**: 12 383 384**Parameters** 385 386| Name| Description| 387| ------ | ---- | 388| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 389| int16_t value | Value to write.| 390 391**Returns** 392 393| Type| Description| 394| ---- | ---- | 395| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 396 397### OH_IPCParcel_ReadInt16() 398 399```C 400int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int16_t *value) 401``` 402 403**Description** 404 405Reads an int16_t value from an **OHIPCParcel** object. 406 407**System capability**: SystemCapability.Communication.IPC 408 409**Since**: 12 410 411**Parameters** 412 413| Name| Description| 414| ------ | ---- | 415| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 416| int16_t *value | Pointer to the buffer for holding the read data. It cannot be NULL.| 417 418**Returns** 419 420| Type| Description| 421| ---- | ---- | 422| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md) if the read operation fails.| 423 424### OH_IPCParcel_WriteInt32() 425 426```C 427int OH_IPCParcel_WriteInt32(OHIPCParcel *parcel, int32_t value) 428``` 429 430**Description** 431Writes an int32_t value to an **OHIPCParcel** object. 432 433**System capability**: SystemCapability.Communication.IPC 434 435**Since**: 12 436 437**Parameters** 438 439| Name| Description| 440| ------ | ---- | 441| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 442| int32_t value | Value to write.| 443 444**Returns** 445 446| Type| Description| 447| ---- | ---- | 448| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 449 450### OH_IPCParcel_ReadInt32() 451 452```C 453int OH_IPCParcel_ReadInt32(const OHIPCParcel *parcel, int32_t *value) 454``` 455 456**Description** 457 458Reads an int32_t value from an **OHIPCParcel** object. 459 460**System capability**: SystemCapability.Communication.IPC 461 462**Since**: 12 463 464**Parameters** 465 466| Name| Description| 467| ------ | ---- | 468| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 469| int32_t *value | Pointer to the buffer for holding the read data. It cannot be NULL.| 470 471**Returns** 472 473| Type| Description| 474| ---- | ---- | 475| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md) if the read operation fails.| 476 477### OH_IPCParcel_WriteInt64() 478 479```C 480int OH_IPCParcel_WriteInt64(OHIPCParcel *parcel, int64_t value) 481``` 482 483**Description** 484Writes an int64_t value to an **OHIPCParcel** object. 485 486**System capability**: SystemCapability.Communication.IPC 487 488**Since**: 12 489 490**Parameters** 491 492| Name| Description| 493| ------ | ---- | 494| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 495| int64_t value | Value to write.| 496 497**Returns** 498 499| Type| Description| 500| ---- | ---- | 501| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 502 503### OH_IPCParcel_ReadInt64() 504 505```C 506int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int64_t *value) 507``` 508 509**Description** 510 511Reads an int64_t value from an **OHIPCParcel** object. 512 513**System capability**: SystemCapability.Communication.IPC 514 515**Since**: 12 516 517**Parameters** 518 519| Name| Description| 520| ------ | ---- | 521| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 522| int64_t *value | Pointer to the buffer for holding the read data. It cannot be NULL.| 523 524**Returns** 525 526| Type| Description| 527| ---- | ---- | 528| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md) if the read operation fails.| 529 530### OH_IPCParcel_WriteFloat() 531 532```C 533int OH_IPCParcel_WriteFloat(OHIPCParcel *parcel, float value) 534``` 535 536**Description** 537Writes a float value to an **OHIPCParcel** object. 538 539**System capability**: SystemCapability.Communication.IPC 540 541**Since**: 12 542 543**Parameters** 544 545| Name| Description| 546| ------ | ---- | 547| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 548| float value | Value to write.| 549 550**Returns** 551 552| Type| Description| 553| ---- | ---- | 554| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 555 556### OH_IPCParcel_ReadFloat() 557 558```C 559int OH_IPCParcel_ReadFloat(const OHIPCParcel *parcel, float *value) 560``` 561 562**Description** 563 564Reads a float value from an **OHIPCParcel** object. 565 566**System capability**: SystemCapability.Communication.IPC 567 568**Since**: 12 569 570**Parameters** 571 572| Name| Description| 573| ------ | ---- | 574| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 575| float *value | Pointer to the buffer for holding the read data. It cannot be NULL.| 576 577**Returns** 578 579| Type| Description| 580| ---- | ---- | 581| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md) if the read operation fails.| 582 583### OH_IPCParcel_WriteDouble() 584 585```C 586int OH_IPCParcel_WriteDouble(OHIPCParcel *parcel, double value) 587``` 588 589**Description** 590Writes a double value to an **OHIPCParcel** object. 591 592**System capability**: SystemCapability.Communication.IPC 593 594**Since**: 12 595 596**Parameters** 597 598| Name| Description| 599| ------ | ---- | 600| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 601| double value | Value to write.| 602 603**Returns** 604 605| Type| Description| 606| ---- | ---- | 607| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 608 609### OH_IPCParcel_ReadDouble() 610 611```C 612int OH_IPCParcel_ReadDouble(const OHIPCParcel *parcel, double *value) 613``` 614 615**Description** 616 617Reads a double value from an **OHIPCParcel** object. 618 619**System capability**: SystemCapability.Communication.IPC 620 621**Since**: 12 622 623**Parameters** 624 625| Name| Description| 626| ------ | ---- | 627| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 628| double *value | Pointer to the buffer for holding the read data. It cannot be NULL.| 629 630**Returns** 631 632| Type| Description| 633| ---- | ---- | 634| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md) if the read operation fails.| 635 636### OH_IPCParcel_WriteString() 637 638```C 639int OH_IPCParcel_WriteString(OHIPCParcel *parcel, const char *str) 640``` 641 642**Description** 643Writes a string including a string terminator to an **OHIPCParcel** object. 644 645**System capability**: SystemCapability.Communication.IPC 646 647**Since**: 12 648 649**Parameters** 650 651| Name| Description| 652| ------ | ---- | 653| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 654| const char *str | Pointer to the string to write. It cannot be NULL.| 655 656**Returns** 657 658| Type| Description| 659| ---- | ---- | 660| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 661 662### OH_IPCParcel_ReadString() 663 664```C 665const OH_IPCParcel_ReadString(const OHIPCParcel *parcel) 666``` 667 668**Description** 669 670Reads a string from an **OHIPCParcel** object. You can obtain the length of the string from **strlen**. 671 672**System capability**: SystemCapability.Communication.IPC 673 674**Since**: 12 675 676**Parameters** 677 678| Name| Description| 679| ------ | ---- | 680| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 681 682**Returns** 683 684| Type| Description| 685| ---- | ---- | 686| const | Returns the address of the string read if the operation is successful; returns NULL if the operation fails or invalid parameters are found.| 687 688### OH_IPCParcel_WriteBuffer() 689 690```C 691int OH_IPCParcel_WriteBuffer(OHIPCParcel *parcel, const uint8_t *buffer, int32_t len) 692``` 693 694**Description** 695Writes data of the specified length from the memory to an **OHIPCParcel** object. 696 697**System capability**: SystemCapability.Communication.IPC 698 699**Since**: 12 700 701**Parameters** 702 703| Name| Description| 704| ------ | ---- | 705| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 706| const uint8_t *buffer | Pointer to the address of the memory information to write.| 707| int32_t len | Length of the data to write.| 708 709**Returns** 710 711| Type| Description| 712| ---- | ---- | 713| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 714 715### OH_IPCParcel_ReadBuffer() 716 717```C 718const unit8_t* OH_IPCParcel_ReadBuffer(const OHIPCParcel *parcel, int32_t len) 719``` 720 721**Description** 722 723Reads memory information of the specified length from an **OHIPCParcel** object. 724 725**System capability**: SystemCapability.Communication.IPC 726 727**Since**: 12 728 729**Parameters** 730 731| Name| Description| 732| ------ | ---- | 733| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 734| int32_t len | Length of the memory to be read.| 735 736**Returns** 737 738| Type| Description| 739| ---- | ---- | 740| const | Returns the memory address read if the operation is successful; returns NULL if invalid parameters are found or **len** exceeds the readable length of **parcel**.| 741 742### OH_IPCParcel_WriteRemoteStub() 743 744```C 745int OH_IPCParcel_WriteRemoteStub(OHIPCParcel *parcel, const OHIPCRemoteStub *stub) 746``` 747 748**Description** 749 750Writes an **OHIPCRemoteStub** object to an **OHIPCParcel** object. 751 752**System capability**: SystemCapability.Communication.IPC 753 754**Since**: 12 755 756**Parameters** 757 758| Name| Description| 759| ------ | ---- | 760| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 761| const [OHIPCRemoteStub](capi-ohipcparcel-ohipcremotestub.md) *stub | Pointer to the **OHIPCRemoteStub** object to write. It cannot be NULL.| 762 763**Returns** 764 765| Type| Description| 766| ---- | ---- | 767| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 768 769### OH_IPCParcel_ReadRemoteStub() 770 771```C 772OHIPCRemoteStub* OH_IPCParcel_ReadRemoteStub(const OHIPCParcel *parcel) 773``` 774 775**Description** 776 777Reads the **OHIPCRemoteStub** object from an **OHIPCParcel** object. 778 779**System capability**: SystemCapability.Communication.IPC 780 781**Since**: 12 782 783**Parameters** 784 785| Name| Description| 786| ------ | ---- | 787| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 788 789**Returns** 790 791| Type| Description| 792| ---- | ---- | 793| OHIPCRemoteStub* | Returns the pointer to the **OHIPCRemoteStub** object read if the operation is successful; returns NULL otherwise.| 794 795### OH_IPCParcel_WriteRemoteProxy() 796 797```C 798int OH_IPCParcel_WriteRemoteProxy(OHIPCParcel *parcel, const OHIPCRemoteProxy *proxy) 799``` 800 801**Description** 802 803Writes an **OHIPCRemoteProxy** object to an **OHIPCParcel** object. 804 805**System capability**: SystemCapability.Communication.IPC 806 807**Since**: 12 808 809**Parameters** 810 811| Name| Description| 812| ------ | ---- | 813| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 814| const [OHIPCRemoteProxy](capi-ohipcparcel-ohipcremoteproxy.md) *proxy | Pointer to the **OHIPCRemoteProxy** object to write. It cannot be NULL.| 815 816**Returns** 817 818| Type| Description| 819| ---- | ---- | 820| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 821 822### OH_IPCParcel_ReadRemoteProxy() 823 824```C 825OHIPCRemoteProxy* OH_IPCParcel_ReadRemoteProxy(const OHIPCParcel *parcel) 826``` 827 828**Description** 829 830Reads the **OHIPCRemoteProxy** object from an **OHIPCParcel** object. 831 832**System capability**: SystemCapability.Communication.IPC 833 834**Since**: 12 835 836**Parameters** 837 838| Name| Description| 839| ------ | ---- | 840| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 841 842**Returns** 843 844| Type| Description| 845| ---- | ---- | 846| OHIPCRemoteProxy* | Returns the pointer to the **OHIPCRemoteProxy** object created if the operation is successful; returns NULL otherwise.| 847 848### OH_IPCParcel_WriteFileDescriptor() 849 850```C 851int OH_IPCParcel_WriteFileDescriptor(OHIPCParcel *parcel, int32_t fd) 852``` 853 854**Description** 855Writes a file descriptor to an **OHIPCParcel** object. 856 857**System capability**: SystemCapability.Communication.IPC 858 859**Since**: 12 860 861**Parameters** 862 863| Name| Description| 864| ------ | ---- | 865| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 866| int32_t fd | Pointer to the file descriptor to write.| 867 868**Returns** 869 870| Type| Description| 871| ---- | ---- | 872| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 873 874### OH_IPCParcel_ReadFileDescriptor() 875 876```C 877const unit8_t* OH_IPCParcel_ReadFileDescriptor(const OHIPCParcel *parcel, int32_t *fd) 878``` 879 880**Description** 881 882Reads a file descriptor from an **OHIPCParcel** object. 883 884**System capability**: SystemCapability.Communication.IPC 885 886**Since**: 12 887 888**Parameters** 889 890| Name| Description| 891| ------ | ---- | 892| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 893| int32_t *fd | Pointer to the file descriptor to read. It cannot be NULL.| 894 895**Returns** 896 897| Type| Description| 898| ---- | ---- | 899| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md) if the read operation fails.| 900 901### OH_IPCParcel_Append() 902 903```C 904const unit8_t* OH_IPCParcel_Append(OHIPCParcel *parcel, const OHIPCParcel *data) 905``` 906 907**Description** 908 909Appends data to an **OHIPCParcel** object. 910 911**System capability**: SystemCapability.Communication.IPC 912 913**Since**: 12 914 915**Parameters** 916 917| Name| Description| 918| ------ | ---- | 919| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 920| const [OHIPCParcel](capi-ohipcparcel.md) *data | Pointer to the data to append. It cannot be NULL.| 921 922**Returns** 923 924| Type| Description| 925| ---- | ---- | 926| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the operation fails.| 927 928### OH_IPCParcel_WriteInterfaceToken() 929 930```C 931int OH_IPCParcel_WriteInterfaceToken(OHIPCParcel *parcel, const char *token) 932``` 933 934**Description** 935Writes an interface token to an **OHIPCParcel** object for interface identity verification. 936 937**System capability**: SystemCapability.Communication.IPC 938 939**Since**: 12 940 941**Parameters** 942 943| Name| Description| 944| ------ | ---- | 945| [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 946| const char *token | Pointer to the interface token to write. It cannot be NULL.| 947 948**Returns** 949 950| Type| Description| 951| ---- | ---- | 952| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found;<br> returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md) if the write operation fails.| 953 954### OH_IPCParcel_ReadInterfaceToken() 955 956```C 957int OH_IPCParcel_ReadInterfaceToken(const OHIPCParcel *parcel, char **token, int32_t *len, OH_IPC_MemAllocator allocator) 958``` 959 960**Description** 961 962Reads an interface token from an **OHIPCParcel** object for interface identity verification. 963 964**System capability**: SystemCapability.Communication.IPC 965 966**Since**: 12 967 968**Parameters** 969 970| Name| Description| 971| ------ | ---- | 972| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | Pointer to the **OHIPCParcel** object. It cannot be NULL.| 973| char **token | Double pointer to the interface token to read. The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL. If an error code is returned, you still need to check whether the memory is empty and release the memory. Otherwise, memory leaks may occur.| 974| int32_t *len | Pointer to the length of the interface token read, including the terminator. It cannot be NULL.| 975| [OH_IPC_MemAllocator](#oh_ipc_memallocator) allocator | Memory allocator specified by the user for allocating memory for **token**. It cannot be NULL.| 976 977**Returns** 978 979| Type| Description| 980| ---- | ---- | 981| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if invalid parameters are found; returns [OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md) if the read operation fails.| 982