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