xref: /interface/sdk_c/IPCKit/ipc_cparcel.h (revision 7777dab0)
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef CAPI_INCLUDE_IPC_CPARCEL_H
17#define CAPI_INCLUDE_IPC_CPARCEL_H
18
19/**
20 * @addtogroup OHIPCParcel
21 * @{
22 *
23 * @brief Defines C interfaces for IPC serialization and deserialization.
24 *
25 * @syscap SystemCapability.Communication.IPC.Core
26 * @since 12
27 */
28
29/**
30 * @file ipc_cparcel.h
31 *
32 * @brief Defines C interfaces for IPC serialization and deserialization.
33 *
34 * @library libipc_capi.so
35 * @kit IPCKit
36 * @syscap SystemCapability.Communication.IPC.Core
37 * @since 12
38 */
39
40#include <stdint.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/**
47* @brief Defines an IPC serialized object.
48*
49* @syscap SystemCapability.Communication.IPC.Core
50* @since 12
51*/
52struct OHIPCParcel;
53
54/**
55* @brief Typedef an IPC serialized object.
56*
57* @syscap SystemCapability.Communication.IPC.Core
58* @since 12
59*/
60typedef struct OHIPCParcel OHIPCParcel;
61
62/**
63* @brief Defines an IPC remote proxy object.
64*
65* @syscap SystemCapability.Communication.IPC.Core
66* @since 12
67*/
68struct OHIPCRemoteProxy;
69
70/**
71* @brief Typedef an IPC remote proxy object.
72*
73* @syscap SystemCapability.Communication.IPC.Core
74* @since 12
75*/
76typedef struct OHIPCRemoteProxy OHIPCRemoteProxy;
77
78/**
79* @brief Defines an IPC remote service object.
80*
81* @syscap SystemCapability.Communication.IPC.Core
82* @since 12
83*/
84struct OHIPCRemoteStub;
85
86/**
87* @brief Typedef an IPC remote service object.
88*
89* @syscap SystemCapability.Communication.IPC.Core
90* @since 12
91*/
92typedef struct OHIPCRemoteStub OHIPCRemoteStub;
93
94/**
95 * @brief Allocates memory.
96 *
97 * @syscap SystemCapability.Communication.IPC.Core
98 * @param len Length of the memory to allocate.
99 * @return Returns the address of the memory allocated if the operation is successful; returns NULL otherwise.
100 * @since 12
101 */
102typedef void* (*OH_IPC_MemAllocator)(int32_t len);
103
104/**
105 * @brief Creates an <b>OHIPCParcel</b> object, which cannot exceed 204,800 bytes.
106 *
107 * @syscap SystemCapability.Communication.IPC.Core
108 * @return Returns the pointer to the <b>OHIPCParcel</b> object created if the operation is successful;
109 * returns NULL otherwise.
110 * @since 12
111 */
112OHIPCParcel* OH_IPCParcel_Create(void);
113
114/**
115 * @brief Destroys an <b>OHIPCParcel</b> object.
116 *
117 * @syscap SystemCapability.Communication.IPC.Core
118 * @param parcel Pointer to the <b>OHIPCParcel</b> object to destroy.
119 * @since 12
120 */
121void OH_IPCParcel_Destroy(OHIPCParcel *parcel);
122
123/**
124 * @brief Obtains the size of the data contained in an <b>OHIPCParcel</b> object.
125 *
126 * @syscap SystemCapability.Communication.IPC.Core
127 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
128 * @return Returns the data size obtained if the operation is successful.\n
129 * Returns <b>-1</b> if invalid parameters are found.
130 * @since 12
131 */
132int OH_IPCParcel_GetDataSize(const OHIPCParcel *parcel);
133
134/**
135 * @brief Obtains the number of bytes that can be written to an <b>OHIPCParcel</b> object.
136 *
137 * @syscap SystemCapability.Communication.IPC.Core
138 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
139 * @return Returns the number of bytes that can be written to the <b>OHIPCParcel</b> object. \n
140 * Returns <b>-1</b> if invalid parameters are found.
141 * @since 12
142 */
143int OH_IPCParcel_GetWritableBytes(const OHIPCParcel *parcel);
144
145/**
146 * @brief Obtains the number of bytes that can be read from an <b>OHIPCParcel</b> object.
147 *
148 * @syscap SystemCapability.Communication.IPC.Core
149 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
150 * @return Returns the number of bytes that can be read from the <b>OHIPCParcel</b> object. \n
151 * Returns <b>-1</b> if invalid parameters are found.
152 * @since 12
153 */
154int OH_IPCParcel_GetReadableBytes(const OHIPCParcel *parcel);
155
156/**
157 * @brief Obtains the position where data is read in an <b>OHIPCParcel</b> object.
158 *
159 * @syscap SystemCapability.Communication.IPC.Core
160 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
161 * @return Returns the position obtained if the operation is successful. \n
162 * Returns <b>-1</b> if invalid parameters are found.
163 * @since 12
164 */
165int OH_IPCParcel_GetReadPosition(const OHIPCParcel *parcel);
166
167/**
168 * @brief Obtains the position where data is written in an <b>OHIPCParcel</b> object.
169 *
170 * @syscap SystemCapability.Communication.IPC.Core
171 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
172 * @return Returns the position obtained if the operation is successful. \n
173 * Returns <b>-1</b> if invalid parameters are found.
174 * @since 12
175 */
176int OH_IPCParcel_GetWritePosition(const OHIPCParcel *parcel);
177
178/**
179 * @brief Resets the position to read data in an IPC parcel.
180 *
181 * @syscap SystemCapability.Communication.IPC.Core
182 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
183 * @param newReadPos New position to read data. The value ranges from <b>0</b> to the current data size.
184 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
185 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found.
186 * @since 12
187 */
188int OH_IPCParcel_RewindReadPosition(OHIPCParcel *parcel, uint32_t newReadPos);
189
190/**
191 * @brief Resets the position to write data in an <b>OHIPCParcel</b> object.
192 *
193 * @syscap SystemCapability.Communication.IPC.Core
194 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
195 * @param newWritePos New position to write data. The value ranges from <b>0</b> to the current data size.
196 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
197 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found.
198 * @since 12
199 */
200int OH_IPCParcel_RewindWritePosition(OHIPCParcel *parcel, uint32_t newWritePos);
201
202/**
203 * @brief Writes an int8_t value to an <b>OHIPCParcel</b> object.
204 *
205 * @syscap SystemCapability.Communication.IPC.Core
206 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
207 * @param value Value to write.
208 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
209 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
210 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
211 * @since 12
212 */
213int OH_IPCParcel_WriteInt8(OHIPCParcel *parcel, int8_t value);
214
215/**
216 * @brief Reads an int8_t value from an <b>OHIPCParcel</b> object.
217 *
218 * @syscap SystemCapability.Communication.IPC.Core
219 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
220 * @param value Pointer to the data to read. It cannot be NULL.
221 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
222 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
223 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
224 * @since 12
225 */
226int OH_IPCParcel_ReadInt8(const OHIPCParcel *parcel, int8_t *value);
227
228/**
229 * @brief Writes an int16_t value to an <b>OHIPCParcel</b> object.
230 *
231 * @syscap SystemCapability.Communication.IPC.Core
232 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
233 * @param value Value to write.
234 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
235 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
236 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
237 * @since 12
238 */
239int OH_IPCParcel_WriteInt16(OHIPCParcel *parcel, int16_t value);
240
241/**
242 * @brief Reads an int16_t value from an <b>OHIPCParcel</b> object.
243 *
244 * @syscap SystemCapability.Communication.IPC.Core
245 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
246 * @param value Pointer to the data to read. It cannot be NULL.
247 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
248 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
249 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
250 * @since 12
251 */
252int OH_IPCParcel_ReadInt16(const OHIPCParcel *parcel, int16_t *value);
253
254/**
255 * @brief Writes an int32_t value to an <b>OHIPCParcel</b> object.
256 *
257 * @syscap SystemCapability.Communication.IPC.Core
258 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
259 * @param value Value to write.
260 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
261 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
262 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
263 * @since 12
264 */
265int OH_IPCParcel_WriteInt32(OHIPCParcel *parcel, int32_t value);
266
267/**
268 * @brief Reads an int32_t value from an <b>OHIPCParcel</b> object.
269 *
270 * @syscap SystemCapability.Communication.IPC.Core
271 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
272 * @param value Pointer to the data to read. It cannot be NULL.
273 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
274 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
275 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
276 * @since 12
277 */
278int OH_IPCParcel_ReadInt32(const OHIPCParcel *parcel, int32_t *value);
279
280/**
281 * @brief Writes an int64_t value to an <b>OHIPCParcel</b> object.
282 *
283 * @syscap SystemCapability.Communication.IPC.Core
284 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
285 * @param value Value to write.
286 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
287 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
288 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
289 * @since 12
290 */
291int OH_IPCParcel_WriteInt64(OHIPCParcel *parcel, int64_t value);
292
293/**
294 * @brief Reads an int64_t value from an <b>OHIPCParcel</b> object.
295 *
296 * @syscap SystemCapability.Communication.IPC.Core
297 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
298 * @param value Pointer to the data to read. It cannot be NULL.
299 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
300 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
301 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
302 * @since 12
303 */
304int OH_IPCParcel_ReadInt64(const OHIPCParcel *parcel, int64_t *value);
305
306/**
307 * @brief Writes a float value to an <b>OHIPCParcel</b> object.
308 *
309 * @syscap SystemCapability.Communication.IPC.Core
310 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
311 * @param value Value to write.
312 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
313 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
314 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
315 * @since 12
316 */
317int OH_IPCParcel_WriteFloat(OHIPCParcel *parcel, float value);
318
319/**
320 * @brief Reads a float value from an <b>OHIPCParcel</b> object.
321 *
322 * @syscap SystemCapability.Communication.IPC.Core
323 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
324 * @param value Pointer to the data to read. It cannot be NULL.
325 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
326 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
327 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
328 * @since 12
329 */
330int OH_IPCParcel_ReadFloat(const OHIPCParcel *parcel, float *value);
331
332/**
333 * @brief Writes a double value to an <b>OHIPCParcel</b> object.
334 *
335 * @syscap SystemCapability.Communication.IPC.Core
336 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
337 * @param value Value to write.
338 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
339 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
340 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
341 * @since 12
342 */
343int OH_IPCParcel_WriteDouble(OHIPCParcel *parcel, double value);
344
345/**
346 * @brief Reads a double value from an <b>OHIPCParcel</b> object.
347 *
348 * @syscap SystemCapability.Communication.IPC.Core
349 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
350 * @param value Pointer to the data to read. It cannot be NULL.
351 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
352 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
353 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
354 * @since 12
355 */
356int OH_IPCParcel_ReadDouble(const OHIPCParcel *parcel, double *value);
357
358/**
359 * @brief Writes a string including a string terminator to an <b>OHIPCParcel</b> object.
360 *
361 * @syscap SystemCapability.Communication.IPC.Core
362 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
363 * @param str String to write, which cannot be NULL.
364 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
365 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
366 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
367 * @since 12
368 */
369int OH_IPCParcel_WriteString(OHIPCParcel *parcel, const char *str);
370
371/**
372 * @brief Reads a string from an <b>OHIPCParcel</b> object. You can obtain the length of the string from <b>strlen</b>.
373 *
374 * @syscap SystemCapability.Communication.IPC.Core
375 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
376 * @return Returns the address of the string read if the operation is successful;
377 * returns NULL if the operation fails or invalid parameters are found.
378 * @since 12
379 */
380const char* OH_IPCParcel_ReadString(const OHIPCParcel *parcel);
381
382/**
383 * @brief Writes data of the specified length from the memory to an <b>OHIPCParcel</b> object.
384 *
385 * @syscap SystemCapability.Communication.IPC.Core
386 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
387 * @param buffer Pointer to the address of the memory information to write.
388 * @param len Length of the data to write.
389 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
390 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
391 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
392 * @since 12
393 */
394int OH_IPCParcel_WriteBuffer(OHIPCParcel *parcel, const uint8_t *buffer, int32_t len);
395
396/**
397 * @brief Reads memory information of the specified length from an <b>OHIPCParcel</b> object.
398 *
399 * @syscap SystemCapability.Communication.IPC.Core
400 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
401 * @param len Length of the memory to be read.
402 * @return Returns the memory address read if the operation is successful;
403 * returns NULL if invalid parameters are found or <b>len</b> exceeds the readable length of <b>parcel</b>.
404 * @since 12
405 */
406const uint8_t* OH_IPCParcel_ReadBuffer(const OHIPCParcel *parcel, int32_t len);
407
408/**
409 * @brief Writes an <b>OHIPCRemoteStub</b> object to an <b>OHIPCParcel</b> object.
410 *
411 * @syscap SystemCapability.Communication.IPC.Core
412 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
413 * @param stub Pointer to the <b>OHIPCRemoteStub</b> object to write. It cannot be NULL.
414 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
415 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
416 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
417 * @since 12
418 */
419int OH_IPCParcel_WriteRemoteStub(OHIPCParcel *parcel, const OHIPCRemoteStub *stub);
420
421/**
422 * @brief Reads the <b>OHIPCRemoteStub</b> object from an <b>OHIPCParcel</b> object.
423 *
424 * @syscap SystemCapability.Communication.IPC.Core
425 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
426 * @return Returns the pointer to the <b>OHIPCRemoteStub</b> object read if the operation is successful;
427 * returns NULL otherwise.
428 * @since 12
429 */
430OHIPCRemoteStub* OH_IPCParcel_ReadRemoteStub(const OHIPCParcel *parcel);
431
432/**
433 * @brief Writes an <b>OHIPCRemoteProxy</b> object to an <b>OHIPCParcel</b> object.
434 *
435 * @syscap SystemCapability.Communication.IPC.Core
436 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
437 * @param proxy Pointer to the <b>OHIPCRemoteProxy</b> object to write. It cannot be NULL.
438 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
439 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
440 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
441 * @since 12
442 */
443int OH_IPCParcel_WriteRemoteProxy(OHIPCParcel *parcel, const OHIPCRemoteProxy *proxy);
444
445/**
446 * @brief Reads the <b>OHIPCRemoteProxy</b> object from an <b>OHIPCParcel</b> object.
447 *
448 * @syscap SystemCapability.Communication.IPC.Core
449 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
450 * @return Returns the pointer to the <b>OHIPCRemoteProxy</b> object read if the operation is successful;
451 * returns NULL otherwise.
452 * @since 12
453 */
454OHIPCRemoteProxy* OH_IPCParcel_ReadRemoteProxy(const OHIPCParcel *parcel);
455
456/**
457 * @brief Writes a file descriptor to an <b>OHIPCParcel</b> object.
458 *
459 * @syscap SystemCapability.Communication.IPC.Core
460 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
461 * @param fd File descriptor to write.
462 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
463 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
464 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
465 * @since 12
466 */
467int OH_IPCParcel_WriteFileDescriptor(OHIPCParcel *parcel, int32_t fd);
468
469/**
470 * @brief Reads a file descriptor from an <b>OHIPCParcel</b> object.
471 *
472 * @syscap SystemCapability.Communication.IPC.Core
473 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
474 * @param fd Pointer to the file descriptor to read. It cannot be NULL.
475 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
476 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
477 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
478 * @since 12
479 */
480int OH_IPCParcel_ReadFileDescriptor(const OHIPCParcel *parcel, int32_t *fd);
481
482/**
483 * @brief Appends data to an <b>OHIPCParcel</b> object.
484 *
485 * @syscap SystemCapability.Communication.IPC.Core
486 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
487 * @param data Pointer to the data to append. It cannot be NULL.
488 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
489 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
490 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the operation fails.
491 * @since 12
492 */
493int OH_IPCParcel_Append(OHIPCParcel *parcel, const OHIPCParcel *data);
494
495/**
496 * @brief Writes an interface token to an <b>OHIPCParcel</b> object for interface identity verification.
497 *
498 * @syscap SystemCapability.Communication.IPC.Core
499 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
500 * @param token Pointer to the interface token to write. It cannot be NULL.
501 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
502 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
503 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_WRITE_ERROR} if the data write operation fails.
504 * @since 12
505 */
506int OH_IPCParcel_WriteInterfaceToken(OHIPCParcel *parcel, const char *token);
507
508/**
509 * @brief Reads an interface token from an <b>OHIPCParcel</b> object for interface identity verification.
510 *
511 * @syscap SystemCapability.Communication.IPC.Core
512 * @param parcel Pointer to the target <b>OHIPCParcel</b> object. It cannot be NULL.
513 * @param token Pointer to the address of the memory for storing the interface token.
514 * The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL.
515 * If an error code is returned, you still need to check whether the memory is empty and release the memory.
516 * Otherwise, memory leaks may occur.
517 * @param len Pointer to the length of the interface token read, including the terminator. It cannot be NULL.
518 * @param allocator Memory allocator specified by the user for allocating memory for <b>token</b>. It cannot be NULL.
519 * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
520 * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if invalid parameters are found. \n
521 * Returns {@link OH_IPC_ErrorCode#OH_IPC_PARCEL_READ_ERROR} if the read operation fails.
522 * @since 12
523 */
524int OH_IPCParcel_ReadInterfaceToken(const OHIPCParcel *parcel, char **token, int32_t *len,
525    OH_IPC_MemAllocator allocator);
526
527#ifdef __cplusplus
528}
529#endif
530
531/** @} */
532#endif
533