• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ipc_cparcel.h
2<!--Kit: IPC Kit-->
3<!--Subsystem: Communication-->
4<!--Owner: @xdx19211@luodonghui0157-->
5<!--Designer: @zhaopeng_gitee-->
6<!--Tester: @maxiaorong-->
7<!--Adviser: @zhang_yixin13-->
8
9## 概述
10
11提供IPC序列化/反序列化C接口。
12
13**库:** libipc_capi.so
14
15**系统能力:** SystemCapability.Communication.IPC.Core
16
17**起始版本:** 12
18
19**相关模块:**[OHIPCParcel](capi-ohipcparcel.md)
20
21## 汇总
22
23### 结构体
24
25| 名称 | typedef关键字 | 描述 |
26| ---- | ------------- | ---- |
27| [OHIPCParcel](capi-ohipcparcel.md) | OHIPCParcel | IPC序列化对象。 |
28| [OHIPCRemoteProxy](capi-ohipcparcel-ohipcremoteproxy.md) | OHIPCRemoteProxy | IPC远端代理对象。 |
29| [OHIPCRemoteStub](capi-ohipcparcel-ohipcremotestub.md) | OHIPCRemoteStub | IPC远端服务对象。 |
30
31### 函数
32
33| 名称 | typedef关键字 | 描述 |
34| ---- | ------------- | ---- |
35| [typedef void* (\*OH_IPC_MemAllocator)(int32_t len)](#oh_ipc_memallocator) | OH_IPC_MemAllocator | 内存分配函数类型。 |
36| [OHIPCParcel* OH_IPCParcel_Create(void)](#oh_ipcparcel_create) | - | 创建OHIPCParcel对象,对象可序列化大小不能超过204800字节。 |
37| [void OH_IPCParcel_Destroy(OHIPCParcel *parcel)](#oh_ipcparcel_destroy) | - | 销毁OHIPCParcel对象。 |
38| [int OH_IPCParcel_GetDataSize(const OHIPCParcel *parcel)](#oh_ipcparcel_getdatasize) | - | 获取OHIPCParcel对象包含的数据的大小。 |
39| [int OH_IPCParcel_GetWritableBytes(const OHIPCParcel *parcel)](#oh_ipcparcel_getwritablebytes) | - | 获取OHIPCParcel对象可以写入的字节数。 |
40| [int OH_IPCParcel_GetReadableBytes(const OHIPCParcel *parcel)](#oh_ipcparcel_getreadablebytes) | - | 获取OHIPCParcel对象还可以读取的字节数。 |
41| [int OH_IPCParcel_GetReadPosition(const OHIPCParcel *parcel)](#oh_ipcparcel_getreadposition) | - | 获取OHIPCParcel对象当前读取位置。 |
42| [int OH_IPCParcel_GetWritePosition(const OHIPCParcel *parcel)](#oh_ipcparcel_getwriteposition) | - | 获取OHIPCParcel对象当前写入位置。 |
43| [int OH_IPCParcel_RewindReadPosition(OHIPCParcel *parcel, uint32_t newReadPos)](#oh_ipcparcel_rewindreadposition) | - | 重置OHIPCParcel对象读取位置。 |
44| [int OH_IPCParcel_RewindWritePosition(OHIPCParcel *parcel, uint32_t newWritePos)](#oh_ipcparcel_rewindwriteposition) | - | 重置OHIPCParcel对象写入位置。 |
45| [int OH_IPCParcel_WriteInt8(OHIPCParcel *parcel, int8_t value)](#oh_ipcparcel_writeint8) | - | 向OHIPCParcel对象写入一个int8_t值。 |
46| [int OH_IPCParcel_ReadInt8(const OHIPCParcel *parcel, int8_t *value)](#oh_ipcparcel_readint8) | - | 从OHIPCParcel对象中读取一个int8_t值。 |
47| [int OH_IPCParcel_WriteInt16(OHIPCParcel *parcel, int16_t value)](#oh_ipcparcel_writeint16) | - | 向OHIPCParcel对象写入一个int16_t值。 |
48| [int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int16_t *value)](#oh_ipcparcel_readint16) | - | 从OHIPCParcel对象中读取一个int16_t值。 |
49| [int OH_IPCParcel_WriteInt32(OHIPCParcel *parcel, int32_t value)](#oh_ipcparcel_writeint32) | - | 向OHIPCParcel对象写入一个int32_t值。 |
50| [int OH_IPCParcel_ReadInt32(const OHIPCParcel *parcel, int32_t *value)](#oh_ipcparcel_readint32) | - | 从OHIPCParcel对象中读取一个int32_t值。 |
51| [int OH_IPCParcel_WriteInt64(OHIPCParcel *parcel, int64_t value)](#oh_ipcparcel_writeint64) | - | 向OHIPCParcel对象写入一个int64_t值。 |
52| [int OH_IPCParcel_ReadInt64(const OHIPCParcel *parcel, int64_t *value)](#oh_ipcparcel_readint64) | - | 从OHIPCParcel对象中读取一个int64_t值。 |
53| [int OH_IPCParcel_WriteFloat(OHIPCParcel *parcel, float value)](#oh_ipcparcel_writefloat) | - | 向OHIPCParcel对象写入一个float值。 |
54| [int OH_IPCParcel_ReadFloat(const OHIPCParcel *parcel, float *value)](#oh_ipcparcel_readfloat) | - | 从OHIPCParcel对象中读取一个float值。 |
55| [int OH_IPCParcel_WriteDouble(OHIPCParcel *parcel, double value)](#oh_ipcparcel_writedouble) | - | 向OHIPCParcel对象写入一个double值。 |
56| [int OH_IPCParcel_ReadDouble(const OHIPCParcel *parcel, double *value)](#oh_ipcparcel_readdouble) | - | 从OHIPCParcel对象中读取一个double值。 |
57| [int OH_IPCParcel_WriteString(OHIPCParcel *parcel, const char *str)](#oh_ipcparcel_writestring) | - | 向OHIPCParcel对象写入字符串,包含字符串结束符。 |
58| [const char OH_IPCParcel_ReadString(const OHIPCParcel *parcel)](#oh_ipcparcel_readstring) | - | 从OHIPCParcel对象读取字符串,用户可通过strlen获取字符串长度。 |
59| [int OH_IPCParcel_Writebuffer(OHIPCParcel *parcel, const uint8_t *buffer, size_t len)](#oh_ipcparcel_writebuffer) | - | 向OHIPCParcel对象写入指定长度的内存信息。 |
60| [const uint8_t *OH_IPCParcel_ReadBuffer(const OHIPCParcel *parcel, int32_t len)](#oh_ipcparcel_readbuffer) | - | 从OHIPCParcel对象读取指定长度的内存信息。 |
61| [int OH_IPCParcel_WriteRemoteStub(OHIPCParcel *parcel, const OHRemoteObject *stub)](#oh_ipcparcel_writeremotestub) | - | 向OHIPCParcel对象写入OHRemoteObject对象。 |
62| [OHIPCRemoteStub* OH_IPCParcel_ReadRemoteStub(OHIPCParcel *parcel)](#oh_ipcparcel_readremotestub) | - | 从OHIPCParcel对象读取OHRemoteObject对象。 |
63| [int OH_IPCParcel_WriteRemoteProxy(OHIPCParcel *parcel, const OHRemoteObject *proxy)](#oh_ipcparcel_writeremoteproxy) | - | 向OHIPCParcel对象写入OHRemoteObject对象。 |
64| [OHIPCRemoteProxy* OH_IPCParcel_ReadRemoteProxy(OHIPCParcel *parcel)](#oh_ipcparcel_readremoteproxy) | - | 从OHIPCParcel对象读取OHRemoteObject对象。 |
65| [int OH_IPCParcel_WriteFileDescriptor(OHIPCParcel *parcel, int32_t fd)](#oh_ipcparcel_writefiledescriptor) | - | 向OHIPCParcel对象写入文件描述符。 |
66| [int OH_IPCParcel_ReadFileDescriptor(OHIPCParcel *parcel int32_t *fd)](#oh_ipcparcel_readfiledescriptor) | - | 从OHIPCParcel对象读取文件描述符。 |
67| [int OH_IPCParcel_Append(OHIPCParcel *parcel, const OHIPCParcel *data)](#oh_ipcparcel_append) | - | OHIPCParcel对象数据拼接。 |
68| [int OH_IPCParcel_WriteInterfaceToken(OHIPCParcel *parcel, const char *token)](#oh_ipcparcel_writeinterfacetoken) | - | 向OHIPCParcel对象写入接口描述符,用于接口身份校验。 |
69| [int OH_IPCParcel_ReadInterfaceToken(OHIPCParcel *parcel, char **token, int32_t *len)](#oh_ipcparcel_readinterfacetoken) | - | 从OHIPCParcel对象读取接口描述符信息,用于接口身份校验。 |
70
71## 函数说明
72
73### OH_IPC_MemAllocator()
74
75```C
76typedef void* (OH_IPC_MemAllocator)(int32_t len)
77```
78
79**描述:**
80
81内存分配函数类型。
82
83**系统能力:** SystemCapability.Communication.IPC.Core
84
85**起始版本:** 12
86
87**参数:**
88
89| 参数项 | 描述 |
90| ------ | ---- |
91|int32_t len | len 申请内存的长度。 |
92
93**返回:**
94
95| 类型 | 说明 |
96| ---- | ---- |
97| void* | 成功返回分配的内存地址;失败返回NULL。 |
98
99### OH_IPCParcel_Create()
100
101```C
102OHIPCParcel* OH_IPCParcel_Create(void)
103```
104
105**描述:**
106
107创建OHIPCParcel对象,对象可许序列化大小不能超过204800字节。
108
109**系统能力:** SystemCapability.Communication.IPC.Core
110
111**起始版本:** 12
112
113**返回:**
114
115| 类型 | 说明 |
116| ---- | ---- |
117| OHIPCParcel* | 成功返回OHIPCParcel对象指针;失败返回NULL。 |
118
119### OH_IPCParcel_Destroy()
120
121```C
122void OH_IPCParcel_Destroy(OHIPCParcel *parcel)
123```
124
125**描述:**
126
127销毁OHIPCParcel对象。
128
129**系统能力:** SystemCapability.Communication.IPC.Core
130
131**起始版本:** 12
132
133**参数:**
134
135| 参数项 | 描述 |
136| ------ | ---- |
137| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel 需要销毁OHIPCParcel对象的指针。 |
138
139### OH_IPCParcel_GetDataSize()
140
141``` C
142int OH_IPCParcel_GetDataSize(const OHIPCParcel *parcel)
143```
144
145**描述:**
146获取OHIPCParcel对象包含的数据的大小。
147
148**系统能力:** SystemCapability.Communication.IPC.Core
149
150**起始版本:** 12
151
152**参数:**
153
154| 参数项 | 描述 |
155| ------ | ---- |
156| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
157
158**返回:**
159
160| 类型 | 描述 |
161| ---- | ---- |
162| int | 返回数据大小,参数不合法时返回-1。 |
163
164### OH_IPCParcel_GetWritableBytes()
165
166```C
167int OH_IPCParcel_GetWritableBytes(const OHIPCParcel *parcel)
168```
169
170**描述:**
171
172获取OHIPCParcel对象可以写入的字节数。
173
174**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
175
176**起始版本:** 12
177
178**参数:**
179
180| 参数项 | 描述 |
181| ------ | ---- |
182| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
183
184**返回:**
185
186| 类型 | 说明 |
187| ---- | ---- |
188| int | 返回可写字节数大小,参数不合法时返回-1。 |
189
190### OH_IPCParcel_GetReadableBytes()
191
192```C
193int OH_IPCParcel_GetReadableBytes(const OHIPCParcel *parcel)
194```
195
196**描述:**
197
198获取OHIPCParcel对象还可以读取的字节数。
199
200**系统能力:** SystemCapability.Communication.IPC
201
202**起始版本:** 12
203
204**参数:**
205
206| 参数项 | 描述 |
207| ------ | ---- |
208| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
209
210**返回:**
211
212| 类型 | 说明 |
213| ---- | ---- |
214| int | 返回可读字节数大小,参数不合法时时返回-1。 |
215
216### OH_IPCParcel_GetReadPosition()
217
218```C
219int OH_IPCParcel_GetReadPosition(const OH_IPCParcel *parcel)
220```
221
222**描述:**
223
224获取OHIPCParcel对象当前读取位置。
225
226**参数:**
227
228| 参数项 | 描述 |
229| ---- | ---- |
230| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
231
232**返回:**
233
234| 类型 | 说明 |
235| ---- | ---- |
236| int | 返回当前读位置,参数不合法时返回-1。 |
237
238### OH_IPCParcel_GetWritePosition()
239
240```C
241int OH_IPCParcel_GetWritePosition(const OHIPCParcel *parcel)
242```
243
244**描述:**
245
246获取OHIPCParcel对象当前写入位置。
247
248**系统能力:** SystemCapability.Communication.IPC
249
250**起始版本:** 12
251
252**参数:**
253
254| 参数项| 描述 |
255| ----- | ---- |
256| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
257
258**返回:**
259
260| 类型 | 说明 |
261| ---- | ---- |
262| int | 返回当前写入位置,参数不合法时返回-1。 |
263
264### OH_IPCParcel_RewindReadPosition()
265
266```c
267int OH_IPCParcel_RewindReadPosition(OHIPCParcel *parcel, uint32_t newReadPos)
268```
269
270**描述:**
271
272重置OHIPCParcel对象读取位置。
273
274**系统能力:** SystemCapability.Communication.IPC.Core
275
276**起始版本:** 12
277
278**参数:**
279
280| 参数项 | 描述 |
281| ------ | ---- |
282| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
283| uint32_t newReadPos | newReadPos 新的读取位置,范围:[0,当前数据大小]。 |
284
285**返回:**
286
287| 类型 | 说明 |
288| ---- | ---- |
289| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
290
291### OH_IPCParcel_RewindWritePosition()
292
293```C
294int OH_IPCParcel_RewindWritePosition(OHIPCParcel *parcel, uint32_t newWritePos);
295```
296
297**描述:**
298
299重置OHIPCParcel的写入位置。
300
301**系统能力:** SystemCapability.Communication.IPC.Core
302
303**起始版本:** 12
304
305**参数:**
306
307| 参数项 | 描述 |
308| ------ | ---- |
309| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
310| uint32_t newWritePos | newWritePos 新的写入位置,范围:[0, 当前数据大小]。 |
311
312**返回:**
313
314| 类型 | 描述 |
315| ---- | ---- |
316| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
317
318### OH_IPCParcel_WriteInt8()
319
320```C
321int OH_IPCParcel_WriteInt8(OHIPCParcel *parcel, int8_t value)
322```
323
324**描述:**
325
326向OHIPCParcel写入一个int8_t值。
327
328**系统能力:** SystemCapability.Communication.IPC.Core
329
330**起始版本:** 12
331
332**参数:**
333
334| 参数项 | 描述 |
335| ------ | ---- |
336| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
337| int8_t value | value 要写入的值。 |
338
339**返回:**
340
341| 返回 | 说明 |
342| -----| ---- |
343| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
344
345### OH_IPCParcel_ReadInt8()
346
347```C
348int OH_IPCParcel_ReadInt8(OHIPCParcel *parcel, int8_t *value)
349```
350
351**描述:**
352
353从OHIPCParcel对象中读取int8_t值。
354
355**系统能力:** SystemCapability.Communication.IPC
356
357**起始版本:** 12
358
359**参数:**
360
361| 参数项 | 描述 |
362| ------ | ---- |
363| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
364| int8_t *value | value 存储读取数据的指针,不能为空。 |
365
366**返回:**
367
368| 返回 | 描述 |
369| ---- | ---- |
370| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 读取失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
371
372### OH_IPCParcel_WriteInt16()
373
374```C
375int OH_IPCParcel_WriteInt16(OHIPCParcel *parcel, int16_t value)
376```
377
378**描述:**
379向OHIPCParcel对象写入int16_t值。
380
381**系统能力:** SystemCapability.Communication.IPC
382
383**起始版本:** 12
384
385**参数:**
386
387| 参数项 | 描述 |
388| ------ | ---- |
389| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
390| int16_t value | value 要写入的值。 |
391
392**返回:**
393
394| 类型 | 说明 |
395| ---- | ---- |
396| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
397
398### OH_IPCParcel_ReadInt16()
399
400```C
401int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int16_t *value)
402```
403
404**描述:**
405
406从OHIPCParcel对象读取int16_t值。
407
408**系统能力:** SystemCapability.Communication.IPC
409
410**起始版本:** 12
411
412**参数:**
413
414| 参数项 | 描述 |
415| ------ | ---- |
416| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
417| int16_t *value | value 存储读取数据的指针,不能为空。 |
418
419**返回:**
420
421| 类型 | 说明 |
422| ---- | ---- |
423| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 读取失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
424
425### OH_IPCParcel_WriteInt32()
426
427```C
428int OH_IPCParcel_WriteInt32(OHIPCParcel *parcel, int32_t value)
429```
430
431**描述:**
432向OHIPCParcel对象写入int32_t值。
433
434**系统能力:** SystemCapability.Communication.IPC
435
436**起始版本:** 12
437
438**参数:**
439
440| 参数项 | 描述 |
441| ------ | ---- |
442| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
443| int32_t value | value 要写入的值。 |
444
445**返回:**
446
447| 类型 | 说明 |
448| ---- | ---- |
449| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
450
451### OH_IPCParcel_ReadInt32()
452
453```C
454int OH_IPCParcel_ReadInt32(const OHIPCParcel *parcel, int32_t *value)
455```
456
457**描述:**
458
459从OHIPCParcel对象读取int32_t值。
460
461**系统能力:** SystemCapability.Communication.IPC
462
463**起始版本:** 12
464
465**参数:**
466
467| 参数项 | 描述 |
468| ------ | ---- |
469| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
470| int32_t *value | value 存储读取数据的指针,不能为空。 |
471
472**返回:**
473
474| 类型 | 说明 |
475| ---- | ---- |
476| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 读取失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
477
478### OH_IPCParcel_WriteInt64()
479
480```C
481int OH_IPCParcel_WriteInt64(OHIPCParcel *parcel, int64_t value)
482```
483
484**描述:**
485向OHIPCParcel对象写入int64_t值。
486
487**系统能力:** SystemCapability.Communication.IPC
488
489**起始版本:** 12
490
491**参数:**
492
493| 参数项 | 描述 |
494| ------ | ---- |
495| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
496| int64_t value | value 要写入的值。 |
497
498**返回:**
499
500| 类型 | 说明 |
501| ---- | ---- |
502| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
503
504### OH_IPCParcel_ReadInt64()
505
506```C
507int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int64_t *value)
508```
509
510**描述:**
511
512从OHIPCParcel对象读取int64_t值。
513
514**系统能力:** SystemCapability.Communication.IPC
515
516**起始版本:** 12
517
518**参数:**
519
520| 参数项 | 描述 |
521| ------ | ---- |
522| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
523| int64_t *value | value 存储读取数据的指针,不能为空。 |
524
525**返回:**
526
527| 类型 | 说明 |
528| ---- | ---- |
529| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 读取失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
530
531### OH_IPCParcel_WriteFloat()
532
533```C
534int OH_IPCParcel_WriteFloat(OHIPCParcel *parcel, float value)
535```
536
537**描述:**
538向OHIPCParcel对象写入float值。
539
540**系统能力:** SystemCapability.Communication.IPC
541
542**起始版本:** 12
543
544**参数:**
545
546| 参数项 | 描述 |
547| ------ | ---- |
548| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
549| float value | value 要写入的值。 |
550
551**返回:**
552
553| 类型 | 说明 |
554| ---- | ---- |
555| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
556
557### OH_IPCParcel_ReadFloat()
558
559```C
560int OH_IPCParcel_ReadFloat(const OHIPCParcel *parcel, float *value)
561```
562
563**描述:**
564
565从OHIPCParcel对象读取float值。
566
567**系统能力:** SystemCapability.Communication.IPC
568
569**起始版本:** 12
570
571**参数:**
572
573| 参数项 | 描述 |
574| ------ | ---- |
575| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
576| float *value | value 存储读取数据的指针,不能为空。 |
577
578**返回:**
579
580| 类型 | 说明 |
581| ---- | ---- |
582| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 读取失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
583
584### OH_IPCParcel_WriteDouble()
585
586```C
587int OH_IPCParcel_WriteDouble(OHIPCParcel *parcel, double value)
588```
589
590**描述:**
591向OHIPCParcel对象写入double值。
592
593**系统能力:** SystemCapability.Communication.IPC
594
595**起始版本:** 12
596
597**参数:**
598
599| 参数项 | 描述 |
600| ------ | ---- |
601| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
602| double value | value 要写入的值。 |
603
604**返回:**
605
606| 类型 | 说明 |
607| ---- | ---- |
608| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
609
610### OH_IPCParcel_ReadDouble()
611
612```C
613int OH_IPCParcel_ReadDouble(const OHIPCParcel *parcel, double *value)
614```
615
616**描述:**
617
618从OHIPCParcel对象读取double值。
619
620**系统能力:** SystemCapability.Communication.IPC
621
622**起始版本:** 12
623
624**参数:**
625
626| 参数项 | 描述 |
627| ------ | ---- |
628| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
629| double *value | value 存储读取数据的指针,不能为空。 |
630
631**返回:**
632
633| 类型 | 说明 |
634| ---- | ---- |
635| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 读取失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
636
637### OH_IPCParcel_WriteString()
638
639```C
640int OH_IPCParcel_WriteString(OHIPCParcel *parcel, const char *str)
641```
642
643**描述:**
644向OHIPCParcel对象写入字符串,包括字符串结束符。
645
646**系统能力:** SystemCapability.Communication.IPC
647
648**起始版本:** 12
649
650**参数:**
651
652| 参数项 | 描述 |
653| ------ | ---- |
654| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
655| const char *str | str 写入字符串,不能为空。 |
656
657**返回:**
658
659| 类型 | 说明 |
660| ---- | ---- |
661| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
662
663### OH_IPCParcel_ReadString()
664
665```C
666const OH_IPCParcel_ReadString(const OHIPCParcel *parcel)
667```
668
669**描述:**
670
671从OHIPCParcel对象读取字符串,用户可通过strlen获取字符串长度。
672
673**系统能力:** SystemCapability.Communication.IPC
674
675**起始版本:** 12
676
677**参数:**
678
679| 参数项 | 描述 |
680| ------ | ---- |
681| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
682
683**返回:**
684
685| 类型 | 说明 |
686| ---- | ---- |
687| const | 成功返回读取字符串地址;参数不合法或读取失败时返回NULL。 |
688
689### OH_IPCParcel_WriteBuffer()
690
691```C
692int OH_IPCParcel_WriteBuffer(OHIPCParcel *parcel, const uint8_t *buffer, int32_t len)
693```
694
695**描述:**
696向OHIPCParcel对象写入指定长度的内存信息。
697
698**系统能力:** SystemCapability.Communication.IPC
699
700**起始版本:** 12
701
702**参数:**
703
704| 参数项 | 描述 |
705| ------ | ---- |
706| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
707| const uint8_t *buffer | buffer 写入内存地址信息。 |
708| int32_t len | len 写入信息长度。 |
709
710**返回:**
711
712| 类型 | 说明 |
713| ---- | ---- |
714| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
715
716### OH_IPCParcel_ReadBuffer()
717
718```C
719const unit8_t* OH_IPCParcel_ReadBuffer(const OHIPCParcel *parcel, int32_t len)
720```
721
722**描述:**
723
724从OHIPCParcel对象读取指定长度内存信息。
725
726**系统能力:** SystemCapability.Communication.IPC
727
728**起始版本:** 12
729
730**参数:**
731
732| 参数项 | 描述 |
733| ------ | ---- |
734| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
735| int32_t len | len 读取内存的长度。 |
736
737**返回:**
738
739| 类型 | 说明 |
740| ---- | ---- |
741| const | 成功返回读取到的内存地址;参数不合法或len超过parcel可读长度时返回NULL。 |
742
743### OH_IPCParcel_WriteRemoteStub()
744
745```C
746int OH_IPCParcel_WriteRemoteStub(OHIPCParcel *parcel, const OHIPCRemoteStub *stub)
747```
748
749**描述:**
750
751向OHIPCParcel对象写入OHIPCRemoteStub对象。
752
753**系统能力:** SystemCapability.Communication.IPC
754
755**起始版本:** 12
756
757**参数:**
758
759| 参数项 | 描述 |
760| ------ | ---- |
761| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
762| const [OHIPCRemoteStub](capi-ohipcparcel-ohipcremotestub.md) *stub | stub 需要写入的OHIPCRemoteStub对象指针,不能为空。 |
763
764**返回:**
765
766| 类型 | 说明 |
767| ---- | ---- |
768| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
769
770### OH_IPCParcel_ReadRemoteStub()
771
772```C
773OHIPCRemoteStub* OH_IPCParcel_ReadRemoteStub(const OHIPCParcel *parcel)
774```
775
776**描述:**
777
778从OHIPCParcel对象读取OHIPCRemoteStub对象。
779
780**系统能力:** SystemCapability.Communication.IPC
781
782**起始版本:** 12
783
784**参数:**
785
786| 参数项 | 描述 |
787| ------ | ---- |
788| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
789
790**返回:**
791
792| 类型 | 说明 |
793| ---- | ---- |
794| OHIPCRemoteStub* | 成功返回OHIPCRemoteStub对象指针;失败返回NULL。 |
795
796### OH_IPCParcel_WriteRemoteProxy()
797
798```C
799int OH_IPCParcel_WriteRemoteProxy(OHIPCParcel *parcel, const OHIPCRemoteProxy *proxy)
800```
801
802**描述:**
803
804向OHIPCParcel对象写入OHIPCRemoteProxy对象。
805
806**系统能力:** SystemCapability.Communication.IPC
807
808**起始版本:** 12
809
810**参数:**
811
812| 参数项 | 描述 |
813| ------ | ---- |
814| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
815| const [OHIPCRemoteProxy](capi-ohipcparcel-ohipcremoteproxy.md) *proxy | proxy 需要写入的OHIPCRemoteProxy对象指针,不能为空。 |
816
817**返回:**
818
819| 类型 | 说明 |
820| ---- | ---- |
821| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
822
823### OH_IPCParcel_ReadRemoteProxy()
824
825```C
826OHIPCRemoteProxy* OH_IPCParcel_ReadRemoteProxy(const OHIPCParcel *parcel)
827```
828
829**描述:**
830
831从OHIPCParcel对象读取OHIPCRemoteProxy对象。
832
833**系统能力:** SystemCapability.Communication.IPC
834
835**起始版本:** 12
836
837**参数:**
838
839| 参数项 | 描述 |
840| ------ | ---- |
841| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
842
843**返回:**
844
845| 类型 | 说明 |
846| ---- | ---- |
847| OHIPCRemoteProxy* | 成功返回OHIPCRemoteProxy对象指针;失败返回NULL。 |
848
849### OH_IPCParcel_WriteFileDescriptor()
850
851```C
852int OH_IPCParcel_WriteFileDescriptor(OHIPCParcel *parcel, int32_t fd)
853```
854
855**描述:**
856向OHIPCParcel对象写入文件描述符。
857
858**系统能力:** SystemCapability.Communication.IPC
859
860**起始版本:** 12
861
862**参数:**
863
864| 参数项 | 描述 |
865| ------ | ---- |
866| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
867| int32_t fd | fd 要写入的文件描述符。 |
868
869**返回:**
870
871| 类型 | 说明 |
872| ---- | ---- |
873| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
874
875### OH_IPCParcel_ReadFileDescriptor()
876
877```C
878const unit8_t* OH_IPCParcel_ReadFileDescriptor(const OHIPCParcel *parcel, int32_t *fd)
879```
880
881**描述:**
882
883从OHIPCParcel对象读取文件描述符。
884
885**系统能力:** SystemCapability.Communication.IPC
886
887**起始版本:** 12
888
889**参数:**
890
891| 参数项 | 描述 |
892| ------ | ---- |
893| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
894| int32_t *fd | fd 存储读取文件描述符的指针,不能为空。 |
895
896**返回:**
897
898| 类型 | 说明 |
899| ---- | ---- |
900| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 读取失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
901
902### OH_IPCParcel_Append()
903
904```C
905const unit8_t* OH_IPCParcel_Append(OHIPCParcel *parcel, const OHIPCParcel *data)
906```
907
908**描述:**
909
910OHIPCParcel对象数据拼接。
911
912**系统能力:** SystemCapability.Communication.IPC
913
914**起始版本:** 12
915
916**参数:**
917
918| 参数项 | 描述 |
919| ------ | ---- |
920| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
921| const [OHIPCParcel](capi-ohipcparcel.md) *data | data 源OHIPCParcel对象的指针,不能为空。 |
922
923**返回:**
924
925| 类型 | 说明 |
926| ---- | ---- |
927| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 拼接失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
928
929### OH_IPCParcel_WriteInterfaceToken()
930
931```C
932int OH_IPCParcel_WriteInterfaceToken(OHIPCParcel *parcel, const char *token)
933```
934
935**描述:**
936向OHIPCParcel对象写入接口描述符,用于接口身份校验。
937
938**系统能力:** SystemCapability.Communication.IPC
939
940**起始版本:** 12
941
942**参数:**
943
944| 参数项 | 描述 |
945| ------ | ---- |
946| [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
947| const char *token | token 需要写入的接口描述符信息,不能为空。 |
948
949**返回:**
950
951| 类型 | 说明 |
952| ---- | ---- |
953| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 写入失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
954
955### OH_IPCParcel_ReadInterfaceToken()
956
957```C
958int OH_IPCParcel_ReadInterfaceToken(const OHIPCParcel *parcel, char **token, int32_t *len, OH_IPC_MemAllocator allocator)
959```
960
961**描述:**
962
963从OHIPCParcel对象读取接口描述符信息,用于接口身份校验。
964
965**系统能力:** SystemCapability.Communication.IPC
966
967**起始版本:** 12
968
969**参数:**
970
971| 参数项 | 描述 |
972| ------ | ---- |
973| const [OHIPCParcel](capi-ohipcparcel.md) *parcel | parcel OHIPCParcel对象的指针,不能为空。 |
974| char **token | token 用于存储接口描述符信息的内存地址,该内存由用户提供的分配器进行内存分配,用户使用完后需要主动释放,不能为空。接口返回失败时,用户依然需要判断该内存是否为空,并主动释放,否则辉造成内存泄漏。 |
975| int32_t *len | len 存储读取接口描述符的长度,包括结束符,不能为空。 |
976| [OH_IPC_MemAllocator](#oh_ipc_memallocator) allocator | allocator 用户指定的用来分配token的内存分配器,不能为空。 |
977
978**返回:**
979
980| 类型 | 说明 |
981| ---- | ---- |
982| int | 成功返回[OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md#oh_ipc_errorcode);<br> 参数不合法时返回[OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode);读取失败返回[OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR](capi-ipc-error-code-h.md#oh_ipc_errorcode)。 |
983