1# @ohos.rpc (RPC)
2
3The **RPC** module implements communication between processes, including inter-process communication (IPC) on a single device and remote procedure call (RPC) between processes on difference devices. IPC is implemented based on the Binder driver, and RPC is based on the DSoftBus driver.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> - This module supports return of error codes since API version 9.
10
11## Modules to Import
12
13```
14import { rpc } from '@kit.IPCKit';
15```
16
17## ErrorCode<sup>9+</sup>
18
19The APIs of this module return exceptions since API version 9. The following table lists the error codes.
20
21**System capability**: SystemCapability.Communication.IPC.Core
22
23| Name                                 | Value     | Description                                         |
24| ------------------------------------- | ------- | --------------------------------------------- |
25| CHECK_PARAM_ERROR                     | 401     | Parameter check failed.                               |
26| OS_MMAP_ERROR                         | 1900001 | Failed to call mmap.                       |
27| OS_IOCTL_ERROR                        | 1900002 | Failed to call **ioctl** with the shared memory file descriptor.|
28| WRITE_TO_ASHMEM_ERROR                 | 1900003 | Failed to write data to the shared memory.                       |
29| READ_FROM_ASHMEM_ERROR                | 1900004 | Failed to read data from the shared memory.                       |
30| ONLY_PROXY_OBJECT_PERMITTED_ERROR     | 1900005 | This operation is allowed only on the proxy object.                    |
31| ONLY_REMOTE_OBJECT_PERMITTED_ERROR    | 1900006 | This operation is allowed only on the remote object.                   |
32| COMMUNICATION_ERROR                   | 1900007 | Failed to communicate with the remote object over IPC.               |
33| PROXY_OR_REMOTE_OBJECT_INVALID_ERROR  | 1900008 | Invalid proxy or remote object.                 |
34| WRITE_DATA_TO_MESSAGE_SEQUENCE_ERROR  | 1900009 | Failed to write data to MessageSequence.                |
35| READ_DATA_FROM_MESSAGE_SEQUENCE_ERROR | 1900010 | Failed to read data from MessageSequence.                |
36| PARCEL_MEMORY_ALLOC_ERROR             | 1900011 | Failed to allocate memory during serialization.                   |
37| CALL_JS_METHOD_ERROR                  | 1900012 | Failed to invoke the JS callback.                         |
38| OS_DUP_ERROR                          | 1900013 | Failed to call dup.                        |
39
40
41## TypeCode<sup>12+</sup>
42
43Since API version 12, [writeArrayBuffer](#writearraybuffer12) and [readArrayBuffer](#readarraybuffer12) are added to pass ArrayBuffer data. The specific TypedArray type is determined by **TypeCode** defined as follows:
44
45**System capability**: SystemCapability.Communication.IPC.Core
46
47| Name                        | Value    | Description                                         |
48| ---------------------------- | ------ | --------------------------------------------  |
49| INT8_ARRAY                   | 0      | The TypedArray type is **INT8_ARRAY**.                 |
50| UINT8_ARRAY                  | 1      | The TypedArray type is **UINT8_ARRAY**.                |
51| INT16_ARRAY                  | 2      | The TypedArray type is **INT16_ARRAY**.                |
52| UINT16_ARRAY                 | 3      | The TypedArray type is **UINT16_ARRAY**.               |
53| INT32_ARRAY                  | 4      | The TypedArray type is **INT32_ARRAY**.                |
54| UINT32_ARRAY                 | 5      | The TypedArray type is **UINT32_ARRAY**.               |
55| FLOAT32_ARRAY                | 6      | The TypedArray type is **FLOAT32_ARRAY**.              |
56| FLOAT64_ARRAY                | 7      | The TypedArray type is **FLOAT64_ARRAY**.              |
57| BIGINT64_ARRAY               | 8      | The TypedArray type is **BIGINT64_ARRAY**.             |
58| BIGUINT64_ARRAY              | 9      | The TypedArray type is **BIGUINT64_ARRAY**.            |
59
60
61## MessageSequence<sup>9+</sup>
62
63Provides APIs for reading and writing data in specific format. During RPC or IPC, the sender can use the **write()** method provided by **MessageSequence** to write data in specific format to a **MessageSequence** object. The receiver can use the **read()** method provided by **MessageSequence** to read data in specific format from a **MessageSequence** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.
64
65### create
66
67static create(): MessageSequence
68
69Creates a **MessageSequence** object. This API is a static method.
70
71**System capability**: SystemCapability.Communication.IPC.Core
72
73**Return value**
74
75| Type           | Description                           |
76| --------------- | ------------------------------- |
77| [MessageSequence](#messagesequence9) | **MessageSequence** object created.|
78
79**Example**
80
81  ```ts
82  import { hilog } from '@kit.PerformanceAnalysisKit';
83
84  let data = rpc.MessageSequence.create();
85  hilog.info(0x0000, 'testTag', 'RpcClient: data is ' + data);
86  ```
87
88### reclaim
89
90reclaim(): void
91
92Reclaims the **MessageSequence** object that is no longer used.
93
94**System capability**: SystemCapability.Communication.IPC.Core
95
96**Example**
97
98  ```ts
99  let reply = rpc.MessageSequence.create();
100  reply.reclaim();
101  ```
102
103### writeRemoteObject
104
105writeRemoteObject(object: IRemoteObject): void
106
107Serializes a remote object and writes it to this **MessageSequence** object.
108
109**System capability**: SystemCapability.Communication.IPC.Core
110
111**Parameters**
112
113| Name| Type                           | Mandatory| Description                                     |
114| ------ | ------------------------------- | ---- | ----------------------------------------- |
115| object | [IRemoteObject](#iremoteobject) | Yes  | Remote object to serialize and write to the **MessageSequence** object.|
116
117**Error codes**
118
119For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
120
121| ID| Error Message|
122| -------- | -------- |
123| 401      | check param failed |
124| 1900008  | proxy or remote object is invalid |
125| 1900009  | write data to message sequence failed |
126
127**Example**
128
129  ```ts
130  import { hilog } from '@kit.PerformanceAnalysisKit';
131  import { BusinessError } from '@kit.BasicServicesKit';
132
133  class TestRemoteObject extends rpc.RemoteObject {
134    constructor(descriptor: string) {
135      super(descriptor);
136    }
137  }
138  let data = rpc.MessageSequence.create();
139  let testRemoteObject = new TestRemoteObject("testObject");
140  try {
141    data.writeRemoteObject(testRemoteObject);
142  } catch (error) {
143    let e: BusinessError = error as BusinessError;
144    hilog.error(0x0000, 'testTag', 'Rpc write remote object fail, errorCode ' + e.code);
145    hilog.error(0x0000, 'testTag', 'Rpc write remote object fail, errorMessage ' + e.message);
146  }
147  ```
148
149### readRemoteObject
150
151readRemoteObject(): IRemoteObject
152
153Reads the remote object from **MessageSequence**. You can use this API to deserialize the **MessageSequence** object to generate an **IRemoteObject**. The remote object is read in the order in which it is written to this **MessageSequence** object.
154
155**System capability**: SystemCapability.Communication.IPC.Core
156
157**Return value**
158
159| Type                           | Description              |
160| ------------------------------- | ------------------ |
161| [IRemoteObject](#iremoteobject) | Remote object obtained.|
162
163**Error codes**
164
165For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
166
167| ID| Error Message|
168| -------- | -------- |
169| 1900008  | proxy or remote object is invalid |
170| 1900010  | read data from message sequence failed |
171
172**Example**
173
174  ```ts
175  import { hilog } from '@kit.PerformanceAnalysisKit';
176  import { BusinessError } from '@kit.BasicServicesKit';
177
178  class TestRemoteObject extends rpc.RemoteObject {
179    constructor(descriptor: string) {
180      super(descriptor);
181    }
182  }
183  let data = rpc.MessageSequence.create();
184  let testRemoteObject = new TestRemoteObject("testObject");
185  try {
186    data.writeRemoteObject(testRemoteObject);
187    let proxy = data.readRemoteObject();
188    hilog.info(0x0000, 'testTag', 'RpcClient: readRemoteObject is ' + proxy);
189  } catch (error) {
190    let e: BusinessError = error as BusinessError;
191    hilog.error(0x0000, 'testTag', 'Rpc write remote object fail, errorCode ' + e.code);
192    hilog.error(0x0000, 'testTag', 'Rpc write remote object fail, errorMessage ' + e.message);
193  }
194  ```
195
196### writeInterfaceToken
197
198writeInterfaceToken(token: string): void
199
200Writes an interface token to this **MessageSequence** object. The remote object can use this interface token to verify the communication.
201
202**System capability**: SystemCapability.Communication.IPC.Core
203
204**Parameters**
205
206| Name| Type  | Mandatory| Description              |
207| ------ | ------ | ---- | ------------------ |
208| token  | string | Yes  | Interface token to write.|
209
210**Error codes**
211
212For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
213
214| ID| Error Message|
215| -------- | -------- |
216| 401      | check param failed |
217| 1900009  | write data to message sequence failed |
218
219**Example**
220
221  ```ts
222  import { hilog } from '@kit.PerformanceAnalysisKit';
223  import { BusinessError } from '@kit.BasicServicesKit';
224
225  let data = rpc.MessageSequence.create();
226  try {
227    data.writeInterfaceToken("aaa");
228  } catch (error) {
229    let e: BusinessError = error as BusinessError;
230    hilog.error(0x0000, 'testTag', 'rpc write interface fail, errorCode ' + e.code);
231    hilog.error(0x0000, 'testTag', 'rpc write interface fail, errorMessage ' + e.message);
232  }
233  ```
234
235### readInterfaceToken
236
237readInterfaceToken(): string
238
239Reads the interface token from this **MessageSequence** object. The interface token is read in the sequence in which it is written to the **MessageSequence** object. The local object can use it to verify the communication.
240
241**System capability**: SystemCapability.Communication.IPC.Core
242
243**Return value**
244
245| Type  | Description                    |
246| ------ | ------------------------ |
247| string | Interface token obtained.|
248
249**Error codes**
250
251For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
252
253| ID| Error Message|
254| -------- | -------- |
255| 1900010  | read data from message sequence failed |
256
257**Example**
258
259```ts
260import { hilog } from '@kit.PerformanceAnalysisKit';
261import { BusinessError } from '@kit.BasicServicesKit';
262
263class Stub extends rpc.RemoteObject {
264  onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
265    try {
266      let interfaceToken = data.readInterfaceToken();
267      hilog.info(0x0000, 'testTag', 'RpcServer: interfaceToken is ' + interfaceToken);
268    } catch (error) {
269      let e: BusinessError = error as BusinessError;
270      hilog.error(0x0000, 'testTag', 'RpcServer: read interfaceToken failed, errorCode ' + e.code);
271      hilog.error(0x0000, 'testTag', 'RpcServer: read interfaceToken failed, errorMessage ' + e.message);
272    }
273    return true;
274  }
275}
276```
277
278### getSize
279
280getSize(): number
281
282Obtains the data size of this **MessageSequence** object.
283
284**System capability**: SystemCapability.Communication.IPC.Core
285
286**Return value**
287
288| Type  | Description                                           |
289| ------ | ----------------------------------------------- |
290| number | Size of the **MessageSequence** instance obtained, in bytes.|
291
292**Example**
293
294  ```ts
295  import { hilog } from '@kit.PerformanceAnalysisKit';
296
297  let data = rpc.MessageSequence.create();
298  let size = data.getSize();
299  hilog.info(0x0000, 'testTag', 'RpcClient: size is ' + size);
300  ```
301
302### getCapacity
303
304getCapacity(): number
305
306Obtains the capacity of this **MessageSequence** object.
307
308**System capability**: SystemCapability.Communication.IPC.Core
309
310**Return value**
311
312| Type  | Description |
313| ------ | ----- |
314| number | Capacity of the obtained **MessageSequence** object, in bytes.|
315
316**Example**
317
318  ```ts
319  import { hilog } from '@kit.PerformanceAnalysisKit';
320
321  let data = rpc.MessageSequence.create();
322  let result = data.getCapacity();
323  hilog.info(0x0000, 'testTag', 'RpcClient: capacity is ' + result);
324  ```
325
326### setSize
327
328setSize(size: number): void
329
330Sets the size of the data contained in this **MessageSequence** object.
331
332**System capability**: SystemCapability.Communication.IPC.Core
333
334**Parameters**
335
336| Name| Type  | Mandatory| Description  |
337| ------ | ------ | ---- | ------ |
338| size   | number | Yes  | Data size to set, in bytes.|
339
340**Error codes**
341
342For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
343
344| ID| Error Message|
345| -------- | -------- |
346| 401      | check param failed |
347
348**Example**
349
350  ```ts
351  import { hilog } from '@kit.PerformanceAnalysisKit';
352  import { BusinessError } from '@kit.BasicServicesKit';
353
354  let data = rpc.MessageSequence.create();
355  data.writeString('Hello World');
356  try {
357    data.setSize(16);
358  } catch (error) {
359    let e: BusinessError = error as BusinessError;
360    hilog.error(0x0000, 'testTag', 'rpc set size of MessageSequence fail, errorCode ' + e.code);
361    hilog.error(0x0000, 'testTag', 'rpc set size of MessageSequence fail, errorMessage ' + e.message);
362  }
363  ```
364
365### setCapacity
366
367setCapacity(size: number): void
368
369Sets the storage capacity of this **MessageSequence** object.
370
371**System capability**: SystemCapability.Communication.IPC.Core
372
373**Parameters**
374
375| Name| Type  | Mandatory| Description                                         |
376| ------ | ------ | ---- | --------------------------------------------- |
377| size   | number | Yes  | Storage capacity of the **MessageSequence** object to set, in bytes.|
378
379**Error codes**
380
381For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
382
383| ID| Error Message|
384| -------- | -------- |
385| 401      | check param failed |
386| 1900011  | parcel memory alloc failed |
387
388**Example**
389
390  ```ts
391  import { hilog } from '@kit.PerformanceAnalysisKit';
392  import { BusinessError } from '@kit.BasicServicesKit';
393
394  let data = rpc.MessageSequence.create();
395  try {
396    data.setCapacity(100);
397  } catch (error) {
398    let e: BusinessError = error as BusinessError;
399    hilog.error(0x0000, 'testTag', 'rpc memory alloc fail, errorCode ' + e.code);
400    hilog.error(0x0000, 'testTag', 'rpc memory alloc fail, errorMessage ' + e.message);
401  }
402  ```
403
404### getWritableBytes
405
406getWritableBytes(): number
407
408Obtains the writable capacity (in bytes) of this **MessageSequence** object.
409
410**System capability**: SystemCapability.Communication.IPC.Core
411
412**Return value**
413
414| Type  | Description  |
415| ------ | ------ |
416| number | Writable capacity of the **MessageSequence** instance, in bytes.|
417
418**Example**
419
420```ts
421import { hilog } from '@kit.PerformanceAnalysisKit';
422
423class Stub extends rpc.RemoteObject {
424  onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
425    let getWritableBytes = data.getWritableBytes();
426    hilog.info(0x0000, 'testTag', 'RpcServer: getWritableBytes is ' + getWritableBytes);
427    return true;
428  }
429}
430```
431
432### getReadableBytes
433
434getReadableBytes(): number
435
436Obtains the readable capacity of this **MessageSequence** object.
437
438**System capability**: SystemCapability.Communication.IPC.Core
439
440**Return value**
441
442| Type  | Description   |
443| ------ | ------- |
444| number | Readable capacity of the **MessageSequence** instance, in bytes.|
445
446**Example**
447
448```ts
449import { hilog } from '@kit.PerformanceAnalysisKit';
450
451class Stub extends rpc.RemoteObject {
452  onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
453    let result = data.getReadableBytes();
454    hilog.info(0x0000, 'testTag', 'RpcServer: getReadableBytes is ' + result);
455    return true;
456  }
457}
458```
459
460### getReadPosition
461
462getReadPosition(): number
463
464Obtains the read position of this **MessageSequence** object.
465
466**System capability**: SystemCapability.Communication.IPC.Core
467
468**Return value**
469
470| Type  | Description  |
471| ------ | ------ |
472| number | Read position obtained.|
473
474**Example**
475
476  ```ts
477  import { hilog } from '@kit.PerformanceAnalysisKit';
478
479  let data = rpc.MessageSequence.create();
480  let readPos = data.getReadPosition();
481  hilog.info(0x0000, 'testTag', 'RpcClient: readPos is ' + readPos);
482  ```
483
484### getWritePosition
485
486getWritePosition(): number
487
488Obtains the write position of this **MessageSequence** object.
489
490**System capability**: SystemCapability.Communication.IPC.Core
491
492**Return value**
493
494| Type  | Description |
495| ------ | ----- |
496| number | Write position obtained.|
497
498**Example**
499
500  ```ts
501  import { hilog } from '@kit.PerformanceAnalysisKit';
502
503  let data = rpc.MessageSequence.create();
504  data.writeInt(10);
505  let bwPos = data.getWritePosition();
506  hilog.info(0x0000, 'testTag', 'RpcClient: bwPos is ' + bwPos);
507  ```
508
509### rewindRead
510
511rewindRead(pos: number): void
512
513Moves the read pointer to the specified position.
514
515**System capability**: SystemCapability.Communication.IPC.Core
516
517**Parameters**
518
519| Name| Type  | Mandatory| Description   |
520| ------ | ------ | ---- | ------- |
521| pos    | number | Yes  | Position from which data is to read.|
522
523**Error codes**
524
525For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
526
527| ID| Error Message|
528| -------- | -------- |
529| 401      | check param failed |
530
531**Example**
532
533  ```ts
534  import { hilog } from '@kit.PerformanceAnalysisKit';
535  import { BusinessError } from '@kit.BasicServicesKit';
536
537  let data = rpc.MessageSequence.create();
538  data.writeInt(12);
539  data.writeString("sequence");
540  let number = data.readInt();
541  hilog.info(0x0000, 'testTag', 'RpcClient: number is ' + number);
542  try {
543    data.rewindRead(0);
544  } catch (error) {
545    let e: BusinessError = error as BusinessError;
546    hilog.error(0x0000, 'testTag', 'rpc rewind read data fail, errorCode ' + e.code);
547    hilog.error(0x0000, 'testTag', 'rpc rewind read data fail, errorMessage ' + e.message);
548  }
549  let number2 = data.readInt();
550  hilog.info(0x0000, 'testTag', 'RpcClient: rewindRead is ' + number2);
551  ```
552
553### rewindWrite
554
555rewindWrite(pos: number): void
556
557Moves the write pointer to the specified position.
558
559**System capability**: SystemCapability.Communication.IPC.Core
560
561**Parameters**
562
563| Name| Type  | Mandatory| Description |
564| ------ | ------ | ---- | ----- |
565| pos    | number | Yes  | Position from which data is to write.|
566
567**Error codes**
568
569For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
570
571| ID| Error Message|
572| -------- | -------- |
573| 401      | check param failed |
574
575**Example**
576
577  ```ts
578  import { hilog } from '@kit.PerformanceAnalysisKit';
579  import { BusinessError } from '@kit.BasicServicesKit';
580
581  let data = rpc.MessageSequence.create();
582  data.writeInt(4);
583  try {
584    data.rewindWrite(0);
585  } catch (error) {
586    let e: BusinessError = error as BusinessError;
587    hilog.error(0x0000, 'testTag', 'rpc rewindWrite fail, errorCode ' + e.code);
588    hilog.error(0x0000, 'testTag', 'rpc rewindWrite fail, errorMessage ' + e.message);
589  }
590  data.writeInt(5);
591  let number = data.readInt();
592  hilog.info(0x0000, 'testTag', 'RpcClient: rewindWrite is: ' + number);
593  ```
594
595### writeByte
596
597writeByte(val: number): void
598
599Writes a byte value to this **MessageSequence** object.
600
601**System capability**: SystemCapability.Communication.IPC.Core
602
603**Parameters**
604
605| Name| Type  | Mandatory| Description |
606| ------ | ------ | ---- | ----- |
607| val    | number | Yes  | Byte value to write.|
608
609**Error codes**
610
611For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
612
613| ID| Error Message|
614| -------- | -------  |
615| 401      | check param failed |
616| 1900009  | write data to message sequence failed |
617
618**Example**
619
620  ```ts
621  import { hilog } from '@kit.PerformanceAnalysisKit';
622  import { BusinessError } from '@kit.BasicServicesKit';
623
624  let data = rpc.MessageSequence.create();
625  try {
626    data.writeByte(2);
627  } catch (error) {
628    let e: BusinessError = error as BusinessError;
629    hilog.error(0x0000, 'testTag', 'rpc write byte fail, errorCode ' + e.code);
630    hilog.error(0x0000, 'testTag', 'rpc write byte fail, errorMessage ' + e.message);
631  }
632  ```
633
634### readByte
635
636readByte(): number
637
638Reads the byte value from this **MessageSequence** object.
639
640**System capability**: SystemCapability.Communication.IPC.Core
641
642**Return value**
643
644| Type  | Description |
645| ------ | ----- |
646| number | Byte value read.|
647
648**Error codes**
649
650For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
651
652| ID| Error Message|
653| ------- | --------  |
654| 1900010 | read data from message sequence failed |
655
656**Example**
657
658  ```ts
659  import { hilog } from '@kit.PerformanceAnalysisKit';
660  import { BusinessError } from '@kit.BasicServicesKit';
661
662  let data = rpc.MessageSequence.create();
663  try {
664    data.writeByte(2);
665  } catch (error) {
666    let e: BusinessError = error as BusinessError;
667    hilog.error(0x0000, 'testTag', 'rpc write byte fail, errorCode ' + e.code);
668    hilog.error(0x0000, 'testTag', 'rpc write byte fail, errorMessage ' + e.message);
669  }
670  try {
671    let ret = data.readByte();
672    hilog.info(0x0000, 'testTag', 'RpcClient: readByte is: ' +  ret);
673  } catch (error) {
674    let e: BusinessError = error as BusinessError;
675    hilog.error(0x0000, 'testTag', 'rpc read byte fail, errorCode ' + e.code);
676    hilog.error(0x0000, 'testTag', 'rpc read byte fail, errorMessage ' + e.message);
677  }
678  ```
679
680### writeShort
681
682writeShort(val: number): void
683
684Writes a short integer to this **MessageSequence** object.
685
686**System capability**: SystemCapability.Communication.IPC.Core
687
688**Parameters**
689
690| Name| Type  | Mandatory| Description|
691| ------ | ------ | ---  | ---  |
692| val    | number | Yes  | Short integer to write.|
693
694**Error codes**
695
696For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
697
698| ID| Error Message|
699| -------- | -------- |
700| 401      | check param failed |
701| 1900009  | write data to message sequence failed |
702
703**Example**
704
705  ```ts
706  import { hilog } from '@kit.PerformanceAnalysisKit';
707  import { BusinessError } from '@kit.BasicServicesKit';
708
709  let data = rpc.MessageSequence.create();
710  try {
711    data.writeShort(8);
712  } catch (error) {
713    let e: BusinessError = error as BusinessError;
714    hilog.error(0x0000, 'testTag', 'rpc write short fail, errorCode ' + e.code);
715    hilog.error(0x0000, 'testTag', 'rpc write short fail, errorMessage ' + e.message);
716  }
717  ```
718
719### readShort
720
721readShort(): number
722
723Reads the short integer from this **MessageSequence** object.
724
725**System capability**: SystemCapability.Communication.IPC.Core
726
727**Return value**
728
729| Type  | Description          |
730| ------ | -------------- |
731| number | Short integer read.|
732
733**Error codes**
734
735For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
736
737| ID| Error Message|
738| -------- | -------- |
739| 1900010  | read data from message sequence failed |
740
741**Example**
742
743  ```ts
744  import { hilog } from '@kit.PerformanceAnalysisKit';
745  import { BusinessError } from '@kit.BasicServicesKit';
746
747  let data = rpc.MessageSequence.create();
748  try {
749    data.writeShort(8);
750  } catch (error) {
751    let e: BusinessError = error as BusinessError;
752    hilog.error(0x0000, 'testTag', 'rpc write short fail, errorCode ' + e.code);
753    hilog.error(0x0000, 'testTag', 'rpc write short fail, errorMessage ' + e.message);
754  }
755  try {
756    let ret = data.readShort();
757    hilog.info(0x0000, 'testTag', 'RpcClient: readByte is ' + ret);
758  } catch (error) {
759    let e: BusinessError = error as BusinessError;
760    hilog.error(0x0000, 'testTag', 'rpc read short fail, errorCode ' + e.code);
761    hilog.error(0x0000, 'testTag', 'rpc read short fail, errorMessage ' + e.message);
762  }
763  ```
764
765### writeInt
766
767writeInt(val: number): void
768
769Writes an integer to this **MessageSequence** object.
770
771**System capability**: SystemCapability.Communication.IPC.Core
772
773**Parameters**
774
775| Name| Type  | Mandatory| Description            |
776| ------ | ------ | ---- | ---------------- |
777| val    | number | Yes  | Integer to write.|
778
779**Error codes**
780
781For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
782
783| ID| Error Message|
784| -------- | -------- |
785| 401      | check param failed |
786| 1900009  | write data to message sequence failed |
787
788**Example**
789
790  ```ts
791  import { hilog } from '@kit.PerformanceAnalysisKit';
792  import { BusinessError } from '@kit.BasicServicesKit';
793
794  let data = rpc.MessageSequence.create();
795  try {
796    data.writeInt(10);
797  } catch (error) {
798    let e: BusinessError = error as BusinessError;
799    hilog.error(0x0000, 'testTag', 'rpc write int fail, errorCode ' + e.code);
800    hilog.error(0x0000, 'testTag', 'rpc write int fail, errorMessage ' + e.message);
801  }
802  ```
803
804### readInt
805
806readInt(): number
807
808Reads the integer from this **MessageSequence** object.
809
810**System capability**: SystemCapability.Communication.IPC.Core
811
812**Return value**
813
814| Type  | Description        |
815| ------ | ------------ |
816| number | Integer read.|
817
818**Error codes**
819
820For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
821
822| ID| Error Message|
823| -------- | -------- |
824| 1900010  | read data from message sequence failed |
825
826**Example**
827
828  ```ts
829  import { hilog } from '@kit.PerformanceAnalysisKit';
830  import { BusinessError } from '@kit.BasicServicesKit';
831
832  let data = rpc.MessageSequence.create();
833  try {
834    data.writeInt(10);
835  } catch (error) {
836    let e: BusinessError = error as BusinessError;
837    hilog.error(0x0000, 'testTag', 'rpc write int fail, errorCode ' + e.code);
838    hilog.error(0x0000, 'testTag', 'rpc write int fail, errorMessage ' + e.message);
839  }
840  try {
841    let ret = data.readInt();
842    hilog.info(0x0000, 'testTag', 'RpcClient: readInt is ' + ret);
843  } catch (error) {
844    let e: BusinessError = error as BusinessError;
845    hilog.error(0x0000, 'testTag', 'rpc read int fail, errorCode ' + e.code);
846    hilog.error(0x0000, 'testTag', 'rpc read int fail, errorMessage ' + e.message);
847  }
848  ```
849
850### writeLong
851
852writeLong(val: number): void
853
854Writes a long integer to this **MessageSequence** object.
855
856**System capability**: SystemCapability.Communication.IPC.Core
857
858**Parameters**
859
860| Name| Type  | Mandatory| Description            |
861| ------ | ------ | ---- | ---------------- |
862| val    | number | Yes  | Long integer to write.|
863
864**Error codes**
865
866For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
867
868| ID| Error Message|
869| -------- | -------- |
870| 401      | check param failed |
871| 1900009  | write data to message sequence failed |
872
873**Example**
874
875  ```ts
876  import { hilog } from '@kit.PerformanceAnalysisKit';
877  import { BusinessError } from '@kit.BasicServicesKit';
878
879  let data = rpc.MessageSequence.create();
880  try {
881    data.writeLong(10000);
882  } catch (error) {
883    let e: BusinessError = error as BusinessError;
884    hilog.error(0x0000, 'testTag', 'rpc write long fail, errorCode ' + e.code);
885    hilog.error(0x0000, 'testTag', 'rpc write long fail, errorMessage ' + e.message);
886  }
887  ```
888
889### readLong
890
891readLong(): number
892
893Reads the long integer from this **MessageSequence** object.
894
895**System capability**: SystemCapability.Communication.IPC.Core
896
897**Return value**
898
899| Type  | Description          |
900| ------ | -------------- |
901| number | Long integer read.|
902
903**Error codes**
904
905For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
906
907| ID| Error Message|
908| -------- | -------- |
909| 1900010  | read data from message sequence failed |
910
911**Example**
912
913  ```ts
914  import { hilog } from '@kit.PerformanceAnalysisKit';
915  import { BusinessError } from '@kit.BasicServicesKit';
916
917  let data = rpc.MessageSequence.create();
918  try {
919    data.writeLong(10000);
920  } catch (error) {
921    let e: BusinessError = error as BusinessError;
922    hilog.error(0x0000, 'testTag', 'rpc write long fail, errorCode ' + e.code);
923    hilog.error(0x0000, 'testTag', 'rpc write long fail, errorMessage ' + e.message);
924  }
925  try {
926    let ret = data.readLong();
927    hilog.info(0x0000, 'testTag', 'RpcClient: readLong is ' + ret);
928  } catch (error) {
929    let e: BusinessError = error as BusinessError;
930    hilog.error(0x0000, 'testTag', 'rpc read long fail, errorCode ' + e.code);
931    hilog.error(0x0000, 'testTag', 'rpc read long fail, errorMessage ' + e.message);
932  }
933  ```
934
935### writeFloat
936
937writeFloat(val: number): void
938
939Writes a floating-point number to this **MessageSequence** object.
940
941**System capability**: SystemCapability.Communication.IPC.Core
942
943**Parameters**
944
945| Name| Type  | Mandatory| Description |
946| ------ | ------ | ---- | ----- |
947| val    | number | Yes  | Floating-point number to write.|
948
949**Error codes**
950
951For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
952
953| ID| Error Message|
954| -------- | -------- |
955| 401      | check param failed |
956| 1900009  | write data to message sequence failed |
957
958**Example**
959
960  ```ts
961  import { hilog } from '@kit.PerformanceAnalysisKit';
962  import { BusinessError } from '@kit.BasicServicesKit';
963
964  let data = rpc.MessageSequence.create();
965  try {
966    data.writeFloat(1.2);
967  } catch (error) {
968    let e: BusinessError = error as BusinessError;
969    hilog.error(0x0000, 'testTag', 'rpc write float fail, errorCode ' + e.code);
970    hilog.error(0x0000, 'testTag', 'rpc write float fail, errorMessage ' + e.message);
971  }
972  ```
973
974### readFloat
975
976readFloat(): number
977
978Reads the floating-pointer number from this **MessageSequence** object.
979
980**System capability**: SystemCapability.Communication.IPC.Core
981
982**Return value**
983
984| Type  | Description        |
985| ------ | ------------ |
986| number | Floating-point number read.|
987
988**Error codes**
989
990For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
991
992| ID| Error Message|
993| -------- | -------- |
994| 1900010  | read data from message sequence failed |
995
996**Example**
997
998  ```ts
999  import { hilog } from '@kit.PerformanceAnalysisKit';
1000  import { BusinessError } from '@kit.BasicServicesKit';
1001
1002  let data = rpc.MessageSequence.create();
1003  try {
1004    data.writeFloat(1.2);
1005  } catch (error) {
1006    let e: BusinessError = error as BusinessError;
1007    hilog.error(0x0000, 'testTag', 'rpc write float fail, errorCode ' + e.code);
1008    hilog.error(0x0000, 'testTag', 'rpc write float fail, errorMessage ' + e.message);
1009  }
1010  try {
1011    let ret = data.readFloat();
1012    hilog.info(0x0000, 'testTag', 'RpcClient: readFloat is ' + ret);
1013  } catch (error) {
1014    let e: BusinessError = error as BusinessError;
1015    hilog.error(0x0000, 'testTag', 'rpc read float fail, errorCode ' + e.code);
1016    hilog.error(0x0000, 'testTag', 'rpc read float fail, errorMessage ' + e.message);
1017  }
1018  ```
1019
1020### writeDouble
1021
1022writeDouble(val: number): void
1023
1024Writes a double-precision floating-point number to this **MessageSequence** object.
1025
1026**System capability**: SystemCapability.Communication.IPC.Core
1027
1028**Parameters**
1029
1030| Name| Type  | Mandatory| Description                  |
1031| ------ | ------ | ---- | ---------------------- |
1032| val    | number | Yes  | Double-precision floating-point number to write.|
1033
1034**Error codes**
1035
1036For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1037
1038| ID| Error Message|
1039| -------- | -------- |
1040| 401      | check param failed |
1041| 1900009  | write data to message sequence failed |
1042
1043**Example**
1044
1045  ```ts
1046  import { hilog } from '@kit.PerformanceAnalysisKit';
1047  import { BusinessError } from '@kit.BasicServicesKit';
1048
1049  let data = rpc.MessageSequence.create();
1050  try {
1051    data.writeDouble(10.2);
1052  } catch (error) {
1053    let e: BusinessError = error as BusinessError;
1054    hilog.error(0x0000, 'testTag', 'rpc write double fail, errorCode ' + e.code);
1055    hilog.error(0x0000, 'testTag', 'rpc write double fail, errorMessage ' + e.message);
1056  }
1057  ```
1058
1059### readDouble
1060
1061readDouble(): number
1062
1063Reads the double-precision floating-point number from this **MessageSequence** object.
1064
1065**System capability**: SystemCapability.Communication.IPC.Core
1066
1067**Return value**
1068
1069| Type  | Description              |
1070| ------ | ------------------ |
1071| number | Double-precision floating-point number read.|
1072
1073**Error codes**
1074
1075For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1076
1077| ID| Error Message|
1078| -------- | -------- |
1079| 1900010  | read data from message sequence failed |
1080
1081**Example**
1082
1083  ```ts
1084  import { hilog } from '@kit.PerformanceAnalysisKit';
1085  import { BusinessError } from '@kit.BasicServicesKit';
1086
1087  let data = rpc.MessageSequence.create();
1088  try {
1089    data.writeDouble(10.2);
1090  } catch (error) {
1091    let e: BusinessError = error as BusinessError;
1092    hilog.error(0x0000, 'testTag', 'rpc write double fail, errorCode ' + e.code);
1093    hilog.error(0x0000, 'testTag', 'rpc write double fail, errorMessage ' + e.message);
1094  }
1095  try {
1096    let ret = data.readDouble();
1097    hilog.info(0x0000, 'testTag', 'RpcClient: readDouble is ' +  ret);
1098  } catch (error) {
1099    let e: BusinessError = error as BusinessError;
1100    hilog.error(0x0000, 'testTag', 'rpc read double fail, errorCode ' + e.code);
1101    hilog.error(0x0000, 'testTag', 'rpc read double fail, errorMessage ' + e.message);
1102  }
1103  ```
1104
1105### writeBoolean
1106
1107writeBoolean(val: boolean): void
1108
1109Writes a Boolean value to this **MessageSequence** object.
1110
1111**System capability**: SystemCapability.Communication.IPC.Core
1112
1113**Parameters**
1114
1115| Name| Type   | Mandatory| Description            |
1116| ------ | ------- | ---- | ---------------- |
1117| val    | boolean | Yes  | Boolean value to write.|
1118
1119**Error codes**
1120
1121For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1122
1123| ID| Error Message|
1124| -------- | -------- |
1125| 401      | check param failed |
1126| 1900009  | write data to message sequence failed |
1127
1128**Example**
1129
1130  ```ts
1131  import { hilog } from '@kit.PerformanceAnalysisKit';
1132  import { BusinessError } from '@kit.BasicServicesKit';
1133
1134  let data = rpc.MessageSequence.create();
1135  try {
1136    data.writeBoolean(false);
1137  } catch (error) {
1138    let e: BusinessError = error as BusinessError;
1139    hilog.error(0x0000, 'testTag', 'rpc write boolean fail, errorCode ' + e.code);
1140    hilog.error(0x0000, 'testTag', 'rpc write boolean fail, errorMessage ' + e.message);
1141  }
1142  ```
1143
1144### readBoolean
1145
1146readBoolean(): boolean
1147
1148Reads the Boolean value from this **MessageSequence** object.
1149
1150**System capability**: SystemCapability.Communication.IPC.Core
1151
1152**Return value**
1153
1154| Type   | Description                |
1155| ------- | -------------------- |
1156| boolean | Boolean value read.|
1157
1158**Error codes**
1159
1160For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1161
1162| ID| Error Message|
1163| -------- | -------- |
1164| 1900010  | read data from message sequence failed |
1165
1166**Example**
1167
1168  ```ts
1169  import { hilog } from '@kit.PerformanceAnalysisKit';
1170  import { BusinessError } from '@kit.BasicServicesKit';
1171
1172  let data = rpc.MessageSequence.create();
1173  try {
1174    data.writeBoolean(false);
1175  } catch (error) {
1176    let e: BusinessError = error as BusinessError;
1177    hilog.error(0x0000, 'testTag', 'rpc write boolean fail, errorCode ' + e.code);
1178    hilog.error(0x0000, 'testTag', 'rpc write boolean fail, errorMessage ' + e.message);
1179  }
1180  try {
1181    let ret = data.readBoolean();
1182    hilog.info(0x0000, 'testTag', 'RpcClient: readBoolean is ' + ret);
1183  } catch (error) {
1184    let e: BusinessError = error as BusinessError;
1185    hilog.error(0x0000, 'testTag', 'rpc read boolean fail, errorCode ' + e.code);
1186    hilog.error(0x0000, 'testTag', 'rpc read boolean fail, errorMessage ' + e.message);
1187  }
1188  ```
1189
1190### writeChar
1191
1192writeChar(val: number): void
1193
1194Writes a character to this **MessageSequence** object.
1195
1196**System capability**: SystemCapability.Communication.IPC.Core
1197
1198**Parameters**
1199
1200| Name| Type  | Mandatory| Description                |
1201| ------ | ------ | ---- | -------------------- |
1202| val    | number | Yes  | Single character to write.|
1203
1204**Error codes**
1205
1206For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1207
1208| ID| Error Message|
1209| -------- | -------- |
1210| 401      | check param failed |
1211| 1900009  | write data to message sequence failed |
1212
1213**Example**
1214
1215  ```ts
1216  import { hilog } from '@kit.PerformanceAnalysisKit';
1217  import { BusinessError } from '@kit.BasicServicesKit';
1218
1219  let data = rpc.MessageSequence.create();
1220  try {
1221    data.writeChar(97);
1222  } catch (error) {
1223    let e: BusinessError = error as BusinessError;
1224    hilog.error(0x0000, 'testTag', 'rpc write char fail, errorCode ' + e.code);
1225    hilog.error(0x0000, 'testTag', 'rpc write char fail, errorMessage ' + e.message);
1226  }
1227  ```
1228
1229### readChar
1230
1231readChar(): number
1232
1233Reads the character from this **MessageSequence** object.
1234
1235**System capability**: SystemCapability.Communication.IPC.Core
1236
1237**Return value**
1238
1239| Type  | Description|
1240| ------ | ---- |
1241| number | Character read.|
1242
1243**Error codes**
1244
1245For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1246
1247| ID| Error Message|
1248| -------- | -------- |
1249| 1900010  | read data from message sequence failed |
1250
1251**Example**
1252
1253  ```ts
1254  import { hilog } from '@kit.PerformanceAnalysisKit';
1255  import { BusinessError } from '@kit.BasicServicesKit';
1256
1257  let data = rpc.MessageSequence.create();
1258  try {
1259    data.writeChar(97);
1260  } catch (error) {
1261    let e: BusinessError = error as BusinessError;
1262    hilog.error(0x0000, 'testTag', 'rpc write char fail, errorCode ' + e.code);
1263    hilog.error(0x0000, 'testTag', 'rpc write char fail, errorMessage ' + e.message);
1264  }
1265  try {
1266    let ret = data.readChar();
1267    hilog.info(0x0000, 'testTag', 'RpcClient: readChar is ' + ret);
1268  } catch (error) {
1269    let e: BusinessError = error as BusinessError;
1270    hilog.error(0x0000, 'testTag', 'rpc read char fail, errorCode ' + e.code);
1271    hilog.error(0x0000, 'testTag', 'rpc read char fail, errorMessage ' + e.message);
1272  }
1273  ```
1274
1275### writeString
1276
1277writeString(val: string): void
1278
1279Writes a string to this **MessageSequence** object.
1280
1281**System capability**: SystemCapability.Communication.IPC.Core
1282
1283**Parameters**
1284
1285| Name| Type  | Mandatory| Description                                     |
1286| ------ | ------ | ---- | ----------------------------------------- |
1287| val    | string | Yes  | String to write. The length of the string must be less than 40960 bytes.|
1288
1289**Error codes**
1290
1291For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1292
1293| ID| Error Message|
1294| -------- | -------- |
1295| 401      | check param failed |
1296| 1900009  | write data to message sequence failed |
1297
1298**Example**
1299
1300  ```ts
1301  import { hilog } from '@kit.PerformanceAnalysisKit';
1302  import { BusinessError } from '@kit.BasicServicesKit';
1303
1304  let data = rpc.MessageSequence.create();
1305  try {
1306    data.writeString('abc');
1307  } catch (error) {
1308    let e: BusinessError = error as BusinessError;
1309    hilog.error(0x0000, 'testTag', 'rpc write string fail, errorCode ' + e.code);
1310    hilog.error(0x0000, 'testTag', 'rpc write string fail, errorMessage ' + e.message);
1311  }
1312  ```
1313
1314### readString
1315
1316readString(): string
1317
1318Reads the string from this **MessageSequence** object.
1319
1320**System capability**: SystemCapability.Communication.IPC.Core
1321
1322**Return value**
1323
1324| Type  | Description          |
1325| ------ | -------------- |
1326| string | String read.|
1327
1328**Error codes**
1329
1330For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1331
1332| ID| Error Message|
1333| -------- | -------- |
1334| 1900010  | read data from message sequence failed |
1335
1336**Example**
1337
1338  ```ts
1339  import { hilog } from '@kit.PerformanceAnalysisKit';
1340  import { BusinessError } from '@kit.BasicServicesKit';
1341
1342  let data = rpc.MessageSequence.create();
1343  try {
1344    data.writeString('abc');
1345  } catch (error) {
1346    let e: BusinessError = error as BusinessError;
1347    hilog.error(0x0000, 'testTag', 'rpc write string fail, errorCode ' + e.code);
1348    hilog.error(0x0000, 'testTag', 'rpc write string fail, errorMessage ' + e.message);
1349  }
1350  try {
1351    let ret = data.readString();
1352    hilog.info(0x0000, 'testTag', 'RpcClient: readString is ' + ret);
1353  } catch (error) {
1354    let e: BusinessError = error as BusinessError;
1355    hilog.error(0x0000, 'testTag', 'rpc read string fail, errorCode ' + e.code);
1356    hilog.error(0x0000, 'testTag', 'rpc read string fail, errorMessage ' + e.message);
1357  }
1358  ```
1359
1360### writeParcelable
1361
1362writeParcelable(val: Parcelable): void
1363
1364Writes a **Parcelable** object to this **MessageSequence** object.
1365
1366**System capability**: SystemCapability.Communication.IPC.Core
1367
1368**Parameters**
1369
1370| Name| Type| Mandatory| Description|
1371| ------ | --------- | ---- | ------ |
1372| val    | [Parcelable](#parcelable9) | Yes  | **Parcelable** object to write.|
1373
1374**Error codes**
1375
1376For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1377
1378| ID| Error Message|
1379| -------- | -------- |
1380| 401      | check param failed |
1381| 1900009  | write data to message sequence failed |
1382
1383**Example**
1384
1385  ```ts
1386  import { hilog } from '@kit.PerformanceAnalysisKit';
1387  import { BusinessError } from '@kit.BasicServicesKit';
1388
1389  class MyParcelable implements rpc.Parcelable {
1390    num: number = 0;
1391    str: string = '';
1392    constructor( num: number, str: string) {
1393      this.num = num;
1394      this.str = str;
1395    }
1396    marshalling(messageSequence: rpc.MessageSequence): boolean {
1397      messageSequence.writeInt(this.num);
1398      messageSequence.writeString(this.str);
1399      return true;
1400    }
1401    unmarshalling(messageSequence: rpc.MessageSequence): boolean {
1402      this.num = messageSequence.readInt();
1403      this.str = messageSequence.readString();
1404      return true;
1405    }
1406  }
1407  let parcelable = new MyParcelable(1, "aaa");
1408  let data = rpc.MessageSequence.create();
1409  try {
1410    data.writeParcelable(parcelable);
1411  } catch (error) {
1412    let e: BusinessError = error as BusinessError;
1413    hilog.error(0x0000, 'testTag', 'rpc write parcelable fail, errorCode ' + e.code);
1414    hilog.error(0x0000, 'testTag', 'rpc write parcelable fail, errorMessage ' + e.message);
1415  }
1416  ```
1417
1418### readParcelable
1419
1420readParcelable(dataIn: Parcelable): void
1421
1422Reads a **Parcelable** object from this **MessageSequence** object to the specified object (**dataIn**).
1423
1424**System capability**: SystemCapability.Communication.IPC.Core
1425
1426**Parameters**
1427
1428| Name| Type                      | Mandatory| Description                                     |
1429| ------ | -------------------------- | ---- | ----------------------------------------- |
1430| dataIn | [Parcelable](#parcelable9) | Yes  | **Parcelable** object to read.|
1431
1432**Error codes**
1433
1434For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1435
1436| ID| Error Message|
1437| -------- | -------- |
1438| 401      | check param failed |
1439| 1900010  | read data from message sequence failed |
1440| 1900012  | call js callback function failed |
1441
1442**Example**
1443
1444  ```ts
1445  import { hilog } from '@kit.PerformanceAnalysisKit';
1446  import { BusinessError } from '@kit.BasicServicesKit';
1447
1448  class MyParcelable implements rpc.Parcelable {
1449    num: number = 0;
1450    str: string = '';
1451    constructor(num: number, str: string) {
1452      this.num = num;
1453      this.str = str;
1454    }
1455    marshalling(messageSequence: rpc.MessageSequence): boolean {
1456      messageSequence.writeInt(this.num);
1457      messageSequence.writeString(this.str);
1458      return true;
1459    }
1460    unmarshalling(messageSequence: rpc.MessageSequence): boolean {
1461      this.num = messageSequence.readInt();
1462      this.str = messageSequence.readString();
1463      return true;
1464    }
1465  }
1466  let parcelable = new MyParcelable(1, "aaa");
1467  let data = rpc.MessageSequence.create();
1468  data.writeParcelable(parcelable);
1469  let ret = new MyParcelable(0, "");
1470  try {
1471    data.readParcelable(ret);
1472  }catch (error) {
1473    let e: BusinessError = error as BusinessError;
1474    hilog.error(0x0000, 'testTag', 'rpc read parcelable fail, errorCode ' + e.code);
1475    hilog.error(0x0000, 'testTag', 'rpc read parcelable fail, errorMessage ' + e.message);
1476  }
1477  ```
1478
1479### writeByteArray
1480
1481writeByteArray(byteArray: number[]): void
1482
1483Writes a byte array to this **MessageSequence** object.
1484
1485**System capability**: SystemCapability.Communication.IPC.Core
1486
1487**Parameters**
1488
1489| Name   | Type    | Mandatory| Description              |
1490| --------- | -------- | ---- | ------------------ |
1491| byteArray | number[] | Yes  | Byte array to write.|
1492
1493**Error codes**
1494
1495For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1496
1497| ID| Error Message|
1498| -------- | -------- |
1499| 401      | check param failed |
1500| 1900009  | write data to message sequence failed |
1501
1502**Example**
1503
1504  ```ts
1505  import { hilog } from '@kit.PerformanceAnalysisKit';
1506  import { BusinessError } from '@kit.BasicServicesKit';
1507
1508  let data = rpc.MessageSequence.create();
1509  let ByteArrayVar = [1, 2, 3, 4, 5];
1510  try {
1511    data.writeByteArray(ByteArrayVar);
1512  } catch (error) {
1513    let e: BusinessError = error as BusinessError;
1514    hilog.error(0x0000, 'testTag', 'rpc write byteArray fail, errorCode ' + e.code);
1515    hilog.error(0x0000, 'testTag', 'rpc write byteArray fail, errorMessage ' + e.message);
1516  }
1517  ```
1518
1519### readByteArray
1520
1521readByteArray(dataIn: number[]): void
1522
1523Reads a byte array from this **MessageSequence** object.
1524
1525**System capability**: SystemCapability.Communication.IPC.Core
1526
1527**Parameters**
1528
1529| Name| Type    | Mandatory| Description              |
1530| ------ | -------- | ---- | ------------------ |
1531| dataIn | number[] | Yes  | Byte array to read.|
1532
1533**Error codes**
1534
1535For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1536
1537| ID| Error Message|
1538| -------- | -------- |
1539| 401      | check param failed |
1540| 1900010  | read data from message sequence failed |
1541
1542**Example**
1543
1544  ```ts
1545  import { hilog } from '@kit.PerformanceAnalysisKit';
1546  import { BusinessError } from '@kit.BasicServicesKit';
1547
1548  let data = rpc.MessageSequence.create();
1549  let ByteArrayVar = [1, 2, 3, 4, 5];
1550  try {
1551    data.writeByteArray(ByteArrayVar);
1552  } catch (error) {
1553    let e: BusinessError = error as BusinessError;
1554    hilog.error(0x0000, 'testTag', 'rpc write byteArray fail, errorCode ' + e.code);
1555    hilog.error(0x0000, 'testTag', 'rpc write byteArray fail, errorMessage ' + e.message);
1556  }
1557  try {
1558    let array: Array<number> = new Array(5);
1559    data.readByteArray(array);
1560  } catch (error) {
1561    let e: BusinessError = error as BusinessError;
1562    hilog.error(0x0000, 'testTag', 'rpc read byteArray fail, errorCode ' + e.code);
1563    hilog.error(0x0000, 'testTag', 'rpc read byteArray fail, errorMessage ' + e.message);
1564  }
1565  ```
1566
1567### readByteArray
1568
1569readByteArray(): number[]
1570
1571Reads the byte array from this **MessageSequence** object.
1572
1573**System capability**: SystemCapability.Communication.IPC.Core
1574
1575**Return value**
1576
1577| Type    | Description          |
1578| -------- | -------------- |
1579| number[] | Byte array read.|
1580
1581**Error codes**
1582
1583For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1584
1585| ID| Error Message|
1586| -------- | -------- |
1587| 401      | check param failed |
1588| 1900010  | read data from message sequence failed |
1589
1590**Example**
1591
1592  ```ts
1593  import { hilog } from '@kit.PerformanceAnalysisKit';
1594  import { BusinessError } from '@kit.BasicServicesKit';
1595
1596  let data = rpc.MessageSequence.create();
1597  let byteArrayVar = [1, 2, 3, 4, 5];
1598  try {
1599    data.writeByteArray(byteArrayVar);
1600  } catch (error) {
1601    let e: BusinessError = error as BusinessError;
1602    hilog.error(0x0000, 'testTag', 'rpc write byteArray fail, errorCode ' + e.code);
1603    hilog.error(0x0000, 'testTag', 'rpc write byteArray fail, errorMessage ' + e.message);
1604  }
1605  try {
1606    let array = data.readByteArray();
1607    hilog.info(0x0000, 'testTag', 'RpcClient: readByteArray is ' +  array);
1608  } catch (error) {
1609    let e: BusinessError = error as BusinessError;
1610    hilog.error(0x0000, 'testTag', 'rpc read byteArray fail, errorCode ' + e.code);
1611    hilog.error(0x0000, 'testTag', 'rpc read byteArray fail, errorMessage ' + e.message);
1612  }
1613  ```
1614
1615### writeShortArray
1616
1617writeShortArray(shortArray: number[]): void
1618
1619Writes a short array to this **MessageSequence** object.
1620
1621**System capability**: SystemCapability.Communication.IPC.Core
1622
1623**Parameters**
1624
1625| Name    | Type    | Mandatory| Description                |
1626| ---------- | -------- | ---- | -------------------- |
1627| shortArray | number[] | Yes  | Short array to write.|
1628
1629**Error codes**
1630
1631For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1632
1633| ID| Error Message|
1634| -------- | -------- |
1635| 401      | check param failed |
1636| 1900009  | write data to message sequence failed |
1637
1638**Example**
1639
1640  ```ts
1641  import { hilog } from '@kit.PerformanceAnalysisKit';
1642  import { BusinessError } from '@kit.BasicServicesKit';
1643
1644  let data = rpc.MessageSequence.create();
1645  try {
1646    data.writeShortArray([11, 12, 13]);
1647  } catch (error) {
1648    let e: BusinessError = error as BusinessError;
1649    hilog.error(0x0000, 'testTag', 'rpc write shortArray fail, errorCode ' + e.code);
1650    hilog.error(0x0000, 'testTag', 'rpc write shortArray fail, errorMessage ' + e.message);
1651  }
1652  ```
1653
1654### readShortArray
1655
1656readShortArray(dataIn: number[]): void
1657
1658Reads a short array from this **MessageSequence** object.
1659
1660**System capability**: SystemCapability.Communication.IPC.Core
1661
1662**Parameters**
1663
1664| Name| Type    | Mandatory| Description                |
1665| ------ | -------- | ---- | -------------------- |
1666| dataIn | number[] | Yes  | Short array to read.|
1667
1668**Error codes**
1669
1670For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1671
1672| ID| Error Message|
1673| -------- | -------- |
1674| 401      | check param failed |
1675| 1900010  | read data from message sequence failed |
1676
1677**Example**
1678
1679  ```ts
1680  import { hilog } from '@kit.PerformanceAnalysisKit';
1681  import { BusinessError } from '@kit.BasicServicesKit';
1682
1683  let data = rpc.MessageSequence.create();
1684  try {
1685    data.writeShortArray([11, 12, 13]);
1686  } catch (error) {
1687    let e: BusinessError = error as BusinessError;
1688    hilog.error(0x0000, 'testTag', 'rpc write shortArray fail, errorCode ' + e.code);
1689    hilog.error(0x0000, 'testTag', 'rpc write shortArray fail, errorMessage ' + e.message);
1690  }
1691  try {
1692    let array: Array<number> = new Array(3);
1693    data.readShortArray(array);
1694  } catch (error) {
1695    let e: BusinessError = error as BusinessError;
1696    hilog.error(0x0000, 'testTag', 'rpc read shortArray fail, errorCode ' + e.code);
1697    hilog.error(0x0000, 'testTag', 'rpc read shortArray fail, errorMessage ' + e.message);
1698  }
1699  ```
1700
1701### readShortArray
1702
1703readShortArray(): number[]
1704
1705Reads the short array from this **MessageSequence** object.
1706
1707**System capability**: SystemCapability.Communication.IPC.Core
1708
1709**Return value**
1710
1711| Type    | Description            |
1712| -------- | ---------------- |
1713| number[] | Short array read.|
1714
1715**Error codes**
1716
1717For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1718
1719| ID| Error Message|
1720| -------- | -------- |
1721| 1900010  | read data from message sequence failed |
1722
1723**Example**
1724
1725  ```ts
1726  import { hilog } from '@kit.PerformanceAnalysisKit';
1727  import { BusinessError } from '@kit.BasicServicesKit';
1728
1729  let data = rpc.MessageSequence.create();
1730  try {
1731    data.writeShortArray([11, 12, 13]);
1732  } catch (error) {
1733    let e: BusinessError = error as BusinessError;
1734    hilog.error(0x0000, 'testTag', 'rpc write shortArray fail, errorCode ' + e.code);
1735    hilog.error(0x0000, 'testTag', 'rpc write shortArray fail, errorMessage ' + e.message);
1736  }
1737  try {
1738    let array = data.readShortArray();
1739    hilog.info(0x0000, 'testTag', 'RpcClient: readShortArray is ' + array);
1740  } catch (error) {
1741    let e: BusinessError = error as BusinessError;
1742    hilog.error(0x0000, 'testTag', 'rpc read shortArray fail, errorCode ' + e.code);
1743    hilog.error(0x0000, 'testTag', 'rpc read shortArray fail, errorMessage ' + e.message);
1744  }
1745  ```
1746
1747### writeIntArray
1748
1749writeIntArray(intArray: number[]): void
1750
1751Writes an integer array to this **MessageSequence** object.
1752
1753**System capability**: SystemCapability.Communication.IPC.Core
1754
1755**Parameters**
1756
1757| Name  | Type    | Mandatory| Description              |
1758| -------- | -------- | ---- | ------------------ |
1759| intArray | number[] | Yes  | Integer array to write.|
1760
1761**Error codes**
1762
1763For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1764
1765| ID| Error Message|
1766| -------- | -------- |
1767| 401      | check param failed |
1768| 1900009  | write data to message sequence failed |
1769
1770**Example**
1771
1772  ```ts
1773  import { hilog } from '@kit.PerformanceAnalysisKit';
1774  import { BusinessError } from '@kit.BasicServicesKit';
1775
1776  let data = rpc.MessageSequence.create();
1777  try {
1778    data.writeIntArray([100, 111, 112]);
1779  } catch (error) {
1780    let e: BusinessError = error as BusinessError;
1781    hilog.error(0x0000, 'testTag', 'rpc write intArray fail, errorCode ' + e.code);
1782    hilog.error(0x0000, 'testTag', 'rpc write intArray fail, errorMessage ' + e.message);
1783  }
1784  ```
1785
1786### readIntArray
1787
1788readIntArray(dataIn: number[]): void
1789
1790Reads an integer array from this **MessageSequence** object.
1791
1792**System capability**: SystemCapability.Communication.IPC.Core
1793
1794**Parameters**
1795
1796| Name| Type    | Mandatory| Description              |
1797| ------ | -------- | ---- | ------------------ |
1798| dataIn | number[] | Yes  | Integer array to read.|
1799
1800**Error codes**
1801
1802For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1803
1804| ID| Error Message|
1805| -------- | -------- |
1806| 401      | check param failed |
1807| 1900010  | read data from message sequence failed |
1808
1809**Example**
1810
1811  ```ts
1812  import { hilog } from '@kit.PerformanceAnalysisKit';
1813  import { BusinessError } from '@kit.BasicServicesKit';
1814
1815  let data = rpc.MessageSequence.create();
1816  try {
1817    data.writeIntArray([100, 111, 112]);
1818  } catch (error) {
1819    let e: BusinessError = error as BusinessError;
1820    hilog.error(0x0000, 'testTag', 'rpc write intArray fail, errorCode ' + e.code);
1821    hilog.error(0x0000, 'testTag', 'rpc write intArray fail, errorMessage ' + e.message);
1822  }
1823  let array: Array<number> = new Array(3);
1824  try {
1825    data.readIntArray(array);
1826  } catch (error) {
1827    let e: BusinessError = error as BusinessError;
1828    hilog.error(0x0000, 'testTag', 'rpc read intArray fail, errorCode ' + e.code);
1829    hilog.error(0x0000, 'testTag', 'rpc read intArray fail, errorMessage ' + e.message);
1830  }
1831  ```
1832
1833### readIntArray
1834
1835readIntArray(): number[]
1836
1837Reads the integer array from this **MessageSequence** object.
1838
1839**System capability**: SystemCapability.Communication.IPC.Core
1840
1841**Return value**
1842
1843| Type    | Description          |
1844| -------- | -------------- |
1845| number[] | Integer array read.|
1846
1847**Error codes**
1848
1849For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1850
1851| ID| Error Message|
1852| -------- | -------- |
1853| 1900010  | read data from message sequence failed |
1854
1855**Example**
1856
1857  ```ts
1858  import { hilog } from '@kit.PerformanceAnalysisKit';
1859  import { BusinessError } from '@kit.BasicServicesKit';
1860
1861  let data = rpc.MessageSequence.create();
1862  try {
1863    data.writeIntArray([100, 111, 112]);
1864  } catch (error) {
1865    let e: BusinessError = error as BusinessError;
1866    hilog.error(0x0000, 'testTag', 'rpc write intArray fail, errorCode ' + e.code);
1867    hilog.error(0x0000, 'testTag', 'rpc write intArray fail, errorMessage ' + e.message);
1868  }
1869  try {
1870    let array = data.readIntArray();
1871    hilog.info(0x0000, 'testTag', 'RpcClient: readIntArray is ' + array);
1872  } catch (error) {
1873    let e: BusinessError = error as BusinessError;
1874    hilog.error(0x0000, 'testTag', 'rpc read intArray fail, errorCode ' + e.code);
1875    hilog.error(0x0000, 'testTag', 'rpc read intArray fail, errorMessage ' + e.message);
1876  }
1877  ```
1878
1879### writeLongArray
1880
1881writeLongArray(longArray: number[]): void
1882
1883Writes a long array to this **MessageSequence** object.
1884
1885**System capability**: SystemCapability.Communication.IPC.Core
1886
1887**Parameters**
1888
1889| Name   | Type    | Mandatory| Description                |
1890| --------- | -------- | ---- | -------------------- |
1891| longArray | number[] | Yes  | Long array to write.|
1892
1893**Error codes**
1894
1895For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1896
1897| ID| Error Message|
1898| -------- | -------- |
1899| 401      | check param failed |
1900| 1900009  | write data to message sequence failed |
1901
1902**Example**
1903
1904  ```ts
1905  import { hilog } from '@kit.PerformanceAnalysisKit';
1906  import { BusinessError } from '@kit.BasicServicesKit';
1907
1908  let data = rpc.MessageSequence.create();
1909  try {
1910    data.writeLongArray([1111, 1112, 1113]);
1911  }catch (error){
1912    let e: BusinessError = error as BusinessError;
1913    hilog.error(0x0000, 'testTag', 'rpc write longArray fail, errorCode ' + e.code);
1914    hilog.error(0x0000, 'testTag', 'rpc write longArray fail, errorMessage ' + e.message);
1915  }
1916  ```
1917
1918### readLongArray
1919
1920readLongArray(dataIn: number[]): void
1921
1922Reads a long array from this **MessageSequence** object.
1923
1924**System capability**: SystemCapability.Communication.IPC.Core
1925
1926**Parameters**
1927
1928| Name| Type    | Mandatory| Description                |
1929| ------ | -------- | ---- | -------------------- |
1930| dataIn | number[] | Yes  | Long array to read.|
1931
1932**Error codes**
1933
1934For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1935
1936| ID| Error Message|
1937| -------- | -------- |
1938| 401      | check param failed |
1939| 1900010  | read data from message sequence failed |
1940
1941**Example**
1942
1943  ```ts
1944  import { hilog } from '@kit.PerformanceAnalysisKit';
1945  import { BusinessError } from '@kit.BasicServicesKit';
1946
1947  let data = rpc.MessageSequence.create();
1948  try {
1949    data.writeLongArray([1111, 1112, 1113]);
1950  } catch (error) {
1951    let e: BusinessError = error as BusinessError;
1952    hilog.error(0x0000, 'testTag', 'rpc write longArray fail, errorCode ' + e.code);
1953    hilog.error(0x0000, 'testTag', 'rpc write longArray fail, errorMessage ' + e.message);
1954  }
1955  let array: Array<number> = new Array(3);
1956  try {
1957    data.readLongArray(array);
1958  } catch (error) {
1959    let e: BusinessError = error as BusinessError;
1960    hilog.error(0x0000, 'testTag', 'rpc read longArray fail, errorCode ' + e.code);
1961    hilog.error(0x0000, 'testTag', 'rpc read longArray fail, errorMessage ' + e.message);
1962  }
1963  ```
1964
1965### readLongArray
1966
1967readLongArray(): number[]
1968
1969Reads the long integer array from this **MessageSequence** object.
1970
1971**System capability**: SystemCapability.Communication.IPC.Core
1972
1973**Return value**
1974
1975| Type    | Description            |
1976| -------- | ---------------- |
1977| number[] | Long array read.|
1978
1979**Error codes**
1980
1981For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
1982
1983| ID| Error Message|
1984| -------- | -------- |
1985| 1900010  | read data from message sequence failed |
1986
1987**Example**
1988
1989  ```ts
1990  import { hilog } from '@kit.PerformanceAnalysisKit';
1991  import { BusinessError } from '@kit.BasicServicesKit';
1992
1993  let data = rpc.MessageSequence.create();
1994  try {
1995    data.writeLongArray([1111, 1112, 1113]);
1996  } catch (error) {
1997    let e: BusinessError = error as BusinessError;
1998    hilog.error(0x0000, 'testTag', 'rpc write longArray fail, errorCode ' + e.code);
1999    hilog.error(0x0000, 'testTag', 'rpc write longArray fail, errorMessage ' + e.message);
2000  }
2001  try {
2002    let array = data.readLongArray();
2003    hilog.info(0x0000, 'testTag', 'RpcClient: readLongArray is ' + array);
2004  } catch (error) {
2005    let e: BusinessError = error as BusinessError;
2006    hilog.error(0x0000, 'testTag', 'rpc read longArray fail, errorCode ' + e.code);
2007    hilog.error(0x0000, 'testTag', 'rpc read longArray fail, errorMessage ' + e.message);
2008  }
2009  ```
2010
2011### writeFloatArray
2012
2013writeFloatArray(floatArray: number[]): void
2014
2015Writes a floating-point array to this **MessageSequence** object.
2016
2017**System capability**: SystemCapability.Communication.IPC.Core
2018
2019**Parameters**
2020
2021| Name    | Type    | Mandatory| Description                                                                                                                   |
2022| ---------- | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
2023| floatArray | number[] | Yes  | Floating-point array to write. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
2024
2025**Error codes**
2026
2027For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2028
2029| ID| Error Message|
2030| -------- | -------- |
2031| 401      | check param failed |
2032| 1900009  | write data to message sequence failed |
2033
2034**Example**
2035
2036  ```ts
2037  import { hilog } from '@kit.PerformanceAnalysisKit';
2038  import { BusinessError } from '@kit.BasicServicesKit';
2039
2040  let data = rpc.MessageSequence.create();
2041  try {
2042    data.writeFloatArray([1.2, 1.3, 1.4]);
2043  } catch (error) {
2044    let e: BusinessError = error as BusinessError;
2045    hilog.error(0x0000, 'testTag', 'rpc write floatArray fail, errorCode ' + e.code);
2046    hilog.error(0x0000, 'testTag', 'rpc write floatArray fail, errorMessage ' + e.message);
2047  }
2048  ```
2049
2050### readFloatArray
2051
2052readFloatArray(dataIn: number[]): void
2053
2054Reads a floating-point array from this **MessageSequence** object.
2055
2056**System capability**: SystemCapability.Communication.IPC.Core
2057
2058**Parameters**
2059
2060| Name| Type    | Mandatory| Description                                                                                                                   |
2061| ------ | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
2062| dataIn | number[] | Yes  | Floating-point array to read. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
2063
2064**Error codes**
2065
2066For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2067
2068| ID| Error Message|
2069| -------- | -------- |
2070| 401      | check param failed |
2071| 1900010  | read data from message sequence failed |
2072
2073**Example**
2074
2075  ```ts
2076  import { hilog } from '@kit.PerformanceAnalysisKit';
2077  import { BusinessError } from '@kit.BasicServicesKit';
2078
2079  let data = rpc.MessageSequence.create();
2080  try {
2081    data.writeFloatArray([1.2, 1.3, 1.4]);
2082  }catch (error){
2083    let e: BusinessError = error as BusinessError;
2084    hilog.error(0x0000, 'testTag', 'rpc write floatArray fail, errorCode ' + e.code);
2085    hilog.error(0x0000, 'testTag', 'rpc write floatArray fail, errorMessage ' + e.message);
2086  }
2087  let array: Array<number> = new Array(3);
2088  try {
2089    data.readFloatArray(array);
2090  } catch (error) {
2091    let e: BusinessError = error as BusinessError;
2092    hilog.error(0x0000, 'testTag', 'rpc read floatArray fail, errorCode ' + e.code);
2093    hilog.error(0x0000, 'testTag', 'rpc read floatArray fail, errorMessage ' + e.message);
2094  }
2095  ```
2096
2097### readFloatArray
2098
2099readFloatArray(): number[]
2100
2101Reads the floating-point array from this **MessageSequence** object.
2102
2103**System capability**: SystemCapability.Communication.IPC.Core
2104
2105**Return value**
2106
2107| Type    | Description          |
2108| -------- | -------------- |
2109| number[] | Floating-point array read.|
2110
2111**Error codes**
2112
2113For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2114
2115| ID| Error Message|
2116| -------- | -------- |
2117| 1900010  | read data from message sequence failed |
2118
2119**Example**
2120
2121  ```ts
2122  import { hilog } from '@kit.PerformanceAnalysisKit';
2123  import { BusinessError } from '@kit.BasicServicesKit';
2124
2125  let data = rpc.MessageSequence.create();
2126  try {
2127    data.writeFloatArray([1.2, 1.3, 1.4]);
2128  } catch (error) {
2129    let e: BusinessError = error as BusinessError;
2130    hilog.error(0x0000, 'testTag', 'rpc write floatArray fail, errorCode ' + e.code);
2131    hilog.error(0x0000, 'testTag', 'rpc write floatArray fail, errorMessage ' + e.message);
2132  }
2133  try {
2134    let array = data.readFloatArray();
2135    hilog.info(0x0000, 'testTag', 'RpcClient: readFloatArray is ' + array);
2136  } catch (error) {
2137    let e: BusinessError = error as BusinessError;
2138    hilog.error(0x0000, 'testTag', 'rpc read floatArray fail, errorCode ' + e.code);
2139    hilog.error(0x0000, 'testTag', 'rpc read floatArray fail, errorMessage ' + e.message);
2140  }
2141  ```
2142
2143### writeDoubleArray
2144
2145writeDoubleArray(doubleArray: number[]): void
2146
2147Writes a double-precision floating-point array to this **MessageSequence** object.
2148
2149**System capability**: SystemCapability.Communication.IPC.Core
2150
2151**Parameters**
2152
2153| Name     | Type    | Mandatory| Description                    |
2154| ----------- | -------- | ---- | ------------------------ |
2155| doubleArray | number[] | Yes  | Double-precision floating-point array to write.|
2156
2157**Error codes**
2158
2159For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2160
2161| ID| Error Message|
2162| -------- | -------- |
2163| 401      | check param failed |
2164| 1900009  | write data to message sequence failed |
2165
2166**Example**
2167
2168  ```ts
2169  import { hilog } from '@kit.PerformanceAnalysisKit';
2170  import { BusinessError } from '@kit.BasicServicesKit';
2171
2172  let data = rpc.MessageSequence.create();
2173  try {
2174    data.writeDoubleArray([11.1, 12.2, 13.3]);
2175  } catch (error) {
2176    let e: BusinessError = error as BusinessError;
2177    hilog.error(0x0000, 'testTag', 'rpc write doubleArray fail, errorCode ' + e.code);
2178    hilog.error(0x0000, 'testTag', 'rpc write doubleArray fail, errorMessage ' + e.message);
2179  }
2180  ```
2181
2182### readDoubleArray
2183
2184readDoubleArray(dataIn: number[]): void
2185
2186Reads a double-precision floating-point array from this **MessageSequence** object.
2187
2188**System capability**: SystemCapability.Communication.IPC.Core
2189
2190**Parameters**
2191
2192| Name| Type    | Mandatory| Description                    |
2193| ------ | -------- | ---- | ------------------------ |
2194| dataIn | number[] | Yes  | Double-precision floating-point array to read.|
2195
2196**Error codes**
2197
2198For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2199
2200| ID| Error Message|
2201| -------- | -------- |
2202| 401      | check param failed |
2203| 1900010  | read data from message sequence failed |
2204
2205**Example**
2206
2207  ```ts
2208  import { hilog } from '@kit.PerformanceAnalysisKit';
2209  import { BusinessError } from '@kit.BasicServicesKit';
2210
2211  let data = rpc.MessageSequence.create();
2212  try {
2213    data.writeDoubleArray([11.1, 12.2, 13.3]);
2214  } catch (error) {
2215    let e: BusinessError = error as BusinessError;
2216    hilog.error(0x0000, 'testTag', 'rpc write doubleArray fail, errorCode ' + e.code);
2217    hilog.error(0x0000, 'testTag', 'rpc write doubleArray fail, errorMessage ' + e.message);
2218  }
2219  let array: Array<number> = new Array(3);
2220  try {
2221    data.readDoubleArray(array);
2222  } catch (error) {
2223    let e: BusinessError = error as BusinessError;
2224    hilog.error(0x0000, 'testTag', 'rpc read doubleArray fail, errorCode ' + e.code);
2225    hilog.error(0x0000, 'testTag', 'rpc read doubleArray fail, errorMessage ' + e.message);
2226  }
2227  ```
2228
2229### readDoubleArray
2230
2231readDoubleArray(): number[]
2232
2233Reads the double-precision floating-point array from this **MessageSequence** object.
2234
2235**System capability**: SystemCapability.Communication.IPC.Core
2236
2237**Return value**
2238
2239| Type    | Description                |
2240| -------- | -------------------- |
2241| number[] | Double-precision floating-point array read.|
2242
2243**Error codes**
2244
2245For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2246
2247| ID| Error Message|
2248| -------- | -------- |
2249| 1900010  | read data from message sequence failed |
2250
2251**Example**
2252
2253  ```ts
2254  import { hilog } from '@kit.PerformanceAnalysisKit';
2255  import { BusinessError } from '@kit.BasicServicesKit';
2256
2257  let data = rpc.MessageSequence.create();
2258  try {
2259    data.writeDoubleArray([11.1, 12.2, 13.3]);
2260  } catch (error) {
2261    let e: BusinessError = error as BusinessError;
2262    hilog.error(0x0000, 'testTag', 'rpc write doubleArray fail, errorCode ' + e.code);
2263    hilog.error(0x0000, 'testTag', 'rpc write doubleArray fail, errorMessage ' + e.message);
2264  }
2265  try {
2266    let array = data.readDoubleArray();
2267    hilog.info(0x0000, 'testTag', 'RpcClient: readDoubleArray is ' + array);
2268  } catch (error) {
2269    let e: BusinessError = error as BusinessError;
2270    hilog.error(0x0000, 'testTag', 'rpc read doubleArray fail, errorCode ' + e.code);
2271    hilog.error(0x0000, 'testTag', 'rpc read doubleArray fail, errorMessage ' + e.message);
2272  }
2273  ```
2274
2275### writeBooleanArray
2276
2277writeBooleanArray(booleanArray: boolean[]): void
2278
2279Writes a Boolean array to this **MessageSequence** object.
2280
2281**System capability**: SystemCapability.Communication.IPC.Core
2282
2283**Parameters**
2284
2285| Name      | Type     | Mandatory| Description              |
2286| ------------ | --------- | ---- | ------------------ |
2287| booleanArray | boolean[] | Yes  | Boolean array to write.|
2288
2289**Error codes**
2290
2291For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2292
2293| ID| Error Message|
2294| -------- | -------- |
2295| 401      | check param failed |
2296| 1900009  | write data to message sequence failed |
2297
2298**Example**
2299
2300  ```ts
2301  import { hilog } from '@kit.PerformanceAnalysisKit';
2302  import { BusinessError } from '@kit.BasicServicesKit';
2303
2304  let data = rpc.MessageSequence.create();
2305  try {
2306    data.writeBooleanArray([false, true, false]);
2307  } catch (error) {
2308    let e: BusinessError = error as BusinessError;
2309    hilog.error(0x0000, 'testTag', 'rpc write booleanArray fail, errorCode ' + e.code);
2310    hilog.error(0x0000, 'testTag', 'rpc write booleanArray fail, errorMessage ' + e.message);
2311  }
2312  ```
2313
2314### readBooleanArray
2315
2316readBooleanArray(dataIn: boolean[]): void
2317
2318Reads a Boolean array from this **MessageSequence** object.
2319
2320**System capability**: SystemCapability.Communication.IPC.Core
2321
2322**Parameters**
2323
2324| Name| Type     | Mandatory| Description              |
2325| ------ | --------- | ---- | ------------------ |
2326| dataIn | boolean[] | Yes  | Boolean array to read.|
2327
2328**Error codes**
2329
2330For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2331
2332| ID| Error Message|
2333| -------- | -------- |
2334| 401      | check param failed |
2335| 1900010  | read data from message sequence failed |
2336
2337**Example**
2338
2339  ```ts
2340  import { hilog } from '@kit.PerformanceAnalysisKit';
2341  import { BusinessError } from '@kit.BasicServicesKit';
2342
2343  let data = rpc.MessageSequence.create();
2344  try {
2345    data.writeBooleanArray([false, true, false]);
2346  } catch (error) {
2347    let e: BusinessError = error as BusinessError;
2348    hilog.error(0x0000, 'testTag', 'rpc write booleanArray fail, errorCode ' + e.code);
2349    hilog.error(0x0000, 'testTag', 'rpc write booleanArray fail, errorMessage ' + e.message);
2350  }
2351  let array: Array<boolean> = new Array(3);
2352  try {
2353    data.readBooleanArray(array);
2354  } catch (error) {
2355    let e: BusinessError = error as BusinessError;
2356    hilog.error(0x0000, 'testTag', 'rpc read booleanArray fail, errorCode ' + e.code);
2357    hilog.error(0x0000, 'testTag', 'rpc read booleanArray fail, errorMessage ' + e.message);
2358  }
2359  ```
2360
2361### readBooleanArray
2362
2363readBooleanArray(): boolean[]
2364
2365Reads the Boolean array from this **MessageSequence** object.
2366
2367**System capability**: SystemCapability.Communication.IPC.Core
2368
2369**Return value**
2370
2371| Type     | Description          |
2372| --------- | -------------- |
2373| boolean[] | Boolean array read.|
2374
2375**Error codes**
2376
2377For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2378
2379| ID| Error Message|
2380| -------- | -------- |
2381| 1900010  | read data from message sequence failed |
2382
2383**Example**
2384
2385  ```ts
2386  import { hilog } from '@kit.PerformanceAnalysisKit';
2387  import { BusinessError } from '@kit.BasicServicesKit';
2388
2389  let data = rpc.MessageSequence.create();
2390  try {
2391    data.writeBooleanArray([false, true, false]);
2392  } catch (error) {
2393    let e: BusinessError = error as BusinessError;
2394    hilog.error(0x0000, 'testTag', 'rpc write booleanArray fail, errorCode ' + e.code);
2395    hilog.error(0x0000, 'testTag', 'rpc write booleanArray fail, errorMessage ' + e.message);
2396  }
2397  try {
2398    let array = data.readBooleanArray();
2399    hilog.info(0x0000, 'testTag', 'RpcClient: readBooleanArray is ' + array);
2400  } catch (error) {
2401    let e: BusinessError = error as BusinessError;
2402    hilog.error(0x0000, 'testTag', 'rpc read booleanArray fail, errorCode ' + e.code);
2403    hilog.error(0x0000, 'testTag', 'rpc read booleanArray fail, errorMessage ' + e.message);
2404  }
2405  ```
2406
2407### writeCharArray
2408
2409writeCharArray(charArray: number[]): void
2410
2411Writes a character array to this **MessageSequence** object.
2412
2413**System capability**: SystemCapability.Communication.IPC.Core
2414
2415**Parameters**
2416
2417| Name   | Type    | Mandatory| Description                  |
2418| --------- | -------- | ---- | ---------------------- |
2419| charArray | number[] | Yes  | Character array to write.|
2420
2421**Error codes**
2422
2423For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2424
2425| ID| Error Message|
2426| -------- | -------- |
2427| 401      | check param failed |
2428| 1900009  | write data to message sequence failed |
2429
2430**Example**
2431
2432  ```ts
2433  import { hilog } from '@kit.PerformanceAnalysisKit';
2434  import { BusinessError } from '@kit.BasicServicesKit';
2435
2436  let data = rpc.MessageSequence.create();
2437  try {
2438    data.writeCharArray([97, 98, 88]);
2439  } catch (error) {
2440    let e: BusinessError = error as BusinessError;
2441    hilog.error(0x0000, 'testTag', 'rpc write charArray fail, errorCode ' + e.code);
2442    hilog.error(0x0000, 'testTag', 'rpc write charArray fail, errorMessage ' + e.message);
2443  }
2444  ```
2445
2446### readCharArray
2447
2448readCharArray(dataIn: number[]): void
2449
2450Reads a character array from this **MessageSequence** object.
2451
2452**System capability**: SystemCapability.Communication.IPC.Core
2453
2454**Parameters**
2455
2456| Name| Type    | Mandatory| Description                  |
2457| ------ | -------- | ---- | ---------------------- |
2458| dataIn | number[] | Yes  | Character array to read.|
2459
2460**Error codes**
2461
2462For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2463
2464| ID| Error Message|
2465| -------- | -------- |
2466| 401      | check param failed |
2467| 1900010  | read data from message sequence failed |
2468
2469**Example**
2470
2471  ```ts
2472  import { hilog } from '@kit.PerformanceAnalysisKit';
2473  import { BusinessError } from '@kit.BasicServicesKit';
2474
2475  let data = rpc.MessageSequence.create();
2476  try {
2477    data.writeCharArray([97, 98, 88]);
2478  } catch (error) {
2479    let e: BusinessError = error as BusinessError;
2480    hilog.error(0x0000, 'testTag', 'rpc write charArray fail, errorCode ' + e.code);
2481    hilog.error(0x0000, 'testTag', 'rpc write charArray fail, errorMessage ' + e.message);
2482  }
2483  let array: Array<number> = new Array(3);
2484  try {
2485    data.readCharArray(array);
2486  } catch (error) {
2487    let e: BusinessError = error as BusinessError;
2488    hilog.error(0x0000, 'testTag', 'rpc read charArray fail, errorCode ' + e.code);
2489    hilog.error(0x0000, 'testTag', 'rpc read charArray fail, errorMessage ' + e.message);
2490  }
2491  ```
2492
2493### readCharArray
2494
2495readCharArray(): number[]
2496
2497Reads the character array from this **MessageSequence** object.
2498
2499**System capability**: SystemCapability.Communication.IPC.Core
2500
2501**Return value**
2502
2503| Type    | Description              |
2504| -------- | ------------------ |
2505| number[] | Character array read.|
2506
2507**Error codes**
2508
2509For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2510
2511| ID| Error Message|
2512| -------- | -------- |
2513| 1900010  | read data from message sequence failed |
2514
2515**Example**
2516
2517  ```ts
2518  import { hilog } from '@kit.PerformanceAnalysisKit';
2519  import { BusinessError } from '@kit.BasicServicesKit';
2520
2521  let data = rpc.MessageSequence.create();
2522  try {
2523    data.writeCharArray([97, 98, 88]);
2524  } catch (error) {
2525    let e: BusinessError = error as BusinessError;
2526    hilog.error(0x0000, 'testTag', 'rpc write charArray fail, errorCode ' + e.code);
2527    hilog.error(0x0000, 'testTag', 'rpc write charArray fail, errorMessage ' + e.message);
2528  }
2529  try {
2530    let array = data.readCharArray();
2531    hilog.info(0x0000, 'testTag', 'RpcClient: readCharArray is ' + array);
2532  } catch (error) {
2533    let e: BusinessError = error as BusinessError;
2534    hilog.error(0x0000, 'testTag', 'rpc read charArray fail, errorCode ' + e.code);
2535    hilog.error(0x0000, 'testTag', 'rpc read charArray fail, errorMessage ' + e.message);
2536  }
2537  ```
2538
2539### writeStringArray
2540
2541writeStringArray(stringArray: string[]): void
2542
2543Writes a string array to this **MessageSequence** object.
2544
2545**System capability**: SystemCapability.Communication.IPC.Core
2546
2547**Parameters**
2548
2549| Name     | Type    | Mandatory| Description                                                   |
2550| ----------- | -------- | ---- | ------------------------------------------------------- |
2551| stringArray | string[] | Yes  | String array to write. The length of a single element in the array must be less than 40960 bytes.|
2552
2553**Error codes**
2554
2555For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2556
2557| ID| Error Message|
2558| -------- | -------- |
2559| 401      | check param failed |
2560| 1900009  | write data to message sequence failed |
2561
2562**Example**
2563
2564  ```ts
2565  import { hilog } from '@kit.PerformanceAnalysisKit';
2566  import { BusinessError } from '@kit.BasicServicesKit';
2567
2568  let data = rpc.MessageSequence.create();
2569  try {
2570    data.writeStringArray(["abc", "def"]);
2571  } catch (error) {
2572    let e: BusinessError = error as BusinessError;
2573    hilog.error(0x0000, 'testTag', 'rpc write stringArray fail, errorCode ' + e.code);
2574    hilog.error(0x0000, 'testTag', 'rpc write stringArray fail, errorMessage ' + e.message);
2575  }
2576  ```
2577
2578### readStringArray
2579
2580readStringArray(dataIn: string[]): void
2581
2582Reads a string array from this **MessageSequence** object.
2583
2584**System capability**: SystemCapability.Communication.IPC.Core
2585
2586**Parameters**
2587
2588| Name| Type    | Mandatory| Description                |
2589| ------ | -------- | ---- | -------------------- |
2590| dataIn | string[] | Yes  | String array to read.|
2591
2592**Error codes**
2593
2594For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2595
2596| ID| Error Message|
2597| -------- | -------- |
2598| 401      | check param failed |
2599| 1900010  | read data from message sequence failed |
2600
2601**Example**
2602
2603  ```ts
2604  import { hilog } from '@kit.PerformanceAnalysisKit';
2605  import { BusinessError } from '@kit.BasicServicesKit';
2606
2607  let data = rpc.MessageSequence.create();
2608  try {
2609    data.writeStringArray(["abc", "def"]);
2610  } catch (error) {
2611    let e: BusinessError = error as BusinessError;
2612    hilog.error(0x0000, 'testTag', 'rpc write stringArray fail, errorCode ' + e.code);
2613    hilog.error(0x0000, 'testTag', 'rpc write stringArray fail, errorMessage ' + e.message);
2614  }
2615  let array: Array<string> = new Array(2);
2616  try {
2617    data.readStringArray(array);
2618  } catch (error) {
2619    let e: BusinessError = error as BusinessError;
2620    hilog.error(0x0000, 'testTag', 'rpc read stringArray fail, errorCode ' + e.code);
2621    hilog.error(0x0000, 'testTag', 'rpc read stringArray fail, errorMessage ' + e.message);
2622  }
2623  ```
2624
2625### readStringArray
2626
2627readStringArray(): string[]
2628
2629Reads the string array from this **MessageSequence** object.
2630
2631**System capability**: SystemCapability.Communication.IPC.Core
2632
2633**Return value**
2634
2635| Type    | Description            |
2636| -------- | ---------------- |
2637| string[] | String array read.|
2638
2639**Error codes**
2640
2641For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2642
2643| ID| Error Message|
2644| -------- | -------- |
2645| 1900010  | read data from message sequence failed |
2646
2647**Example**
2648
2649  ```ts
2650  import { hilog } from '@kit.PerformanceAnalysisKit';
2651  import { BusinessError } from '@kit.BasicServicesKit';
2652
2653  let data = rpc.MessageSequence.create();
2654  try {
2655    data.writeStringArray(["abc", "def"]);
2656  } catch (error) {
2657    let e: BusinessError = error as BusinessError;
2658    hilog.error(0x0000, 'testTag', 'rpc write stringArray fail, errorCode ' + e.code);
2659    hilog.error(0x0000, 'testTag', 'rpc write stringArray fail, errorMessage ' + e.message);
2660  }
2661  try {
2662    let array = data.readStringArray();
2663    hilog.info(0x0000, 'testTag', 'RpcClient: readStringArray is ' + array);
2664  } catch (error) {
2665    let e: BusinessError = error as BusinessError;
2666    hilog.error(0x0000, 'testTag', 'rpc read stringArray fail, errorCode ' + e.code);
2667    hilog.error(0x0000, 'testTag', 'rpc read stringArray fail, errorMessage ' + e.message);
2668  }
2669  ```
2670
2671### writeNoException
2672
2673writeNoException(): void
2674
2675Writes information to this **MessageSequence** object indicating that no exception occurred.
2676
2677**System capability**: SystemCapability.Communication.IPC.Core
2678
2679**Error codes**
2680
2681For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2682
2683| ID| Error Message|
2684| -------- | -------- |
2685| 1900009  | write data to message sequence failed |
2686
2687**Example**
2688
2689  ```ts
2690  import { hilog } from '@kit.PerformanceAnalysisKit';
2691  import { BusinessError } from '@kit.BasicServicesKit';
2692
2693  class TestRemoteObject extends rpc.RemoteObject {
2694    constructor(descriptor: string) {
2695      super(descriptor);
2696    }
2697    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
2698      if (code === 1) {
2699        hilog.info(0x0000, 'testTag', 'RpcServer: onRemoteMessageRequest called');
2700        try {
2701          reply.writeNoException();
2702        } catch (error) {
2703          let e: BusinessError = error as BusinessError;
2704          hilog.error(0x0000, 'testTag', 'rpc write no exception fail, errorCode ' + e.code);
2705          hilog.error(0x0000, 'testTag', 'rpc write no exception fail, errorMessage ' + e.message);
2706        }
2707        return true;
2708      } else {
2709        hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
2710        return false;
2711      }
2712    }
2713  }
2714  ```
2715
2716### readException
2717
2718readException(): void
2719
2720Reads the exception information from this **MessageSequence** object.
2721
2722**System capability**: SystemCapability.Communication.IPC.Core
2723
2724**Error codes**
2725
2726For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2727
2728| ID| Error Message|
2729| -------- | -------- |
2730| 1900010  | read data from message sequence failed |
2731
2732**Example**
2733
2734  ```ts
2735  // If the FA model is used, import featureAbility from @kit.AbilityKit.
2736  // import { featureAbility } from '@kit.AbilityKit';
2737  import { Want, common } from '@kit.AbilityKit';
2738  import { hilog } from '@kit.PerformanceAnalysisKit';
2739
2740  let proxy: rpc.IRemoteObject | undefined;
2741  let connect: common.ConnectOptions = {
2742    onConnect: (elementName, remoteProxy) => {
2743      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
2744      proxy = remoteProxy;
2745    },
2746    onDisconnect: (elementName) => {
2747      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
2748    },
2749    onFailed: () => {
2750      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
2751    }
2752  };
2753  let want: Want = {
2754    bundleName: "com.ohos.server",
2755    abilityName: "com.ohos.server.EntryAbility",
2756  };
2757
2758  // Use this method to connect to the ability for the FA model.
2759  // FA.connectAbility(want,connect);
2760
2761  // Save the connection ID, which will be used for the subsequent service disconnection.
2762  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
2763  // Save the connection ID, which will be used for the subsequent service disconnection.
2764  let connectionId = context.connectServiceExtensionAbility(want, connect);
2765  ```
2766
2767  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
2768
2769  ```ts
2770  import { BusinessError } from '@kit.BasicServicesKit';
2771  import { hilog } from '@kit.PerformanceAnalysisKit';
2772
2773  let option = new rpc.MessageOption();
2774  let data = rpc.MessageSequence.create();
2775  let reply = rpc.MessageSequence.create();
2776  data.writeNoException();
2777  data.writeInt(6);
2778  if (proxy != undefined) {
2779    proxy.sendMessageRequest(1, data, reply, option)
2780      .then((result: rpc.RequestResult) => {
2781        if (result.errCode === 0) {
2782          hilog.info(0x0000, 'testTag', 'sendMessageRequest got result');
2783          try {
2784            result.reply.readException();
2785          } catch (error) {
2786            let e: BusinessError = error as BusinessError;
2787            hilog.error(0x0000, 'testTag', 'rpc read exception fail, errorCode ' + e.code);
2788            hilog.error(0x0000, 'testTag', 'rpc read exception fail, errorMessage ' + e.message);
2789          }
2790          let num = result.reply.readInt();
2791          hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
2792        } else {
2793          hilog.error(0x0000, 'testTag', 'RPCTest: sendMessageRequest failed, errCode: ' + result.errCode);
2794        }
2795      }).catch((e: Error) => {
2796        hilog.error(0x0000, 'testTag', 'RPCTest: sendMessageRequest got exception: ' + e.message);
2797      }).finally (() => {
2798        hilog.info(0x0000, 'testTag', 'RPCTest: sendMessageRequest ends, reclaim parcel');
2799        data.reclaim();
2800        reply.reclaim();
2801      });
2802  }
2803  ```
2804
2805### writeParcelableArray
2806
2807writeParcelableArray(parcelableArray: Parcelable[]): void
2808
2809Writes a **Parcelable** array to this **MessageSequence** object.
2810
2811**System capability**: SystemCapability.Communication.IPC.Core
2812
2813**Parameters**
2814
2815| Name         | Type        | Mandatory| Description                      |
2816| --------------- | ------------ | ---- | -------------------------- |
2817| parcelableArray | [Parcelable](#parcelable9)[] | Yes  | **Parcelable** array to write.|
2818
2819**Error codes**
2820
2821For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2822
2823| ID| Error Message|
2824| -------- | -------- |
2825| 401      | check param failed |
2826| 1900009  | write data to message sequence failed |
2827
2828**Example**
2829
2830  ```ts
2831  import { hilog } from '@kit.PerformanceAnalysisKit';
2832  import { BusinessError } from '@kit.BasicServicesKit';
2833
2834  class MyParcelable implements rpc.Parcelable {
2835    num: number = 0;
2836    str: string = '';
2837    constructor(num: number, str: string) {
2838      this.num = num;
2839      this.str = str;
2840    }
2841    marshalling(messageSequence: rpc.MessageSequence): boolean {
2842      messageSequence.writeInt(this.num);
2843      messageSequence.writeString(this.str);
2844      return true;
2845    }
2846    unmarshalling(messageSequence: rpc.MessageSequence): boolean {
2847      this.num = messageSequence.readInt();
2848      this.str = messageSequence.readString();
2849      return true;
2850    }
2851  }
2852  let parcelable = new MyParcelable(1, "aaa");
2853  let parcelable2 = new MyParcelable(2, "bbb");
2854  let parcelable3 = new MyParcelable(3, "ccc");
2855  let a = [parcelable, parcelable2, parcelable3];
2856  let data = rpc.MessageSequence.create();
2857  try {
2858    data.writeParcelableArray(a);
2859  } catch (error) {
2860    let e: BusinessError = error as BusinessError;
2861    hilog.error(0x0000, 'testTag', 'rpc write parcelable array fail, errorCode ' + e.code);
2862    hilog.error(0x0000, 'testTag', 'rpc write parcelable array fail, errorMessage ' + e.message);
2863  }
2864  ```
2865
2866### readParcelableArray
2867
2868readParcelableArray(parcelableArray: Parcelable[]): void
2869
2870Reads a **Parcelable** array from this **MessageSequence** object.
2871
2872**System capability**: SystemCapability.Communication.IPC.Core
2873
2874**Parameters**
2875
2876| Name         | Type        | Mandatory| Description                      |
2877| --------------- | ------------ | ---- | -------------------------- |
2878| parcelableArray | [Parcelable](#parcelable9)[] | Yes  | **Parcelable** array to read.|
2879
2880**Error codes**
2881
2882For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2883
2884| ID| Error Message|
2885| -------- | -------- |
2886| 401      | check param failed |
2887| 1900010  | read data from message sequence failed |
2888| 1900012  | call js callback function failed |
2889
2890**Example**
2891
2892  ```ts
2893  import { hilog } from '@kit.PerformanceAnalysisKit';
2894  import { BusinessError } from '@kit.BasicServicesKit';
2895
2896  class MyParcelable implements rpc.Parcelable {
2897    num: number = 0;
2898    str: string = '';
2899    constructor(num: number, str: string) {
2900      this.num = num;
2901      this.str = str;
2902    }
2903    marshalling(messageSequence: rpc.MessageSequence): boolean {
2904      messageSequence.writeInt(this.num);
2905      messageSequence.writeString(this.str);
2906      return true;
2907    }
2908    unmarshalling(messageSequence: rpc.MessageSequence): boolean {
2909      this.num = messageSequence.readInt();
2910      this.str = messageSequence.readString();
2911      return true;
2912    }
2913  }
2914  let parcelable = new MyParcelable(1, "aaa");
2915  let parcelable2 = new MyParcelable(2, "bbb");
2916  let parcelable3 = new MyParcelable(3, "ccc");
2917  let a = [parcelable, parcelable2, parcelable3];
2918  let data = rpc.MessageSequence.create();
2919  data.writeParcelableArray(a);
2920  let b = [new MyParcelable(0, ""), new MyParcelable(0, ""), new MyParcelable(0, "")];
2921  try {
2922    data.readParcelableArray(b);
2923  } catch (error) {
2924    let e: BusinessError = error as BusinessError;
2925    hilog.error(0x0000, 'testTag', 'rpc read parcelable array fail, errorCode ' + e.code);
2926    hilog.error(0x0000, 'testTag', 'rpc read parcelable array fail, errorMessage ' + e.message);
2927  }
2928  ```
2929
2930### writeRemoteObjectArray
2931
2932writeRemoteObjectArray(objectArray: IRemoteObject[]): void
2933
2934Writes an array of **IRemoteObject** objects to this **MessageSequence** object.
2935
2936**System capability**: SystemCapability.Communication.IPC.Core
2937
2938**Parameters**
2939
2940| Name     | Type           | Mandatory| Description                                          |
2941| ----------- | --------------- | ---- | ---------------------------------------------- |
2942| objectArray | [IRemoteObject](#iremoteobject)[] | Yes  | Array of **IRemoteObject** objects to write.|
2943
2944**Error codes**
2945
2946For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2947
2948| ID| Error Message|
2949| -------- | -------- |
2950| 401      | check param failed |
2951| 1900009  | write data to message sequence failed |
2952
2953**Example**
2954
2955  ```ts
2956  import { hilog } from '@kit.PerformanceAnalysisKit';
2957  import { BusinessError } from '@kit.BasicServicesKit';
2958
2959  class TestRemoteObject extends rpc.RemoteObject {
2960    constructor(descriptor: string) {
2961      super(descriptor);
2962      this.modifyLocalInterface(this, descriptor);
2963    }
2964
2965    asObject(): rpc.IRemoteObject {
2966      return this;
2967    }
2968  }
2969  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
2970  let data = rpc.MessageSequence.create();
2971  try {
2972    data.writeRemoteObjectArray(a);
2973  } catch (error) {
2974    let e: BusinessError = error as BusinessError;
2975    hilog.error(0x0000, 'testTag', 'rpc write remote object array fail, errorCode ' + e.code);
2976    hilog.error(0x0000, 'testTag', 'rpc write remote object array fail, errorMessage ' + e.message);
2977  }
2978  ```
2979
2980### readRemoteObjectArray
2981
2982readRemoteObjectArray(objects: IRemoteObject[]): void
2983
2984Reads an array of **IRemoteObject** objects from this **MessageSequence** object.
2985
2986**System capability**: SystemCapability.Communication.IPC.Core
2987
2988**Parameters**
2989
2990| Name | Type           | Mandatory| Description                                          |
2991| ------- | --------------- | ---- | ---------------------------------------------- |
2992| objects | [IRemoteObject](#iremoteobject)[] | Yes  | **IRemoteObject** array to read.|
2993
2994**Error codes**
2995
2996For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
2997
2998| ID| Error Message|
2999| -------- | -------- |
3000| 401      | check param failed |
3001| 1900010  | read data from message sequence failed |
3002
3003**Example**
3004
3005  ```ts
3006  import { hilog } from '@kit.PerformanceAnalysisKit';
3007  import { BusinessError } from '@kit.BasicServicesKit';
3008
3009  class TestRemoteObject extends rpc.RemoteObject {
3010    constructor(descriptor: string) {
3011      super(descriptor);
3012      this.modifyLocalInterface(this, descriptor);
3013    }
3014
3015    asObject(): rpc.IRemoteObject {
3016      return this;
3017    }
3018  }
3019  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
3020  let data = rpc.MessageSequence.create();
3021  data.writeRemoteObjectArray(a);
3022  let b: Array<rpc.IRemoteObject> = new Array(3);
3023  try {
3024    data.readRemoteObjectArray(b);
3025  } catch (error) {
3026    let e: BusinessError = error as BusinessError;
3027    hilog.error(0x0000, 'testTag', 'rpc read remote object array fail, errorCode ' + e.code);
3028    hilog.error(0x0000, 'testTag', 'rpc read remote object array fail, errorMessage ' + e.message);
3029  }
3030  ```
3031
3032### readRemoteObjectArray
3033
3034readRemoteObjectArray(): IRemoteObject[]
3035
3036Reads the **IRemoteObject** object array from this **MessageSequence** object.
3037
3038**System capability**: SystemCapability.Communication.IPC.Core
3039
3040**Return value**
3041
3042| Type           | Description                       |
3043| --------------- | --------------------------- |
3044| [IRemoteObject](#iremoteobject)[] | **IRemoteObject** object array read.|
3045
3046**Error codes**
3047
3048For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3049
3050| ID| Error Message|
3051| -------- | -------- |
3052| 1900010  | read data from message sequence failed |
3053
3054**Example**
3055
3056  ```ts
3057  import { hilog } from '@kit.PerformanceAnalysisKit';
3058  import { BusinessError } from '@kit.BasicServicesKit';
3059
3060  class TestRemoteObject extends rpc.RemoteObject {
3061    constructor(descriptor: string) {
3062      super(descriptor);
3063      this.modifyLocalInterface(this, descriptor);
3064    }
3065
3066    asObject(): rpc.IRemoteObject {
3067      return this;
3068    }
3069  }
3070  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
3071  let data = rpc.MessageSequence.create();
3072  data.writeRemoteObjectArray(a);
3073  try {
3074    let b = data.readRemoteObjectArray();
3075    hilog.info(0x0000, 'testTag', 'RpcClient: readRemoteObjectArray is ' + b);
3076  } catch (error) {
3077    let e: BusinessError = error as BusinessError;
3078    hilog.error(0x0000, 'testTag', 'rpc read remote object array fail, errorCode ' + e.code);
3079    hilog.error(0x0000, 'testTag', 'rpc read remote object array fail, errorMessage ' + e.message);
3080  }
3081  ```
3082
3083### closeFileDescriptor
3084
3085static closeFileDescriptor(fd: number): void
3086
3087Closes a file descriptor. This API is a static method.
3088
3089**System capability**: SystemCapability.Communication.IPC.Core
3090
3091**Parameters**
3092
3093| Name| Type  | Mandatory| Description                |
3094| ------ | ------ | ---- | -------------------- |
3095| fd     | number | Yes  | File descriptor to close.|
3096
3097**Error codes**
3098
3099For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3100
3101| ID| Error Message|
3102| -------- | -------- |
3103| 401      | check param failed |
3104
3105**Example**
3106
3107  ```ts
3108  import { fileIo } from '@kit.CoreFileKit';
3109  import { hilog } from '@kit.PerformanceAnalysisKit';
3110  import { BusinessError } from '@kit.BasicServicesKit';
3111
3112  let filePath = "path/to/file";
3113  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
3114  try {
3115    rpc.MessageSequence.closeFileDescriptor(file.fd);
3116  } catch (error) {
3117    let e: BusinessError = error as BusinessError;
3118    hilog.error(0x0000, 'testTag', 'rpc close file descriptor fail, errorCode ' + e.code);
3119    hilog.error(0x0000, 'testTag', 'rpc close file descriptor fail, errorMessage ' + e.message);
3120  }
3121  ```
3122
3123### dupFileDescriptor
3124
3125static dupFileDescriptor(fd: number): number
3126
3127Duplicates a file descriptor. This API is a static method.
3128
3129**System capability**: SystemCapability.Communication.IPC.Core
3130
3131**Parameters**
3132
3133| Name| Type  | Mandatory| Description                    |
3134| ------ | ------ | ---- | ------------------------ |
3135| fd     | number | Yes  | File descriptor to duplicate.|
3136
3137**Return value**
3138
3139| Type  | Description                |
3140| ------ | -------------------- |
3141| number | New file descriptor.|
3142
3143**Error codes**
3144
3145For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3146
3147| ID| Error Message|
3148| -------- | -------- |
3149| 401      | check param failed |
3150| 1900013  | call os dup function failed |
3151
3152**Example**
3153
3154  ```ts
3155  import { fileIo } from '@kit.CoreFileKit';
3156  import { hilog } from '@kit.PerformanceAnalysisKit';
3157  import { BusinessError } from '@kit.BasicServicesKit';
3158
3159  let filePath = "path/to/file";
3160  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
3161  try {
3162    rpc.MessageSequence.dupFileDescriptor(file.fd);
3163  } catch (error) {
3164    let e: BusinessError = error as BusinessError;
3165    hilog.error(0x0000, 'testTag', 'rpc dup file descriptor fail, errorCode ' + e.code);
3166    hilog.error(0x0000, 'testTag', 'rpc dup file descriptor fail, errorMessage ' + e.message);
3167  }
3168  ```
3169
3170### containFileDescriptors
3171
3172containFileDescriptors(): boolean
3173
3174Checks whether this **MessageSequence** object contains file descriptors.
3175
3176**System capability**: SystemCapability.Communication.IPC.Core
3177
3178**Return value**
3179
3180| Type   | Description                                                                |
3181| ------- | -------------------------------------------------------------------- |
3182| boolean | Returns **true** if the **MessageSequence** object contains file descriptors; returns **false** otherwise.|
3183
3184**Example**
3185
3186  ```ts
3187  import { fileIo } from '@kit.CoreFileKit';
3188  import { hilog } from '@kit.PerformanceAnalysisKit';
3189  import { BusinessError } from '@kit.BasicServicesKit';
3190
3191  let sequence = new rpc.MessageSequence();
3192  let filePath = "path/to/file";
3193  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
3194  try {
3195    sequence.writeFileDescriptor(file.fd);
3196  } catch (error) {
3197    let e: BusinessError = error as BusinessError;
3198    hilog.error(0x0000, 'testTag', 'rpc write file descriptor fail, errorCode ' + e.code);
3199    hilog.error(0x0000, 'testTag', 'rpc write file descriptor fail, errorMessage ' + e.message);
3200  }
3201  try {
3202    let containFD = sequence.containFileDescriptors();
3203    hilog.info(0x0000, 'testTag', 'RpcTest: sequence after write fd containFd result is ' + containFD);
3204  } catch (error) {
3205    let e: BusinessError = error as BusinessError;
3206    hilog.error(0x0000, 'testTag', 'rpc contain file descriptor fail, errorCode ' + e.code);
3207    hilog.error(0x0000, 'testTag', 'rpc contain file descriptor fail, errorMessage ' + e.message);
3208  }
3209  ```
3210
3211### writeFileDescriptor
3212
3213writeFileDescriptor(fd: number): void
3214
3215Writes a file descriptor to this **MessageSequence** object.
3216
3217**System capability**: SystemCapability.Communication.IPC.Core
3218
3219**Parameters**
3220
3221| Name| Type  | Mandatory| Description        |
3222| ------ | ------ | ---- | ------------ |
3223| fd     | number | Yes  | File descriptor to write.|
3224
3225**Error codes**
3226
3227For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3228
3229| ID| Error Message|
3230| -------- | -------- |
3231| 401      | check param failed |
3232| 1900009  | write data to message sequence failed |
3233
3234**Example**
3235
3236  ```ts
3237  import { fileIo } from '@kit.CoreFileKit';
3238  import { hilog } from '@kit.PerformanceAnalysisKit';
3239  import { BusinessError } from '@kit.BasicServicesKit';
3240
3241  let sequence = new rpc.MessageSequence();
3242  let filePath = "path/to/file";
3243  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
3244  try {
3245    sequence.writeFileDescriptor(file.fd);
3246  } catch (error) {
3247    let e: BusinessError = error as BusinessError;
3248    hilog.error(0x0000, 'testTag', 'rpc write file descriptor fail, errorCode ' + e.code);
3249    hilog.error(0x0000, 'testTag', 'rpc write file descriptor fail, errorMessage ' + e.message);
3250  }
3251  ```
3252
3253### readFileDescriptor
3254
3255readFileDescriptor(): number
3256
3257Reads the file descriptor from this **MessageSequence** object.
3258
3259**System capability**: SystemCapability.Communication.IPC.Core
3260
3261**Return value**
3262
3263| Type  | Description            |
3264| ------ | ---------------- |
3265| number | File descriptor read.|
3266
3267**Error codes**
3268
3269For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3270
3271| ID| Error Message|
3272| -------- | -------- |
3273| 1900010  | read data from message sequence failed |
3274
3275**Example**
3276
3277  ```ts
3278  import { fileIo } from '@kit.CoreFileKit';
3279  import { hilog } from '@kit.PerformanceAnalysisKit';
3280  import { BusinessError } from '@kit.BasicServicesKit';
3281
3282  let sequence = new rpc.MessageSequence();
3283  let filePath = "path/to/file";
3284  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
3285  try {
3286    sequence.writeFileDescriptor(file.fd);
3287  } catch (error) {
3288    let e: BusinessError = error as BusinessError;
3289    hilog.error(0x0000, 'testTag', 'rpc write file descriptor fail, errorCode ' + e.code);
3290    hilog.error(0x0000, 'testTag', 'rpc write file descriptor fail, errorMessage ' + e.message);
3291  }
3292  try {
3293    let readFD = sequence.readFileDescriptor();
3294    hilog.info(0x0000, 'testTag', 'RpcClient: readFileDescriptor is ' + readFD);
3295  } catch (error) {
3296    let e: BusinessError = error as BusinessError;
3297    hilog.error(0x0000, 'testTag', 'rpc read file descriptor fail, errorCode ' + e.code);
3298    hilog.error(0x0000, 'testTag', 'rpc read file descriptor fail, errorMessage ' + e.message);
3299  }
3300  ```
3301
3302### writeAshmem
3303
3304writeAshmem(ashmem: Ashmem): void
3305
3306Writes an anonymous shared object to this **MessageSequence** object.
3307
3308**System capability**: SystemCapability.Communication.IPC.Core
3309
3310**Parameters**
3311
3312| Name| Type  | Mandatory| Description                                 |
3313| ------ | ------ | ---- | ------------------------------------- |
3314| ashmem | [Ashmem](#ashmem8) | Yes  | Anonymous shared object to write.|
3315
3316**Error codes**
3317
3318For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3319
3320| ID| Error Message|
3321| -------- | ------- |
3322| 401      | check param failed |
3323| 1900003  | write to ashmem failed |
3324
3325**Example**
3326
3327  ```ts
3328  import { hilog } from '@kit.PerformanceAnalysisKit';
3329  import { BusinessError } from '@kit.BasicServicesKit';
3330
3331  let sequence = new rpc.MessageSequence();
3332  let ashmem: rpc.Ashmem | undefined = undefined;
3333  try {
3334    ashmem = rpc.Ashmem.create("ashmem", 1024);
3335    try {
3336      sequence.writeAshmem(ashmem);
3337    } catch (error) {
3338      let e: BusinessError = error as BusinessError;
3339      hilog.error(0x0000, 'testTag', 'rpc write ashmem fail, errorCode ' + e.code);
3340      hilog.error(0x0000, 'testTag', 'rpc write ashmem fail, errorMessage ' + e.message);
3341    }
3342  } catch (error) {
3343    let e: BusinessError = error as BusinessError;
3344    hilog.error(0x0000, 'testTag', 'rpc create ashmem fail, errorCode ' + e.code);
3345    hilog.error(0x0000, 'testTag', 'rpc create ashmem fail, errorMessage ' + e.message);
3346  }
3347  ```
3348
3349### readAshmem
3350
3351readAshmem(): Ashmem
3352
3353Reads the anonymous shared object from this **MessageSequence** object.
3354
3355**System capability**: SystemCapability.Communication.IPC.Core
3356
3357**Return value**
3358
3359| Type  | Description              |
3360| ------ | ------------------ |
3361| [Ashmem](#ashmem8) | Anonymous share object obtained.|
3362
3363**Error codes**
3364
3365For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3366
3367| ID| Error Message|
3368| -------- | -------- |
3369| 401      | check param failed |
3370| 1900004  | read from ashmem failed |
3371
3372**Example**
3373
3374  ```ts
3375  import { hilog } from '@kit.PerformanceAnalysisKit';
3376  import { BusinessError } from '@kit.BasicServicesKit';
3377
3378  let sequence = new rpc.MessageSequence();
3379  let ashmem: rpc.Ashmem | undefined = undefined;
3380  try {
3381    ashmem = rpc.Ashmem.create("ashmem", 1024);
3382    try {
3383      sequence.writeAshmem(ashmem);
3384    } catch (error) {
3385      let e: BusinessError = error as BusinessError;
3386      hilog.error(0x0000, 'testTag', 'rpc write ashmem fail, errorCode ' + e.code);
3387      hilog.error(0x0000, 'testTag', 'rpc write ashmem fail, errorMessage ' + e.message);
3388    }
3389  } catch (error) {
3390    let e: BusinessError = error as BusinessError;
3391    hilog.error(0x0000, 'testTag', 'rpc create ashmem fail, errorCode ' + e.code);
3392    hilog.error(0x0000, 'testTag', 'rpc create ashmem fail, errorMessage ' + e.message);
3393  }
3394  try {
3395    sequence.readAshmem();
3396  } catch (error) {
3397    let e: BusinessError = error as BusinessError;
3398    hilog.error(0x0000, 'testTag', 'rpc read ashmem fail, errorCode ' + e.code);
3399    hilog.error(0x0000, 'testTag', 'rpc read ashmem fail, errorMessage ' + e.message);
3400  }
3401  ```
3402
3403### getRawDataCapacity
3404
3405getRawDataCapacity(): number
3406
3407Obtains the maximum amount of raw data that can be held by this **MessageSequence** object.
3408
3409**System capability**: SystemCapability.Communication.IPC.Core
3410
3411**Return value**
3412
3413| Type  | Description                                                        |
3414| ------ | ------------------------------------------------------------ |
3415| number | Maximum amount of raw data that **MessageSequence** can hold, that is, 128 MB.|
3416
3417**Example**
3418
3419  ```ts
3420  import { hilog } from '@kit.PerformanceAnalysisKit';
3421
3422  let sequence = new rpc.MessageSequence();
3423  let result = sequence.getRawDataCapacity();
3424  hilog.info(0x0000, 'testTag', 'RpcTest: sequence get RawDataCapacity result is ' + result);
3425  ```
3426
3427### writeRawData<sup>(deprecated)</sup>
3428
3429>**NOTE**<br>This API is no longer maintained since API version 11. Use [writeRawDataBuffer](#writerawdatabuffer11) instead.
3430
3431writeRawData(rawData: number[], size: number): void
3432
3433Writes raw data to this **MessageSequence** object.
3434
3435**System capability**: SystemCapability.Communication.IPC.Core
3436
3437**Parameters**
3438
3439| Name | Type    | Mandatory| Description                              |
3440| ------- | -------- | ---- | ---------------------------------- |
3441| rawData | number[] | Yes  | Raw data to write.                |
3442| size    | number   | Yes  | Size of the raw data, in bytes.|
3443
3444**Error codes**
3445
3446For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3447
3448| ID| Error Message|
3449| -------- | -------- |
3450| 401      | check param failed |
3451| 1900009  | write data to message sequence failed |
3452
3453**Example**
3454
3455  ```ts
3456  import { hilog } from '@kit.PerformanceAnalysisKit';
3457  import { BusinessError } from '@kit.BasicServicesKit';
3458
3459  let sequence = new rpc.MessageSequence();
3460  let arr = [1, 2, 3, 4, 5];
3461  try {
3462    sequence.writeRawData(arr, arr.length);
3463  } catch (error) {
3464    let e: BusinessError = error as BusinessError;
3465    hilog.error(0x0000, 'testTag', 'rpc write rawdata fail, errorCode ' + e.code);
3466    hilog.error(0x0000, 'testTag', 'rpc write rawdata fail, errorMessage ' + e.message);
3467  }
3468  ```
3469
3470### writeRawDataBuffer<sup>11+</sup>
3471
3472writeRawDataBuffer(rawData: ArrayBuffer, size: number): void
3473
3474Writes raw data to this **MessageSequence** object.
3475
3476**System capability**: SystemCapability.Communication.IPC.Core
3477
3478**Parameters**
3479
3480| Name | Type    | Mandatory| Description                              |
3481| ------- | -------- | ---- | ---------------------------------- |
3482| rawData | ArrayBuffer | Yes  | Raw data to write.                |
3483| size    | number   | Yes  | Size of the raw data, in bytes.|
3484
3485**Error codes**
3486
3487For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3488
3489| ID| Error Message|
3490| -------- | -------- |
3491| 401      | check param failed |
3492| 1900009  | write data to message sequence failed |
3493
3494**Example**
3495
3496  ```ts
3497  import { hilog } from '@kit.PerformanceAnalysisKit';
3498  import { BusinessError } from '@kit.BasicServicesKit';
3499
3500  let buffer = new ArrayBuffer(64 * 1024);
3501  let int32View = new Int32Array(buffer);
3502  for (let i = 0; i < int32View.length; i++) {
3503    int32View[i] = i * 2 + 1;
3504  }
3505  let size = buffer.byteLength;
3506  let sequence = new rpc.MessageSequence();
3507  try {
3508    sequence.writeRawDataBuffer(buffer, size);
3509  } catch (error) {
3510    let e: BusinessError = error as BusinessError;
3511    hilog.error(0x0000, 'testTag', 'rpc write rawdata fail, errorCode ' + e.code);
3512    hilog.error(0x0000, 'testTag', 'rpc write rawdata fail, errorMessage ' + e.message);
3513  }
3514  ```
3515
3516### readRawData<sup>(deprecated)</sup>
3517
3518>**NOTE**<br>This API is no longer maintained since API version 11. Use [readRawDataBuffer](#readrawdatabuffer11) instead.
3519
3520readRawData(size: number): number[]
3521
3522Reads raw data from this **MessageSequence** object.
3523
3524**System capability**: SystemCapability.Communication.IPC.Core
3525
3526**Parameters**
3527
3528| Name| Type  | Mandatory| Description                    |
3529| ------ | ------ | ---- | ------------------------ |
3530| size   | number | Yes  | Size of the raw data to read.|
3531
3532**Return value**
3533
3534| Type    | Description                          |
3535| -------- | ------------------------------ |
3536| number[] | Raw data obtained, in bytes.|
3537
3538**Error codes**
3539
3540For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3541
3542| ID| Error Message|
3543| -------- | -------- |
3544| 401      | check param failed |
3545| 1900010  | read data from message sequence failed |
3546
3547**Example**
3548
3549  ```ts
3550  import { hilog } from '@kit.PerformanceAnalysisKit';
3551  import { BusinessError } from '@kit.BasicServicesKit';
3552
3553  let sequence = new rpc.MessageSequence();
3554  let arr = [1, 2, 3, 4, 5];
3555  try {
3556    sequence.writeRawData(arr, arr.length);
3557  } catch (error) {
3558    let e: BusinessError = error as BusinessError;
3559    hilog.error(0x0000, 'testTag', 'rpc write rawdata fail, errorCode ' + e.code);
3560    hilog.error(0x0000, 'testTag', 'rpc write rawdata fail, errorMessage ' + e.message);
3561  }
3562  try {
3563    let result = sequence.readRawData(5);
3564    hilog.info(0x0000, 'testTag', 'RpcTest: sequence read raw data result is ' + result);
3565  } catch (error) {
3566    let e: BusinessError = error as BusinessError;
3567    hilog.error(0x0000, 'testTag', 'rpc read rawdata fail, errorCode ' + e.code);
3568    hilog.error(0x0000, 'testTag', 'rpc read rawdata fail, errorMessage ' + e.message);
3569  }
3570  ```
3571
3572### readRawDataBuffer<sup>11+</sup>
3573
3574readRawDataBuffer(size: number): ArrayBuffer
3575
3576Reads raw data from this **MessageSequence** object.
3577
3578**System capability**: SystemCapability.Communication.IPC.Core
3579
3580**Parameters**
3581
3582| Name| Type  | Mandatory| Description                    |
3583| ------ | ------ | ---- | ------------------------ |
3584| size   | number | Yes  | Size of the raw data to read.|
3585
3586**Return value**
3587
3588| Type    | Description                          |
3589| -------- | ------------------------------ |
3590| ArrayBuffer | Raw data obtained, in bytes.|
3591
3592**Error codes**
3593
3594For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3595
3596| ID| Error Message|
3597| -------- | -------- |
3598| 401      | check param failed |
3599| 1900010  | read data from message sequence failed |
3600
3601**Example**
3602
3603  ```ts
3604  import { hilog } from '@kit.PerformanceAnalysisKit';
3605  import { BusinessError } from '@kit.BasicServicesKit';
3606
3607  let buffer = new ArrayBuffer(64 * 1024);
3608  let int32View = new Int32Array(buffer);
3609  for (let i = 0; i < int32View.length; i++) {
3610    int32View[i] = i * 2 + 1;
3611  }
3612  let size = buffer.byteLength;
3613  let sequence = new rpc.MessageSequence();
3614  try {
3615    sequence.writeRawDataBuffer(buffer, size);
3616  } catch (error) {
3617    let e: BusinessError = error as BusinessError;
3618    hilog.error(0x0000, 'testTag', 'rpc write rawdata fail, errorCode ' + e.code);
3619    hilog.error(0x0000, 'testTag', 'rpc write rawdata fail, errorMessage ' + e.message);
3620  }
3621  try {
3622    let result = sequence.readRawDataBuffer(size);
3623    let readInt32View = new Int32Array(result);
3624    hilog.info(0x0000, 'testTag', 'RpcTest: sequence read raw data result is ' + readInt32View);
3625  } catch (error) {
3626    let e: BusinessError = error as BusinessError;
3627    hilog.error(0x0000, 'testTag', 'rpc read rawdata fail, errorCode ' + e.code);
3628    hilog.error(0x0000, 'testTag', 'rpc read rawdata fail, errorMessage ' + e.message);
3629  }
3630  ```
3631
3632### writeArrayBuffer<sup>12+</sup>
3633
3634writeArrayBuffer(buf: ArrayBuffer, typeCode: TypeCode): void
3635
3636Writes data of the ArrayBuffer type to this **MessageSequence** object.
3637
3638**System capability**: SystemCapability.Communication.IPC.Core
3639
3640**Parameters**
3641
3642| Name   | Type                     | Mandatory| Description                       |
3643| --------- | ------------------------- | ---- | --------------------------- |
3644| buf       | ArrayBuffer               | Yes  | Data to write.  |
3645| typeCode  | [TypeCode](#typecode12)   | Yes  | TypedArray type of the ArrayBuffer data.<br>The underlying write mode is determined based on the enum value of **TypeCode** passed by the service.|
3646
3647**Error codes**
3648
3649For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3650
3651| ID| Error Message|
3652| -------- | -------- |
3653| 401      | check param failed |
3654| 1900009  | write data to message sequence failed |
3655
3656**Example**
3657
3658  ```ts
3659  // In this example, the value of TypeCode is Int16Array.
3660  import { hilog } from '@kit.PerformanceAnalysisKit';
3661  import { BusinessError } from '@kit.BasicServicesKit';
3662  
3663  const data = rpc.MessageSequence.create();
3664
3665  let buffer = new ArrayBuffer(10);
3666  let int16View = new Int16Array(buffer);
3667  for (let i = 0; i < int16View.length; i++) {
3668    int16View[i] = i * 2 + 1;
3669  }
3670
3671  try {
3672    data.writeArrayBuffer(buffer, rpc.TypeCode.INT16_ARRAY);
3673  } catch (error) {
3674    let e: BusinessError = error as BusinessError;
3675    hilog.error(0x0000, 'testTag', 'rpc write ArrayBuffe fail, errorCode ' + e.code);
3676    hilog.error(0x0000, 'testTag', 'rpc write ArrayBuffe fail, errorMessage ' + e.message);
3677  }
3678  ```
3679
3680### readArrayBuffer<sup>12+</sup>
3681
3682readArrayBuffer(typeCode: TypeCode): ArrayBuffer
3683
3684Reads data of the ArrayBuffer type from this **MessageSequence**.
3685
3686**System capability**: SystemCapability.Communication.IPC.Core
3687
3688**Parameters**
3689
3690| Name  | Type                    | Mandatory| Description                  |
3691| -------- | ----------------------- | ---- | ------------------------|
3692| typeCode | [TypeCode](#typecode12) | Yes  | TypedArray type of the ArrayBuffer data.<br>The underlying read mode is determined based on the enum value of **TypeCode** passed by the service. |
3693
3694**Return value**
3695
3696| Type    | Description                                        |
3697| -------- | -------------------------------------------- |
3698| ArrayBuffer | Data of the ArrayBuffer type read, in bytes.|
3699
3700**Error codes**
3701
3702For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
3703
3704| ID| Error Message|
3705| -------- | -------- |
3706| 401      | check param failed |
3707| 1900010  | read data from message sequence failed |
3708
3709**Example**
3710
3711  ```ts
3712  // In this example, the value of TypeCode is Int16Array.
3713  import { hilog } from '@kit.PerformanceAnalysisKit';
3714  import { BusinessError } from '@kit.BasicServicesKit';
3715  
3716  const data = rpc.MessageSequence.create();
3717
3718  let buffer = new ArrayBuffer(10);
3719  let int16View = new Int16Array(buffer);
3720  for (let i = 0; i < int16View.length; i++) {
3721    int16View[i] = i * 2 + 1;
3722  }
3723
3724  try {
3725    data.writeArrayBuffer(buffer, rpc.TypeCode.INT16_ARRAY);
3726  } catch (error) {
3727    let e: BusinessError = error as BusinessError;
3728    hilog.error(0x0000, 'testTag', 'rpc write ArrayBuffe fail, errorCode ' + e.code);
3729    hilog.error(0x0000, 'testTag', 'rpc write ArrayBuffe fail, errorMessage ' + e.message);
3730  }
3731  try {
3732    let result = data.readArrayBuffer(rpc.TypeCode.INT16_ARRAY);
3733    let readInt16View = new Int16Array(result);
3734    hilog.info(0x0000, 'testTag', 'RpcTest: read ArrayBuffer result is ' + readInt16View);
3735  } catch (error) {
3736    let e: BusinessError = error as BusinessError;
3737    hilog.error(0x0000, 'testTag', 'rpc read ArrayBuffer fail, errorCode ' + e.code);
3738    hilog.error(0x0000, 'testTag', 'rpc read ArrayBuffer fail, errorMessage ' + e.message);
3739  }
3740  ```
3741
3742## MessageParcel<sup>(deprecated)</sup>
3743
3744>**NOTE**<br>This class is no longer maintained since API version 9. Use [MessageSequence](#messagesequence9) instead.
3745
3746Provides APIs for reading and writing data in specific format. During RPC, the sender can use the **write()** method provided by **MessageParcel** to write data in specific format to a **MessageParcel** object. The receiver can use the **read()** method provided by **MessageParcel** to read data in specific format from a **MessageParcel** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.
3747
3748### create
3749
3750static create(): MessageParcel
3751
3752Creates a **MessageParcel** object. This method is a static method.
3753
3754**System capability**: SystemCapability.Communication.IPC.Core
3755
3756**Return value**
3757
3758| Type         | Description                         |
3759| ------------- | ----------------------------- |
3760| [MessageParcel](#messageparceldeprecated) | **MessageParcel** object created.|
3761
3762**Example**
3763
3764  ```ts
3765  import { hilog } from '@kit.PerformanceAnalysisKit';
3766
3767  let data = rpc.MessageParcel.create();
3768  hilog.info(0x0000, 'testTag', 'RpcClient: data is ' + data);
3769  ```
3770
3771### reclaim
3772
3773reclaim(): void
3774
3775Reclaims the **MessageParcel** object that is no longer used.
3776
3777**System capability**: SystemCapability.Communication.IPC.Core
3778
3779**Example**
3780
3781  ```ts
3782  let reply = rpc.MessageParcel.create();
3783  reply.reclaim();
3784  ```
3785
3786### writeRemoteObject
3787
3788writeRemoteObject(object: IRemoteObject): boolean
3789
3790Serializes a remote object and writes it to this **MessageParcel** object.
3791
3792**System capability**: SystemCapability.Communication.IPC.Core
3793
3794**Parameters**
3795
3796| Name| Type                           | Mandatory| Description                                   |
3797| ------ | ------------------------------- | ---- | --------------------------------------- |
3798| object | [IRemoteObject](#iremoteobject) | Yes  | Remote object to serialize and write to the **MessageParcel** object.|
3799
3800**Return value**
3801
3802| Type   | Description                                     |
3803| ------- | ----------------------------------------- |
3804| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3805
3806**Example**
3807
3808  ```ts
3809  import { hilog } from '@kit.PerformanceAnalysisKit';
3810
3811  class MyDeathRecipient implements rpc.DeathRecipient {
3812    onRemoteDied() {
3813      hilog.info(0x0000, 'testTag', 'server died');
3814    }
3815  }
3816  class TestRemoteObject extends rpc.RemoteObject {
3817    constructor(descriptor: string) {
3818      super(descriptor);
3819    }
3820    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
3821      return true;
3822    }
3823    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
3824      return true;
3825    }
3826    isObjectDead(): boolean {
3827      return false;
3828    }
3829  }
3830  let data = rpc.MessageParcel.create();
3831  let testRemoteObject = new TestRemoteObject("testObject");
3832  data.writeRemoteObject(testRemoteObject);
3833  ```
3834
3835### readRemoteObject
3836
3837readRemoteObject(): IRemoteObject
3838
3839Reads the remote object from this **MessageParcel** object. You can use this method to deserialize the **MessageParcel** object to generate an **IRemoteObject**. The remote objects are read in the order in which they are written to this **MessageParcel** object.
3840
3841**System capability**: SystemCapability.Communication.IPC.Core
3842
3843**Return value**
3844
3845| Type                           | Description              |
3846| ------------------------------- | ------------------ |
3847| [IRemoteObject](#iremoteobject) | Remote object obtained.|
3848
3849**Example**
3850
3851  ```ts
3852  import { hilog } from '@kit.PerformanceAnalysisKit';
3853
3854  class MyDeathRecipient implements rpc.DeathRecipient {
3855    onRemoteDied() {
3856      hilog.info(0x0000, 'testTag', 'server died');
3857    }
3858  }
3859  class TestRemoteObject extends rpc.RemoteObject {
3860    constructor(descriptor: string) {
3861      super(descriptor);
3862    }
3863    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
3864      return true;
3865    }
3866    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
3867      return true;
3868    }
3869    isObjectDead(): boolean {
3870      return false;
3871    }
3872  }
3873  let data = rpc.MessageParcel.create();
3874  let testRemoteObject = new TestRemoteObject("testObject");
3875  data.writeRemoteObject(testRemoteObject);
3876  let proxy = data.readRemoteObject();
3877  hilog.info(0x0000, 'testTag', 'readRemoteObject is ' + proxy);
3878  ```
3879
3880### writeInterfaceToken
3881
3882writeInterfaceToken(token: string): boolean
3883
3884Writes an interface token to this **MessageParcel** object. The remote object can use this interface token to verify the communication.
3885
3886**System capability**: SystemCapability.Communication.IPC.Core
3887
3888**Parameters**
3889
3890| Name| Type  | Mandatory| Description              |
3891| ------ | ------ | ---- | ------------------ |
3892| token  | string | Yes  | Interface token to write.|
3893
3894**Return value**
3895
3896| Type   | Description                                     |
3897| ------- | ----------------------------------------- |
3898| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3899
3900**Example**
3901
3902  ```ts
3903  import { hilog } from '@kit.PerformanceAnalysisKit';
3904
3905  let data = rpc.MessageParcel.create();
3906  let result = data.writeInterfaceToken("aaa");
3907  hilog.info(0x0000, 'testTag', 'RpcServer: writeInterfaceToken is ' + result);
3908  ```
3909
3910### readInterfaceToken
3911
3912readInterfaceToken(): string
3913
3914Reads the interface token from this **MessageParcel** object. The interface token is read in the sequence in which it is written to the **MessageParcel** object. The local object can use it to verify the communication.
3915
3916**System capability**: SystemCapability.Communication.IPC.Core
3917
3918**Return value**
3919
3920| Type  | Description                    |
3921| ------ | ------------------------ |
3922| string | Interface token obtained.|
3923
3924**Example**
3925
3926  ```ts
3927  import { hilog } from '@kit.PerformanceAnalysisKit';
3928
3929  class Stub extends rpc.RemoteObject {
3930    onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, option: rpc.MessageOption): boolean {
3931      let interfaceToken = data.readInterfaceToken();
3932      hilog.info(0x0000, 'testTag', 'RpcServer: interfaceToken is ' + interfaceToken);
3933      return true;
3934    }
3935  }
3936  ```
3937
3938### getSize
3939
3940getSize(): number
3941
3942Obtains the data size of this **MessageParcel** object.
3943
3944**System capability**: SystemCapability.Communication.IPC.Core
3945
3946**Return value**
3947
3948| Type  | Description                                         |
3949| ------ | --------------------------------------------- |
3950| number | Size of the **MessageParcel** object obtained, in bytes.|
3951
3952**Example**
3953
3954  ```ts
3955  import { hilog } from '@kit.PerformanceAnalysisKit';
3956
3957  let data = rpc.MessageParcel.create();
3958  let size = data.getSize();
3959  hilog.info(0x0000, 'testTag', 'RpcClient: size is ' + size);
3960  ```
3961
3962### getCapacity
3963
3964getCapacity(): number
3965
3966Obtains the capacity of this **MessageParcel** object.
3967
3968**System capability**: SystemCapability.Communication.IPC.Core
3969
3970**Return value**
3971
3972| Type  | Description                                         |
3973| ------ | --------------------------------------------- |
3974| number | **MessageParcel** capacity obtained, in bytes.|
3975
3976**Example**
3977
3978  ```ts
3979  import { hilog } from '@kit.PerformanceAnalysisKit';
3980
3981  let data = rpc.MessageParcel.create();
3982  let result = data.getCapacity();
3983  hilog.info(0x0000, 'testTag', 'RpcClient: capacity is ' + result);
3984  ```
3985
3986### setSize
3987
3988setSize(size: number): boolean
3989
3990Sets the size of data contained in this **MessageParcel** object.
3991
3992**System capability**: SystemCapability.Communication.IPC.Core
3993
3994**Parameters**
3995
3996| Name| Type  | Mandatory| Description                                       |
3997| ------ | ------ | ---- | ------------------------------------------- |
3998| size   | number | Yes  | Data size to set, in bytes.|
3999
4000**Return value**
4001
4002| Type   | Description                             |
4003| ------- | --------------------------------- |
4004| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
4005
4006**Example**
4007
4008  ```ts
4009  import { hilog } from '@kit.PerformanceAnalysisKit';
4010
4011  let data = rpc.MessageParcel.create();
4012  let setSize = data.setSize(16);
4013  hilog.info(0x0000, 'testTag', 'RpcClient: setSize is ' + setSize);
4014  ```
4015
4016### setCapacity
4017
4018setCapacity(size: number): boolean
4019
4020Sets the storage capacity of this **MessageParcel** object.
4021
4022**System capability**: SystemCapability.Communication.IPC.Core
4023
4024**Parameters**
4025
4026| Name| Type  | Mandatory| Description                                       |
4027| ------ | ------ | ---- | ------------------------------------------- |
4028| size   | number | Yes  | Storage capacity to set, in bytes.|
4029
4030**Return value**
4031
4032| Type   | Description                             |
4033| ------- | --------------------------------- |
4034| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
4035
4036**Example**
4037
4038  ```ts
4039  import { hilog } from '@kit.PerformanceAnalysisKit';
4040
4041  let data = rpc.MessageParcel.create();
4042  let result = data.setCapacity(100);
4043  hilog.info(0x0000, 'testTag', 'RpcClient: setCapacity is ' + result);
4044  ```
4045
4046### getWritableBytes
4047
4048getWritableBytes(): number
4049
4050Obtains the writable capacity of this **MessageParcel** object.
4051
4052**System capability**: SystemCapability.Communication.IPC.Core
4053
4054**Return value**
4055
4056| Type  | Description                                               |
4057| ------ | --------------------------------------------------- |
4058| number | **MessageParcel** writable capacity obtained, in bytes.|
4059
4060**Example**
4061
4062  ```ts
4063  import { hilog } from '@kit.PerformanceAnalysisKit';
4064
4065  class Stub extends rpc.RemoteObject {
4066    onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, option: rpc.MessageOption): boolean {
4067      let getWritableBytes = data.getWritableBytes();
4068      hilog.info(0x0000, 'testTag', 'RpcServer: getWritableBytes is ' + getWritableBytes);
4069      return true;
4070    }
4071  }
4072  ```
4073
4074### getReadableBytes
4075
4076getReadableBytes(): number
4077
4078Obtains the readable capacity of this **MessageParcel** object.
4079
4080**System capability**: SystemCapability.Communication.IPC.Core
4081
4082**Return value**
4083
4084| Type  | Description                                               |
4085| ------ | --------------------------------------------------- |
4086| number | **MessageParcel** object readable capacity, in bytes.|
4087
4088**Example**
4089
4090  ```ts
4091  import { hilog } from '@kit.PerformanceAnalysisKit';
4092
4093  class Stub extends rpc.RemoteObject {
4094    onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, option: rpc.MessageOption): boolean {
4095      let result = data.getReadableBytes();
4096      hilog.info(0x0000, 'testTag', 'RpcServer: getReadableBytes is ' + result);
4097      return true;
4098    }
4099  }
4100  ```
4101
4102### getReadPosition
4103
4104getReadPosition(): number
4105
4106Obtains the read position of this **MessageParcel** object.
4107
4108**System capability**: SystemCapability.Communication.IPC.Core
4109
4110**Return value**
4111
4112| Type  | Description                                   |
4113| ------ | --------------------------------------- |
4114| number | Current read position of the **MessageParcel** object.|
4115
4116**Example**
4117
4118  ```ts
4119  import { hilog } from '@kit.PerformanceAnalysisKit';
4120
4121  let data = rpc.MessageParcel.create();
4122  let readPos = data.getReadPosition();
4123  hilog.info(0x0000, 'testTag', 'RpcClient: readPos is ' + readPos);
4124  ```
4125
4126### getWritePosition
4127
4128getWritePosition(): number
4129
4130Obtains the write position of this **MessageParcel** object.
4131
4132**System capability**: SystemCapability.Communication.IPC.Core
4133
4134**Return value**
4135
4136| Type  | Description                                   |
4137| ------ | --------------------------------------- |
4138| number | Current write position of the **MessageParcel** object.|
4139
4140**Example**
4141
4142  ```ts
4143  import { hilog } from '@kit.PerformanceAnalysisKit';
4144
4145  let data = rpc.MessageParcel.create();
4146  data.writeInt(10);
4147  let bwPos = data.getWritePosition();
4148  hilog.info(0x0000, 'testTag', 'RpcClient: bwPos is ' + bwPos);
4149  ```
4150
4151### rewindRead
4152
4153rewindRead(pos: number): boolean
4154
4155Moves the read pointer to the specified position.
4156
4157**System capability**: SystemCapability.Communication.IPC.Core
4158
4159**Parameters**
4160
4161| Name| Type  | Mandatory| Description                    |
4162| ------ | ------ | ---- | ------------------------ |
4163| pos    | number | Yes  | Position from which data is to read.|
4164
4165**Return value**
4166
4167| Type   | Description                                             |
4168| ------- | ------------------------------------------------- |
4169| boolean | Returns **true** if the read position changes; returns **false** otherwise.|
4170
4171**Example**
4172
4173  ```ts
4174  import { hilog } from '@kit.PerformanceAnalysisKit';
4175
4176  let data = rpc.MessageParcel.create();
4177  data.writeInt(12);
4178  data.writeString("parcel");
4179  let number = data.readInt();
4180  hilog.info(0x0000, 'testTag', 'RpcClient: number is ' + number);
4181  data.rewindRead(0);
4182  let number2 = data.readInt();
4183  hilog.info(0x0000, 'testTag', 'RpcClient: rewindRead is ' + number2);
4184  ```
4185
4186### rewindWrite
4187
4188rewindWrite(pos: number): boolean
4189
4190Moves the write pointer to the specified position.
4191
4192**System capability**: SystemCapability.Communication.IPC.Core
4193
4194**Parameters**
4195
4196| Name| Type  | Mandatory| Description                    |
4197| ------ | ------ | ---- | ------------------------ |
4198| pos    | number | Yes  | Position from which data is to write.|
4199
4200**Return value**
4201
4202| Type   | Description                                         |
4203| ------- | --------------------------------------------- |
4204| boolean | Returns **true** if the write position changes; returns **false** otherwise.|
4205
4206**Example**
4207
4208  ```ts
4209  import { hilog } from '@kit.PerformanceAnalysisKit';
4210
4211  let data = rpc.MessageParcel.create();
4212  data.writeInt(4);
4213  data.rewindWrite(0);
4214  data.writeInt(5);
4215  let number = data.readInt();
4216  hilog.info(0x0000, 'testTag', 'RpcClient: rewindWrite is ' + number);
4217  ```
4218
4219### writeByte
4220
4221writeByte(val: number): boolean
4222
4223Writes a Byte value to this **MessageParcel** object.
4224
4225**System capability**: SystemCapability.Communication.IPC.Core
4226
4227**Parameters**
4228
4229| Name| Type  | Mandatory| Description            |
4230| ------ | ------ | ---- | ---------------- |
4231| val    | number | Yes  | Byte value to write.|
4232
4233**Return value**
4234
4235| Type   | Description                         |
4236| ------- | ----------------------------- |
4237| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
4238
4239**Example**
4240
4241  ```ts
4242  import { hilog } from '@kit.PerformanceAnalysisKit';
4243
4244  let data = rpc.MessageParcel.create();
4245  let result = data.writeByte(2);
4246  hilog.info(0x0000, 'testTag', 'RpcClient: writeByte is ' + result);
4247  ```
4248
4249### readByte
4250
4251readByte(): number
4252
4253Reads the Byte value from this **MessageParcel** object.
4254
4255**System capability**: SystemCapability.Communication.IPC.Core
4256
4257**Return value**
4258
4259| Type  | Description        |
4260| ------ | ------------ |
4261| number | Byte value read.|
4262
4263**Example**
4264
4265  ```ts
4266  import { hilog } from '@kit.PerformanceAnalysisKit';
4267
4268  let data = rpc.MessageParcel.create();
4269  let result = data.writeByte(2);
4270  hilog.info(0x0000, 'testTag', 'RpcClient: writeByte is ' + result);
4271  let ret = data.readByte();
4272  hilog.info(0x0000, 'testTag', 'RpcClient: readByte is ' + ret);
4273  ```
4274
4275### writeShort
4276
4277writeShort(val: number): boolean
4278
4279Writes a Short int value to this **MessageParcel** object.
4280
4281**System capability**: SystemCapability.Communication.IPC.Core
4282
4283**Parameters**
4284
4285| Name| Type  | Mandatory| Description              |
4286| ------ | ------ | ---- | ------------------ |
4287| val    | number | Yes  | Short int value to write.|
4288
4289**Return value**
4290
4291| Type   | Description                         |
4292| ------- | ----------------------------- |
4293| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4294
4295**Example**
4296
4297  ```ts
4298  import { hilog } from '@kit.PerformanceAnalysisKit';
4299
4300  let data = rpc.MessageParcel.create();
4301  let result = data.writeShort(8);
4302  hilog.info(0x0000, 'testTag', 'RpcClient: writeShort is ' + result);
4303  ```
4304
4305### readShort
4306
4307readShort(): number
4308
4309Reads the Short int value from this **MessageParcel** object.
4310
4311**System capability**: SystemCapability.Communication.IPC.Core
4312
4313**Return value**
4314
4315| Type  | Description          |
4316| ------ | -------------- |
4317| number | Short int value read.|
4318
4319**Example**
4320
4321  ```ts
4322  import { hilog } from '@kit.PerformanceAnalysisKit';
4323
4324  let data = rpc.MessageParcel.create();
4325  let result = data.writeShort(8);
4326  hilog.info(0x0000, 'testTag', 'RpcClient: writeShort is ' + result);
4327  let ret = data.readShort();
4328  hilog.info(0x0000, 'testTag', 'RpcClient: readShort is ' + ret);
4329  ```
4330
4331### writeInt
4332
4333writeInt(val: number): boolean
4334
4335Writes an Int value to this **MessageParcel** object.
4336
4337**System capability**: SystemCapability.Communication.IPC.Core
4338
4339**Parameters**
4340
4341| Name| Type  | Mandatory| Description            |
4342| ------ | ------ | ---- | ---------------- |
4343| val    | number | Yes  | Int value to write.|
4344
4345**Return value**
4346
4347| Type   | Description                         |
4348| ------- | ----------------------------- |
4349| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
4350
4351**Example**
4352
4353  ```ts
4354  import { hilog } from '@kit.PerformanceAnalysisKit';
4355
4356  let data = rpc.MessageParcel.create();
4357  let result = data.writeInt(10);
4358  hilog.info(0x0000, 'testTag', 'RpcClient: writeInt is ' + result);
4359  ```
4360
4361### readInt
4362
4363readInt(): number
4364
4365Reads the Int value from this **MessageParcel** object.
4366
4367**System capability**: SystemCapability.Communication.IPC.Core
4368
4369**Return value**
4370
4371| Type  | Description        |
4372| ------ | ------------ |
4373| number | Int value read.|
4374
4375**Example**
4376
4377  ```ts
4378  import { hilog } from '@kit.PerformanceAnalysisKit';
4379
4380  let data = rpc.MessageParcel.create();
4381  let result = data.writeInt(10);
4382  hilog.info(0x0000, 'testTag', 'RpcClient: writeInt is ' + result);
4383  let ret = data.readInt();
4384  hilog.info(0x0000, 'testTag', 'RpcClient: readInt is ' + ret);
4385  ```
4386
4387### writeLong
4388
4389writeLong(val: number): boolean
4390
4391Writes a Long int value to this **MessageParcel** object.
4392
4393**System capability**: SystemCapability.Communication.IPC.Core
4394
4395**Parameters**
4396
4397| Name| Type  | Mandatory| Description            |
4398| ------ | ------ | ---- | ---------------- |
4399| val    | number | Yes  | Long int value to write.|
4400
4401**Return value**
4402
4403| Type   | Description                             |
4404| ------- | --------------------------------- |
4405| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4406
4407**Example**
4408
4409  ```ts
4410  import { hilog } from '@kit.PerformanceAnalysisKit';
4411
4412  let data = rpc.MessageParcel.create();
4413  let result = data.writeLong(10000);
4414  hilog.info(0x0000, 'testTag', 'RpcClient: writeLong is ' + result);
4415  ```
4416
4417### readLong
4418
4419readLong(): number
4420
4421Reads the Long int value from this **MessageParcel** object.
4422
4423**System capability**: SystemCapability.Communication.IPC.Core
4424
4425**Return value**
4426
4427| Type  | Description          |
4428| ------ | -------------- |
4429| number | Long int value read.|
4430
4431**Example**
4432
4433  ```ts
4434  import { hilog } from '@kit.PerformanceAnalysisKit';
4435
4436  let data = rpc.MessageParcel.create();
4437  let result = data.writeLong(10000);
4438  hilog.info(0x0000, 'testTag', 'RpcClient: writeLong is ' + result);
4439  let ret = data.readLong();
4440  hilog.info(0x0000, 'testTag', 'RpcClient: readLong is ' + ret);
4441  ```
4442
4443### writeFloat
4444
4445writeFloat(val: number): boolean
4446
4447Writes a Float value to this **MessageParcel** object.
4448
4449**System capability**: SystemCapability.Communication.IPC.Core
4450
4451**Parameters**
4452
4453| Name| Type  | Mandatory| Description            |
4454| ------ | ------ | ---- | ---------------- |
4455| val    | number | Yes  | Float value to write.|
4456
4457**Return value**
4458
4459| Type   | Description                             |
4460| ------- | --------------------------------- |
4461| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4462
4463**Example**
4464
4465  ```ts
4466  import { hilog } from '@kit.PerformanceAnalysisKit';
4467
4468  let data = rpc.MessageParcel.create();
4469  let result = data.writeFloat(1.2);
4470  hilog.info(0x0000, 'testTag', 'RpcClient: writeFloat is ' + result);
4471  ```
4472
4473### readFloat
4474
4475readFloat(): number
4476
4477Reads the Float value from this **MessageParcel** object.
4478
4479**System capability**: SystemCapability.Communication.IPC.Core
4480
4481**Return value**
4482
4483| Type  | Description        |
4484| ------ | ------------ |
4485| number | Float value read.|
4486
4487**Example**
4488
4489  ```ts
4490  import { hilog } from '@kit.PerformanceAnalysisKit';
4491
4492  let data = rpc.MessageParcel.create();
4493  let result = data.writeFloat(1.2);
4494  hilog.info(0x0000, 'testTag', 'RpcClient: writeFloat is ' + result);
4495  let ret = data.readFloat();
4496  hilog.info(0x0000, 'testTag', 'RpcClient: readFloat is ' + ret);
4497  ```
4498
4499### writeDouble
4500
4501writeDouble(val: number): boolean
4502
4503Writes a Double value to this **MessageParcel** object.
4504
4505**System capability**: SystemCapability.Communication.IPC.Core
4506
4507**Parameters**
4508
4509| Name| Type  | Mandatory| Description                  |
4510| ------ | ------ | ---- | ---------------------- |
4511| val    | number | Yes  | Double value to write.|
4512
4513**Return value**
4514
4515| Type   | Description                             |
4516| ------- | --------------------------------- |
4517| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4518
4519**Example**
4520
4521  ```ts
4522  import { hilog } from '@kit.PerformanceAnalysisKit';
4523
4524  let data = rpc.MessageParcel.create();
4525  let result = data.writeDouble(10.2);
4526  hilog.info(0x0000, 'testTag', 'RpcClient: writeDouble is ' + result);
4527  ```
4528
4529### readDouble
4530
4531readDouble(): number
4532
4533Reads the Double value from this **MessageParcel** object.
4534
4535**System capability**: SystemCapability.Communication.IPC.Core
4536
4537**Return value**
4538
4539| Type  | Description              |
4540| ------ | ------------------ |
4541| number | Double value read.|
4542
4543**Example**
4544
4545  ```ts
4546  import { hilog } from '@kit.PerformanceAnalysisKit';
4547
4548  let data = rpc.MessageParcel.create();
4549  let result = data.writeDouble(10.2);
4550  hilog.info(0x0000, 'testTag', 'RpcClient: writeDouble is ' + result);
4551  let ret = data.readDouble();
4552  hilog.info(0x0000, 'testTag', 'RpcClient: readDouble is ' + ret);
4553  ```
4554
4555### writeBoolean
4556
4557writeBoolean(val: boolean): boolean
4558
4559Writes a Boolean value to this **MessageParcel** object.
4560
4561**System capability**: SystemCapability.Communication.IPC.Core
4562
4563**Parameters**
4564
4565| Name| Type   | Mandatory| Description            |
4566| ------ | ------- | ---- | ---------------- |
4567| val    | boolean | Yes  | Boolean value to write.|
4568
4569**Return value**
4570
4571| Type   | Description                             |
4572| ------- | --------------------------------- |
4573| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4574
4575**Example**
4576
4577  ```ts
4578  import { hilog } from '@kit.PerformanceAnalysisKit';
4579
4580  let data = rpc.MessageParcel.create();
4581  let result = data.writeBoolean(false);
4582  hilog.info(0x0000, 'testTag', 'RpcClient: writeBoolean is ' + result);
4583  ```
4584
4585### readBoolean
4586
4587readBoolean(): boolean
4588
4589Reads the Boolean value from this **MessageParcel** object.
4590
4591**System capability**: SystemCapability.Communication.IPC.Core
4592
4593**Return value**
4594
4595| Type   | Description                |
4596| ------- | -------------------- |
4597| boolean | Boolean value read.|
4598
4599**Example**
4600
4601  ```ts
4602  import { hilog } from '@kit.PerformanceAnalysisKit';
4603
4604  let data = rpc.MessageParcel.create();
4605  let result = data.writeBoolean(false);
4606  hilog.info(0x0000, 'testTag', 'RpcClient: writeBoolean is ' + result);
4607  let ret = data.readBoolean();
4608  hilog.info(0x0000, 'testTag', 'RpcClient: readBoolean is ' + ret);
4609  ```
4610
4611### writeChar
4612
4613writeChar(val: number): boolean
4614
4615Writes a Char value to this **MessageParcel** object.
4616
4617**System capability**: SystemCapability.Communication.IPC.Core
4618
4619**Parameters**
4620
4621| Name| Type  | Mandatory| Description                |
4622| ------ | ------ | ---- | -------------------- |
4623| val    | number | Yes  | Char value to write.|
4624
4625**Return value**
4626
4627| Type   | Description                         |
4628| ------- | ----------------------------- |
4629| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4630
4631**Example**
4632
4633  ```ts
4634  import { hilog } from '@kit.PerformanceAnalysisKit';
4635
4636  let data = rpc.MessageParcel.create();
4637  let result = data.writeChar(97);
4638  hilog.info(0x0000, 'testTag', 'RpcClient: writeChar is ' + result);
4639  ```
4640
4641### readChar
4642
4643readChar(): number
4644
4645Reads the Char value from this **MessageParcel** object.
4646
4647**System capability**: SystemCapability.Communication.IPC.Core
4648
4649**Return value**
4650
4651| Type  | Description            |
4652| ------ | ---------------- |
4653| number | Char value read.|
4654
4655**Example**
4656
4657  ```ts
4658  import { hilog } from '@kit.PerformanceAnalysisKit';
4659
4660  let data = rpc.MessageParcel.create();
4661  let result = data.writeChar(97);
4662  hilog.info(0x0000, 'testTag', 'RpcClient: writeChar is ' + result);
4663  let ret = data.readChar();
4664  hilog.info(0x0000, 'testTag', 'RpcClient: readChar is ' + ret);
4665  ```
4666
4667### writeString
4668
4669writeString(val: string): boolean
4670
4671Writes a string to this **MessageParcel** object.
4672
4673**System capability**: SystemCapability.Communication.IPC.Core
4674
4675**Parameters**
4676
4677| Name| Type  | Mandatory| Description                                     |
4678| ------ | ------ | ---- | ----------------------------------------- |
4679| val    | string | Yes  | String to write. The length of the string must be less than 40960 bytes.|
4680
4681**Return value**
4682
4683| Type   | Description                             |
4684| ------- | --------------------------------- |
4685| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4686
4687**Example**
4688
4689  ```ts
4690  import { hilog } from '@kit.PerformanceAnalysisKit';
4691
4692  let data = rpc.MessageParcel.create();
4693  let result = data.writeString('abc');
4694  hilog.info(0x0000, 'testTag', 'RpcClient: writeString is ' + result);
4695  ```
4696
4697### readString
4698
4699readString(): string
4700
4701Reads the string from this **MessageParcel** object.
4702
4703**System capability**: SystemCapability.Communication.IPC.Core
4704
4705**Return value**
4706
4707| Type  | Description          |
4708| ------ | -------------- |
4709| string | String read.|
4710
4711**Example**
4712
4713  ```ts
4714  import { hilog } from '@kit.PerformanceAnalysisKit';
4715
4716  let data = rpc.MessageParcel.create();
4717  let result = data.writeString('abc');
4718  hilog.info(0x0000, 'testTag', 'RpcClient: writeString is ' + result);
4719  let ret = data.readString();
4720  hilog.info(0x0000, 'testTag', 'RpcClient: readString is ' + ret);
4721  ```
4722
4723### writeSequenceable
4724
4725writeSequenceable(val: Sequenceable): boolean
4726
4727Writes a sequenceable object to this **MessageParcel** object.
4728
4729**System capability**: SystemCapability.Communication.IPC.Core
4730
4731**Parameters**
4732
4733| Name| Type                         | Mandatory| Description                |
4734| ------ | ----------------------------- | ---- | -------------------- |
4735| val    | [Sequenceable](#sequenceabledeprecated) | Yes  | Sequenceable object to write.|
4736
4737**Return value**
4738
4739| Type   | Description                            |
4740| ------- | -------------------------------- |
4741| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4742
4743**Example**
4744
4745  ```ts
4746  import { hilog } from '@kit.PerformanceAnalysisKit';
4747
4748  class MySequenceable implements rpc.Sequenceable {
4749    num: number = 0;
4750    str: string = '';
4751    constructor(num: number, str: string) {
4752      this.num = num;
4753      this.str = str;
4754    }
4755    marshalling(messageParcel: rpc.MessageParcel): boolean {
4756      messageParcel.writeInt(this.num);
4757      messageParcel.writeString(this.str);
4758      return true;
4759    }
4760    unmarshalling(messageParcel: rpc.MessageParcel): boolean {
4761      this.num = messageParcel.readInt();
4762      this.str = messageParcel.readString();
4763      return true;
4764    }
4765  }
4766  let sequenceable = new MySequenceable(1, "aaa");
4767  let data = rpc.MessageParcel.create();
4768  let result = data.writeSequenceable(sequenceable);
4769  hilog.info(0x0000, 'testTag', 'RpcClient: writeSequenceable is ' + result);
4770  ```
4771
4772### readSequenceable
4773
4774readSequenceable(dataIn: Sequenceable): boolean
4775
4776Reads member variables from this **MessageParcel** object.
4777
4778**System capability**: SystemCapability.Communication.IPC.Core
4779
4780**Parameters**
4781
4782| Name| Type                         | Mandatory   | Description                                          |
4783| ------ | ----------------------------- | ------- | ---------------------------------------------- |
4784| dataIn | [Sequenceable](#sequenceabledeprecated) | Yes  | Object that reads member variables from the **MessageParcel** object.|
4785
4786**Return value**
4787
4788| Type   | Description                                    |
4789| ------- | ---------------------------------------- |
4790| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
4791
4792**Example**
4793
4794  ```ts
4795  import { hilog } from '@kit.PerformanceAnalysisKit';
4796
4797  class MySequenceable implements rpc.Sequenceable {
4798    num: number = 0;
4799    str: string = '';
4800    constructor(num: number, str: string) {
4801      this.num = num;
4802      this.str = str;
4803    }
4804    marshalling(messageParcel: rpc.MessageParcel): boolean {
4805      messageParcel.writeInt(this.num);
4806      messageParcel.writeString(this.str);
4807      return true;
4808    }
4809    unmarshalling(messageParcel: rpc.MessageParcel): boolean {
4810      this.num = messageParcel.readInt();
4811      this.str = messageParcel.readString();
4812      return true;
4813    }
4814  }
4815  let sequenceable = new MySequenceable(1, "aaa");
4816  let data = rpc.MessageParcel.create();
4817  let result = data.writeSequenceable(sequenceable);
4818  hilog.info(0x0000, 'testTag', 'RpcClient: writeSequenceable is ' + result);
4819  let ret = new MySequenceable(0, "");
4820  let result2 = data.readSequenceable(ret);
4821  hilog.info(0x0000, 'testTag', 'RpcClient: readSequenceable is ' + result2);
4822  ```
4823
4824### writeByteArray
4825
4826writeByteArray(byteArray: number[]): boolean
4827
4828Writes a byte array to this **MessageParcel** object.
4829
4830**System capability**: SystemCapability.Communication.IPC.Core
4831
4832**Parameters**
4833
4834| Name   | Type    | Mandatory| Description              |
4835| --------- | -------- | ---- | ------------------ |
4836| byteArray | number[] | Yes  | Byte array to write.|
4837
4838**Return value**
4839
4840| Type   | Description                            |
4841| ------- | -------------------------------- |
4842| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4843
4844**Example**
4845
4846  ```ts
4847  import { hilog } from '@kit.PerformanceAnalysisKit';
4848
4849  let data = rpc.MessageParcel.create();
4850  let ByteArrayVar = [1, 2, 3, 4, 5];
4851  let result = data.writeByteArray(ByteArrayVar);
4852  hilog.info(0x0000, 'testTag', 'RpcClient: writeByteArray is ' + result);
4853  ```
4854
4855### readByteArray
4856
4857readByteArray(dataIn: number[]): void
4858
4859Reads a byte array from this **MessageParcel** object.
4860
4861**System capability**: SystemCapability.Communication.IPC.Core
4862
4863**Parameters**
4864
4865| Name| Type    | Mandatory| Description              |
4866| ------ | -------- | ---- | ------------------ |
4867| dataIn | number[] | Yes  | Byte array to read.|
4868
4869**Example**
4870
4871  ```ts
4872  import { hilog } from '@kit.PerformanceAnalysisKit';
4873
4874  let data = rpc.MessageParcel.create();
4875  let ByteArrayVar = [1, 2, 3, 4, 5];
4876  let result = data.writeByteArray(ByteArrayVar);
4877  hilog.info(0x0000, 'testTag', 'RpcClient: writeByteArray is ' + result);
4878  let array: Array<number> = new Array(5);
4879  data.readByteArray(array);
4880  ```
4881
4882### readByteArray
4883
4884readByteArray(): number[]
4885
4886Reads the byte array from this **MessageParcel** object.
4887
4888**System capability**: SystemCapability.Communication.IPC.Core
4889
4890**Return value**
4891
4892| Type    | Description          |
4893| -------- | -------------- |
4894| number[] | Byte array read.|
4895
4896**Example**
4897
4898  ```ts
4899  import { hilog } from '@kit.PerformanceAnalysisKit';
4900
4901  let data = rpc.MessageParcel.create();
4902  let ByteArrayVar = [1, 2, 3, 4, 5];
4903  let result = data.writeByteArray(ByteArrayVar);
4904  hilog.info(0x0000, 'testTag', 'RpcClient: writeByteArray is ' + result);
4905  let array = data.readByteArray();
4906  hilog.info(0x0000, 'testTag', 'RpcClient: readByteArray is ' + array);
4907  ```
4908
4909### writeShortArray
4910
4911writeShortArray(shortArray: number[]): boolean
4912
4913Writes a short array to this **MessageParcel** object.
4914
4915**System capability**: SystemCapability.Communication.IPC.Core
4916
4917**Parameters**
4918
4919| Name    | Type    | Mandatory| Description                |
4920| ---------- | -------- | ---- | -------------------- |
4921| shortArray | number[] | Yes  | Short array to write.|
4922
4923**Return value**
4924
4925| Type   | Description                            |
4926| ------- | -------------------------------- |
4927| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4928
4929**Example**
4930
4931  ```ts
4932  import { hilog } from '@kit.PerformanceAnalysisKit';
4933
4934  let data = rpc.MessageParcel.create();
4935  let result = data.writeShortArray([11, 12, 13]);
4936  hilog.info(0x0000, 'testTag', 'RpcClient: writeShortArray is ' + result);
4937  ```
4938
4939### readShortArray
4940
4941readShortArray(dataIn: number[]): void
4942
4943Reads a short array from this **MessageParcel** object.
4944
4945**System capability**: SystemCapability.Communication.IPC.Core
4946
4947**Parameters**
4948
4949| Name| Type    | Mandatory| Description                |
4950| ------ | -------- | ---- | -------------------- |
4951| dataIn | number[] | Yes  | Short array to read.|
4952
4953**Example**
4954
4955  ```ts
4956  import { hilog } from '@kit.PerformanceAnalysisKit';
4957
4958  let data = rpc.MessageParcel.create();
4959  let result = data.writeShortArray([11, 12, 13]);
4960  hilog.info(0x0000, 'testTag', 'RpcClient: writeShortArray is ' + result);
4961  let array: Array<number> = new Array(3);
4962  data.readShortArray(array);
4963  ```
4964
4965### readShortArray
4966
4967readShortArray(): number[]
4968
4969Reads the short array from this **MessageParcel** object.
4970
4971**System capability**: SystemCapability.Communication.IPC.Core
4972
4973**Return value**
4974
4975| Type    | Description            |
4976| -------- | ---------------- |
4977| number[] | Short array read.|
4978
4979**Example**
4980
4981  ```ts
4982  import { hilog } from '@kit.PerformanceAnalysisKit';
4983
4984  let data = rpc.MessageParcel.create();
4985  let result = data.writeShortArray([11, 12, 13]);
4986  hilog.info(0x0000, 'testTag', 'RpcClient: writeShortArray is ' + result);
4987  let array = data.readShortArray();
4988  hilog.info(0x0000, 'testTag', 'RpcClient: readShortArray is ' + array);
4989  ```
4990
4991### writeIntArray
4992
4993writeIntArray(intArray: number[]): boolean
4994
4995Writes an integer array to this **MessageParcel** object.
4996
4997**System capability**: SystemCapability.Communication.IPC.Core
4998
4999**Parameters**
5000
5001| Name  | Type    | Mandatory| Description              |
5002| -------- | -------- | ---- | ------------------ |
5003| intArray | number[] | Yes  | Integer array to write.|
5004
5005**Return value**
5006
5007| Type   | Description                            |
5008| ------- | -------------------------------- |
5009| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5010
5011**Example**
5012
5013  ```ts
5014  import { hilog } from '@kit.PerformanceAnalysisKit';
5015
5016  let data = rpc.MessageParcel.create();
5017  let result = data.writeIntArray([100, 111, 112]);
5018  hilog.info(0x0000, 'testTag', 'RpcClient: writeIntArray is ' + result);
5019  ```
5020
5021### readIntArray
5022
5023readIntArray(dataIn: number[]): void
5024
5025Reads an integer array from this **MessageParcel** object.
5026
5027**System capability**: SystemCapability.Communication.IPC.Core
5028
5029**Parameters**
5030
5031| Name| Type    | Mandatory| Description              |
5032| ------ | -------- | ---- | ------------------ |
5033| dataIn | number[] | Yes  | Integer array to read.|
5034
5035**Example**
5036
5037  ```ts
5038  import { hilog } from '@kit.PerformanceAnalysisKit';
5039
5040  let data = rpc.MessageParcel.create();
5041  let result = data.writeIntArray([100, 111, 112]);
5042  hilog.info(0x0000, 'testTag', 'RpcClient: writeIntArray is ' + result);
5043  let array: Array<number> = new Array(3);
5044  data.readIntArray(array);
5045  ```
5046
5047### readIntArray
5048
5049readIntArray(): number[]
5050
5051Reads the integer array from this **MessageParcel** object.
5052
5053**System capability**: SystemCapability.Communication.IPC.Core
5054
5055**Return value**
5056
5057| Type    | Description          |
5058| -------- | -------------- |
5059| number[] | Integer array read.|
5060
5061**Example**
5062
5063  ```ts
5064  import { hilog } from '@kit.PerformanceAnalysisKit';
5065
5066  let data = rpc.MessageParcel.create();
5067  let result = data.writeIntArray([100, 111, 112]);
5068  hilog.info(0x0000, 'testTag', 'RpcClient: writeIntArray is ' + result);
5069  let array = data.readIntArray();
5070  hilog.info(0x0000, 'testTag', 'RpcClient: readIntArray is ' + array);
5071  ```
5072
5073### writeLongArray
5074
5075writeLongArray(longArray: number[]): boolean
5076
5077Writes a long array to this **MessageParcel** object.
5078
5079**System capability**: SystemCapability.Communication.IPC.Core
5080
5081**Parameters**
5082
5083| Name   | Type    | Mandatory| Description                |
5084| --------- | -------- | ---- | -------------------- |
5085| longArray | number[] | Yes  | Long array to write.|
5086
5087**Return value**
5088
5089| Type   | Description                         |
5090| ------- | ----------------------------- |
5091| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5092
5093**Example**
5094
5095  ```ts
5096  import { hilog } from '@kit.PerformanceAnalysisKit';
5097
5098  let data = rpc.MessageParcel.create();
5099  let result = data.writeLongArray([1111, 1112, 1113]);
5100  hilog.info(0x0000, 'testTag', 'RpcClient: writeLongArray is ' + result);
5101  ```
5102
5103### readLongArray
5104
5105readLongArray(dataIn: number[]): void
5106
5107Reads a long array from this **MessageParcel** object.
5108
5109**System capability**: SystemCapability.Communication.IPC.Core
5110
5111**Parameters**
5112
5113| Name| Type    | Mandatory| Description                |
5114| ------ | -------- | ---- | -------------------- |
5115| dataIn | number[] | Yes  | Long array to read.|
5116
5117**Example**
5118
5119  ```ts
5120  import { hilog } from '@kit.PerformanceAnalysisKit';
5121
5122  let data = rpc.MessageParcel.create();
5123  let result = data.writeLongArray([1111, 1112, 1113]);
5124  hilog.info(0x0000, 'testTag', 'RpcClient: writeLongArray is ' + result);
5125  let array: Array<number> = new Array(3);
5126  data.readLongArray(array);
5127  ```
5128
5129### readLongArray
5130
5131readLongArray(): number[]
5132
5133Reads the long array from this **MessageParcel** object.
5134
5135**System capability**: SystemCapability.Communication.IPC.Core
5136
5137**Return value**
5138
5139| Type    | Description            |
5140| -------- | ---------------- |
5141| number[] | Long array read.|
5142
5143**Example**
5144
5145  ```ts
5146  import { hilog } from '@kit.PerformanceAnalysisKit';
5147
5148  let data = rpc.MessageParcel.create();
5149  let result = data.writeLongArray([1111, 1112, 1113]);
5150  hilog.info(0x0000, 'testTag', 'RpcClient: writeLongArray is ' + result);
5151  let array = data.readLongArray();
5152  hilog.info(0x0000, 'testTag', 'RpcClient: readLongArray is ' + array);
5153  ```
5154
5155### writeFloatArray
5156
5157writeFloatArray(floatArray: number[]): boolean
5158
5159Writes a FloatArray to this **MessageParcel** object.
5160
5161**System capability**: SystemCapability.Communication.IPC.Core
5162
5163**Parameters**
5164
5165| Name| Type| Mandatory| Description |
5166| ---------- | -------- | ---- | --- |
5167| floatArray | number[] | Yes  | Floating-point array to write. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
5168
5169**Return value**
5170
5171| Type   | Description                            |
5172| ------- | -------------------------------- |
5173| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5174
5175**Example**
5176
5177  ```ts
5178  import { hilog } from '@kit.PerformanceAnalysisKit';
5179
5180  let data = rpc.MessageParcel.create();
5181  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
5182  hilog.info(0x0000, 'testTag', 'RpcClient: writeFloatArray is ' + result);
5183  ```
5184
5185### readFloatArray
5186
5187readFloatArray(dataIn: number[]): void
5188
5189Reads a FloatArray from this **MessageParcel** object.
5190
5191**System capability**: SystemCapability.Communication.IPC.Core
5192
5193**Parameters**
5194
5195| Name| Type    | Mandatory| Description  |
5196| ------ | -------- | ---- | ------ |
5197| dataIn | number[] | Yes  | Floating-point array to read. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
5198
5199**Example**
5200
5201  ```ts
5202  import { hilog } from '@kit.PerformanceAnalysisKit';
5203
5204  let data = rpc.MessageParcel.create();
5205  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
5206  hilog.info(0x0000, 'testTag', 'RpcClient: writeFloatArray is ' + result);
5207  let array: Array<number> = new Array(3);
5208  data.readFloatArray(array);
5209  ```
5210
5211### readFloatArray
5212
5213readFloatArray(): number[]
5214
5215Reads the FloatArray from this **MessageParcel** object.
5216
5217**System capability**: SystemCapability.Communication.IPC.Core
5218
5219**Return value**
5220
5221| Type    | Description          |
5222| -------- | -------------- |
5223| number[] | FloatArray read.|
5224
5225**Example**
5226
5227  ```ts
5228  import { hilog } from '@kit.PerformanceAnalysisKit';
5229
5230  let data = rpc.MessageParcel.create();
5231  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
5232  hilog.info(0x0000, 'testTag', 'RpcClient: writeFloatArray is ' + result);
5233  let array = data.readFloatArray();
5234  hilog.info(0x0000, 'testTag', 'RpcClient: readFloatArray is ' + array);
5235  ```
5236
5237### writeDoubleArray
5238
5239writeDoubleArray(doubleArray: number[]): boolean
5240
5241Writes a DoubleArray to this **MessageParcel** object.
5242
5243**System capability**: SystemCapability.Communication.IPC.Core
5244
5245**Parameters**
5246
5247| Name     | Type    | Mandatory| Description                    |
5248| ----------- | -------- | ---- | ------------------------ |
5249| doubleArray | number[] | Yes  | DoubleArray to write.|
5250
5251**Return value**
5252
5253| Type   | Description                            |
5254| ------- | -------------------------------- |
5255| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5256
5257**Example**
5258
5259  ```ts
5260  import { hilog } from '@kit.PerformanceAnalysisKit';
5261
5262  let data = rpc.MessageParcel.create();
5263  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
5264  hilog.info(0x0000, 'testTag', 'RpcClient: writeDoubleArray is ' + result);
5265  ```
5266
5267### readDoubleArray
5268
5269readDoubleArray(dataIn: number[]): void
5270
5271Reads a DoubleArray from this **MessageParcel** object.
5272
5273**System capability**: SystemCapability.Communication.IPC.Core
5274
5275**Parameters**
5276
5277| Name| Type    | Mandatory| Description                    |
5278| ------ | -------- | ---- | ------------------------ |
5279| dataIn | number[] | Yes  | DoubleArray to read.|
5280
5281**Example**
5282
5283  ```ts
5284  import { hilog } from '@kit.PerformanceAnalysisKit';
5285
5286  let data = rpc.MessageParcel.create();
5287  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
5288  hilog.info(0x0000, 'testTag', 'RpcClient: writeDoubleArray is ' + result);
5289  let array: Array<number> = new Array(3);
5290  data.readDoubleArray(array);
5291  ```
5292
5293### readDoubleArray
5294
5295readDoubleArray(): number[]
5296
5297Reads the DoubleArray from this **MessageParcel** object.
5298
5299**System capability**: SystemCapability.Communication.IPC.Core
5300
5301**Return value**
5302
5303| Type    | Description                |
5304| -------- | -------------------- |
5305| number[] | DoubleArray read.|
5306
5307**Example**
5308
5309  ```ts
5310  import { hilog } from '@kit.PerformanceAnalysisKit';
5311
5312  let data = rpc.MessageParcel.create();
5313  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
5314  hilog.info(0x0000, 'testTag', 'RpcClient: writeDoubleArray is ' + result);
5315  let array = data.readDoubleArray();
5316  hilog.info(0x0000, 'testTag', 'RpcClient: readDoubleArray is ' + array);
5317  ```
5318
5319### writeBooleanArray
5320
5321writeBooleanArray(booleanArray: boolean[]): boolean
5322
5323Writes a Boolean array to this **MessageParcel** object.
5324
5325**System capability**: SystemCapability.Communication.IPC.Core
5326
5327**Parameters**
5328
5329| Name      | Type     | Mandatory| Description              |
5330| ------------ | --------- | ---- | ------------------ |
5331| booleanArray | boolean[] | Yes  | Boolean array to write.|
5332
5333**Return value**
5334
5335| Type   | Description                            |
5336| ------- | -------------------------------- |
5337| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5338
5339**Example**
5340
5341  ```ts
5342  import { hilog } from '@kit.PerformanceAnalysisKit';
5343
5344  let data = rpc.MessageParcel.create();
5345  let result = data.writeBooleanArray([false, true, false]);
5346  hilog.info(0x0000, 'testTag', 'RpcClient: writeBooleanArray is ' + result);
5347  ```
5348
5349### readBooleanArray
5350
5351readBooleanArray(dataIn: boolean[]): void
5352
5353Reads a Boolean array from this **MessageParcel** object.
5354
5355**System capability**: SystemCapability.Communication.IPC.Core
5356
5357**Parameters**
5358
5359| Name| Type     | Mandatory| Description              |
5360| ------ | --------- | ---- | ------------------ |
5361| dataIn | boolean[] | Yes  | Boolean array to read.|
5362
5363**Example**
5364
5365  ```ts
5366  import { hilog } from '@kit.PerformanceAnalysisKit';
5367
5368  let data = rpc.MessageParcel.create();
5369  let result = data.writeBooleanArray([false, true, false]);
5370  hilog.info(0x0000, 'testTag', 'RpcClient: writeBooleanArray is ' + result);
5371  let array: Array<boolean> = new Array(3);
5372  data.readBooleanArray(array);
5373  ```
5374
5375### readBooleanArray
5376
5377readBooleanArray(): boolean[]
5378
5379Reads the Boolean array from this **MessageParcel** object.
5380
5381**System capability**: SystemCapability.Communication.IPC.Core
5382
5383**Return value**
5384
5385| Type     | Description          |
5386| --------- | -------------- |
5387| boolean[] | Boolean array read.|
5388
5389**Example**
5390
5391  ```ts
5392  import { hilog } from '@kit.PerformanceAnalysisKit';
5393
5394  let data = rpc.MessageParcel.create();
5395  let result = data.writeBooleanArray([false, true, false]);
5396  hilog.info(0x0000, 'testTag', 'RpcClient: writeBooleanArray is ' + result);
5397  let array = data.readBooleanArray();
5398  hilog.info(0x0000, 'testTag', 'RpcClient: readBooleanArray is ' + array);
5399  ```
5400
5401### writeCharArray
5402
5403writeCharArray(charArray: number[]): boolean
5404
5405Writes a character array to this **MessageParcel** object.
5406
5407**System capability**: SystemCapability.Communication.IPC.Core
5408
5409**Parameters**
5410
5411| Name   | Type    | Mandatory| Description                  |
5412| --------- | -------- | ---- | ---------------------- |
5413| charArray | number[] | Yes  | Character array to write.|
5414
5415**Return value**
5416
5417| Type   | Description                            |
5418| ------- | -------------------------------- |
5419| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5420
5421**Example**
5422
5423  ```ts
5424  import { hilog } from '@kit.PerformanceAnalysisKit';
5425
5426  let data = rpc.MessageParcel.create();
5427  let result = data.writeCharArray([97, 98, 88]);
5428  hilog.info(0x0000, 'testTag', 'RpcClient: writeCharArray is ' + result);
5429  ```
5430
5431### readCharArray
5432
5433readCharArray(dataIn: number[]): void
5434
5435Reads a character array from this **MessageParcel** object.
5436
5437**System capability**: SystemCapability.Communication.IPC.Core
5438
5439**Parameters**
5440
5441| Name| Type    | Mandatory| Description                  |
5442| ------ | -------- | ---- | ---------------------- |
5443| dataIn | number[] | Yes  | Character array to read.|
5444
5445**Example**
5446
5447  ```ts
5448  import { hilog } from '@kit.PerformanceAnalysisKit';
5449
5450  let data = rpc.MessageParcel.create();
5451  let result = data.writeCharArray([97, 98, 99]);
5452  hilog.info(0x0000, 'testTag', 'RpcClient: writeCharArray is ' + result);
5453  let array: Array<number> = new Array(3);
5454  data.readCharArray(array);
5455  ```
5456
5457### readCharArray
5458
5459readCharArray(): number[]
5460
5461Reads the character array from this **MessageParcel** object.
5462
5463**System capability**: SystemCapability.Communication.IPC.Core
5464
5465**Return value**
5466
5467| Type    | Description              |
5468| -------- | ------------------ |
5469| number[] | Character array read.|
5470
5471**Example**
5472
5473  ```ts
5474  import { hilog } from '@kit.PerformanceAnalysisKit';
5475
5476  let data = rpc.MessageParcel.create();
5477  let result = data.writeCharArray([97, 98, 99]);
5478  hilog.info(0x0000, 'testTag', 'RpcClient: writeCharArray is ' + result);
5479  let array = data.readCharArray();
5480  hilog.info(0x0000, 'testTag', 'RpcClient: readCharArray is ' + array);
5481  ```
5482
5483### writeStringArray
5484
5485writeStringArray(stringArray: string[]): boolean
5486
5487Writes a string array to this **MessageParcel** object.
5488
5489**System capability**: SystemCapability.Communication.IPC.Core
5490
5491**Parameters**
5492
5493| Name     | Type    | Mandatory| Description            |
5494| ----------- | -------- | ---- | ---------------- |
5495| stringArray | string[] | Yes  | String array to write. The length of a single element in the array must be less than 40960 bytes.|
5496
5497**Return value**
5498
5499| Type   | Description|
5500| ------- | -------------------------------- |
5501| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5502
5503**Example**
5504
5505  ```ts
5506  import { hilog } from '@kit.PerformanceAnalysisKit';
5507
5508  let data = rpc.MessageParcel.create();
5509  let result = data.writeStringArray(["abc", "def"]);
5510  hilog.info(0x0000, 'testTag', 'RpcClient: writeStringArray is ' + result);
5511  ```
5512
5513### readStringArray
5514
5515readStringArray(dataIn: string[]): void
5516
5517Reads a string array from this **MessageParcel** object.
5518
5519**System capability**: SystemCapability.Communication.IPC.Core
5520
5521**Parameters**
5522
5523| Name| Type    | Mandatory| Description                |
5524| ------ | -------- | ---- | -------------------- |
5525| dataIn | string[] | Yes  | String array to read.|
5526
5527**Example**
5528
5529  ```ts
5530  import { hilog } from '@kit.PerformanceAnalysisKit';
5531
5532  let data = rpc.MessageParcel.create();
5533  let result = data.writeStringArray(["abc", "def"]);
5534  hilog.info(0x0000, 'testTag', 'RpcClient: writeStringArray is ' + result);
5535  let array: Array<string> = new Array(2);
5536  data.readStringArray(array);
5537  ```
5538
5539### readStringArray
5540
5541readStringArray(): string[]
5542
5543Reads the string array from this **MessageParcel** object.
5544
5545**System capability**: SystemCapability.Communication.IPC.Core
5546
5547**Return value**
5548
5549| Type    | Description            |
5550| -------- | ---------------- |
5551| string[] | String array read.|
5552
5553**Example**
5554
5555  ```ts
5556  import { hilog } from '@kit.PerformanceAnalysisKit';
5557
5558  let data = rpc.MessageParcel.create();
5559  let result = data.writeStringArray(["abc", "def"]);
5560  hilog.info(0x0000, 'testTag', 'RpcClient: writeStringArray is ' + result);
5561  let array = data.readStringArray();
5562  hilog.info(0x0000, 'testTag', 'RpcClient: readStringArray is ' + array);
5563  ```
5564
5565### writeNoException<sup>8+</sup>
5566
5567writeNoException(): void
5568
5569Writes information to this **MessageParcel** object indicating that no exception occurred.
5570
5571**System capability**: SystemCapability.Communication.IPC.Core
5572
5573**Example**
5574
5575  ```ts
5576  import { hilog } from '@kit.PerformanceAnalysisKit';
5577
5578  class MyDeathRecipient implements rpc.DeathRecipient {
5579    onRemoteDied() {
5580      hilog.info(0x0000, 'testTag', 'server died');
5581    }
5582  }
5583  class TestRemoteObject extends rpc.RemoteObject {
5584    constructor(descriptor: string) {
5585      super(descriptor);
5586    }
5587    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5588      return true;
5589    }
5590    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5591      return true;
5592    }
5593    isObjectDead(): boolean {
5594      return false;
5595    }
5596    onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, option: rpc.MessageOption): boolean {
5597      if (code === 1) {
5598        hilog.info(0x0000, 'testTag', 'RpcServer: onRemoteRequest called');
5599        reply.writeNoException();
5600        return true;
5601      } else {
5602        hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
5603        return false;
5604      }
5605    }
5606  }
5607  ```
5608
5609### readException<sup>8+</sup>
5610
5611readException(): void
5612
5613Reads the exception information from this **MessageParcel** object.
5614
5615**System capability**: SystemCapability.Communication.IPC.Core
5616
5617**Example**
5618
5619  ```ts
5620  // If the FA model is used, import featureAbility from @kit.AbilityKit.
5621  // import { featureAbility } from '@kit.AbilityKit';
5622  import { Want, common } from '@kit.AbilityKit';
5623  import { hilog } from '@kit.PerformanceAnalysisKit';
5624
5625  let proxy: rpc.IRemoteObject | undefined;
5626  let connect: common.ConnectOptions = {
5627    onConnect: (elementName, remoteProxy) => {
5628      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
5629      proxy = remoteProxy;
5630    },
5631    onDisconnect: (elementName) => {
5632      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
5633    },
5634    onFailed: () => {
5635      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
5636    }
5637  };
5638  let want: Want = {
5639    bundleName: "com.ohos.server",
5640    abilityName: "com.ohos.server.EntryAbility",
5641  };
5642
5643  // Use this method to connect to the ability for the FA model.
5644  // FA.connectAbility(want,connect);
5645
5646  // Save the connection ID, which will be used for the subsequent service disconnection.
5647  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
5648  // Save the connection ID, which will be used for the subsequent service disconnection.
5649  let connectionId = context.connectServiceExtensionAbility(want, connect);
5650  ```
5651
5652  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
5653
5654  ```ts
5655  import { hilog } from '@kit.PerformanceAnalysisKit';
5656
5657  let option = new rpc.MessageOption();
5658  let data = rpc.MessageParcel.create();
5659  let reply = rpc.MessageParcel.create();
5660  data.writeNoException();
5661  data.writeString('hello');
5662  if (proxy != undefined) {
5663    let a = proxy.sendRequest(1, data, reply, option) as Object;
5664    let b = a as Promise<rpc.SendRequestResult>;
5665    b.then((result: rpc.SendRequestResult) => {
5666      if (result.errCode === 0) {
5667        hilog.info(0x0000, 'testTag', 'sendRequest got result');
5668        result.reply.readException();
5669        let msg = result.reply.readString();
5670        hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
5671      } else {
5672        hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed, errCode: ' + result.errCode);
5673      }
5674    }).catch((e: Error) => {
5675      hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest got exception: ' + e.message);
5676    }).finally (() => {
5677      hilog.info(0x0000, 'testTag', 'RPCTest: sendRequest ends, reclaim parcel');
5678      data.reclaim();
5679      reply.reclaim();
5680    });
5681  }
5682  ```
5683
5684### writeSequenceableArray
5685
5686writeSequenceableArray(sequenceableArray: Sequenceable[]): boolean
5687
5688Writes a sequenceable array to this **MessageParcel** object.
5689
5690**System capability**: SystemCapability.Communication.IPC.Core
5691
5692**Parameters**
5693
5694| Name           | Type                                     | Mandatory| Description                      |
5695| ----------------- | ----------------------------------------- | ---- | -------------------------- |
5696| sequenceableArray | [Sequenceable](#sequenceabledeprecated)[] | Yes  | Sequenceable array to write.|
5697
5698**Return value**
5699
5700| Type   | Description                            |
5701| ------- | -------------------------------- |
5702| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5703
5704**Example**
5705
5706  ```ts
5707  import { hilog } from '@kit.PerformanceAnalysisKit';
5708
5709  class MySequenceable implements rpc.Sequenceable {
5710    num: number = 0;
5711    str: string = '';
5712    constructor(num: number, str: string) {
5713      this.num = num;
5714      this.str = str;
5715    }
5716    marshalling(messageParcel: rpc.MessageParcel): boolean {
5717      messageParcel.writeInt(this.num);
5718      messageParcel.writeString(this.str);
5719      return true;
5720    }
5721    unmarshalling(messageParcel: rpc.MessageParcel): boolean {
5722      this.num = messageParcel.readInt();
5723      this.str = messageParcel.readString();
5724      return true;
5725    }
5726  }
5727  let sequenceable = new MySequenceable(1, "aaa");
5728  let sequenceable2 = new MySequenceable(2, "bbb");
5729  let sequenceable3 = new MySequenceable(3, "ccc");
5730  let a = [sequenceable, sequenceable2, sequenceable3];
5731  let data = rpc.MessageParcel.create();
5732  let result = data.writeSequenceableArray(a);
5733  hilog.info(0x0000, 'testTag', 'RpcClient: writeSequenceableArray is ' + result);
5734  ```
5735
5736### readSequenceableArray<sup>8+</sup>
5737
5738readSequenceableArray(sequenceableArray: Sequenceable[]): void
5739
5740Reads a sequenceable array from this **MessageParcel** object.
5741
5742**System capability**: SystemCapability.Communication.IPC.Core
5743
5744**Parameters**
5745
5746| Name           | Type                                     | Mandatory| Description                      |
5747| ----------------- | ----------------------------------------- | ---- | -------------------------- |
5748| sequenceableArray | [Sequenceable](#sequenceabledeprecated)[] | Yes  | Sequenceable array to read.|
5749
5750**Example**
5751
5752  ```ts
5753  import { hilog } from '@kit.PerformanceAnalysisKit';
5754
5755  class MySequenceable implements rpc.Sequenceable {
5756    num: number = 0;
5757    str: string = '';
5758    constructor(num: number, str: string) {
5759      this.num = num;
5760      this.str = str;
5761    }
5762    marshalling(messageParcel: rpc.MessageParcel): boolean {
5763      messageParcel.writeInt(this.num);
5764      messageParcel.writeString(this.str);
5765      return true;
5766    }
5767    unmarshalling(messageParcel: rpc.MessageParcel): boolean {
5768      this.num = messageParcel.readInt();
5769      this.str = messageParcel.readString();
5770      return true;
5771    }
5772  }
5773  let sequenceable = new MySequenceable(1, "aaa");
5774  let sequenceable2 = new MySequenceable(2, "bbb");
5775  let sequenceable3 = new MySequenceable(3, "ccc");
5776  let a = [sequenceable, sequenceable2, sequenceable3];
5777  let data = rpc.MessageParcel.create();
5778  let result = data.writeSequenceableArray(a);
5779  hilog.info(0x0000, 'testTag', 'RpcClient: writeSequenceableArray is ' + result);
5780  let b = [new MySequenceable(0, ""), new MySequenceable(0, ""), new MySequenceable(0, "")];
5781  data.readSequenceableArray(b);
5782  ```
5783
5784### writeRemoteObjectArray<sup>8+</sup>
5785
5786writeRemoteObjectArray(objectArray: IRemoteObject[]): boolean
5787
5788Writes an array of **IRemoteObject** objects to this **MessageParcel** object.
5789
5790**System capability**: SystemCapability.Communication.IPC.Core
5791
5792**Parameters**
5793
5794| Name     | Type           | Mandatory| Description |
5795| ----------- | --------------- | ---- | ----- |
5796| objectArray | [IRemoteObject](#iremoteobject)[] | Yes  | Array of **IRemoteObject** objects to write.|
5797
5798**Return value**
5799
5800| Type   | Description                                                                                                                |
5801| ------- | -------------------------------- |
5802| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5803
5804**Example**
5805
5806  ```ts
5807  import { hilog } from '@kit.PerformanceAnalysisKit';
5808
5809  class MyDeathRecipient implements rpc.DeathRecipient {
5810    onRemoteDied() {
5811      hilog.info(0x0000, 'testTag', 'server died');
5812    }
5813  }
5814  class TestRemoteObject extends rpc.RemoteObject {
5815    constructor(descriptor: string) {
5816      super(descriptor);
5817      this.attachLocalInterface(this, descriptor);
5818    }
5819    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5820      return true;
5821    }
5822    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5823      return true;
5824    }
5825    isObjectDead(): boolean {
5826      return false;
5827    }
5828    asObject(): rpc.IRemoteObject {
5829      return this;
5830    }
5831  }
5832  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
5833  let data = rpc.MessageParcel.create();
5834  let result = data.writeRemoteObjectArray(a);
5835  hilog.info(0x0000, 'testTag', 'RpcClient: writeRemoteObjectArray is ' + result);
5836  ```
5837
5838### readRemoteObjectArray<sup>8+</sup>
5839
5840readRemoteObjectArray(objects: IRemoteObject[]): void
5841
5842Reads an **IRemoteObject** array from this **MessageParcel** object.
5843
5844**System capability**: SystemCapability.Communication.IPC.Core
5845
5846**Parameters**
5847
5848| Name | Type           | Mandatory| Description     |
5849| ------- | --------------- | ---- | --------- |
5850| objects | [IRemoteObject](#iremoteobject)[] | Yes  | **IRemoteObject** array to read.|
5851
5852**Example**
5853
5854  ```ts
5855  import { hilog } from '@kit.PerformanceAnalysisKit';
5856
5857  class MyDeathRecipient implements rpc.DeathRecipient {
5858    onRemoteDied() {
5859      hilog.info(0x0000, 'testTag', 'server died');
5860    }
5861  }
5862  class TestRemoteObject extends rpc.RemoteObject {
5863    constructor(descriptor: string) {
5864      super(descriptor);
5865      this.attachLocalInterface(this, descriptor);
5866    }
5867    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5868      return true;
5869    }
5870    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5871      return true;
5872    }
5873    isObjectDead(): boolean {
5874      return false;
5875    }
5876    asObject(): rpc.IRemoteObject {
5877      return this;
5878    }
5879  }
5880  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
5881  let data = rpc.MessageParcel.create();
5882  data.writeRemoteObjectArray(a);
5883  let b: Array<rpc.IRemoteObject> = new Array(3);
5884  data.readRemoteObjectArray(b);
5885  ```
5886
5887### readRemoteObjectArray<sup>8+</sup>
5888
5889readRemoteObjectArray(): IRemoteObject[]
5890
5891Reads the **IRemoteObject** array from this **MessageParcel** object.
5892
5893**System capability**: SystemCapability.Communication.IPC.Core
5894
5895**Return value**
5896
5897| Type           | Description                       |
5898| --------------- | --------------------------- |
5899| [IRemoteObject](#iremoteobject)[] | **IRemoteObject** object array obtained.|
5900
5901**Example**
5902
5903  ```ts
5904  import { hilog } from '@kit.PerformanceAnalysisKit';
5905
5906  class MyDeathRecipient implements rpc.DeathRecipient {
5907    onRemoteDied() {
5908      hilog.info(0x0000, 'testTag', 'server died');
5909    }
5910  }
5911  class TestRemoteObject extends rpc.RemoteObject {
5912    constructor(descriptor: string) {
5913      super(descriptor);
5914      this.attachLocalInterface(this, descriptor);
5915    }
5916    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5917      return true;
5918    }
5919    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5920      return true;
5921    }
5922    isObjectDead(): boolean {
5923      return false;
5924    }
5925    asObject(): rpc.IRemoteObject {
5926      return this;
5927    }
5928  }
5929  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
5930  let data = rpc.MessageParcel.create();
5931  let result = data.writeRemoteObjectArray(a);
5932  hilog.info(0x0000, 'testTag', 'RpcClient: readRemoteObjectArray is ' + result);
5933  let b = data.readRemoteObjectArray();
5934  hilog.info(0x0000, 'testTag', 'RpcClient: readRemoteObjectArray is ' + b);
5935  ```
5936
5937### closeFileDescriptor<sup>8+</sup>
5938
5939static closeFileDescriptor(fd: number): void
5940
5941Closes a file descriptor. This API is a static method.
5942
5943**System capability**: SystemCapability.Communication.IPC.Core
5944
5945**Parameters**
5946
5947| Name| Type  | Mandatory| Description                |
5948| ------ | ------ | ---- | -------------------- |
5949| fd     | number | Yes  | File descriptor to close.|
5950
5951**Example**
5952
5953  ```ts
5954  import { fileIo } from '@kit.CoreFileKit';
5955
5956  let filePath = "path/to/file";
5957  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
5958  rpc.MessageParcel.closeFileDescriptor(file.fd);
5959  ```
5960
5961### dupFileDescriptor<sup>8+</sup>
5962
5963static dupFileDescriptor(fd: number) :number
5964
5965Duplicates a file descriptor. This API is a static method.
5966
5967**System capability**: SystemCapability.Communication.IPC.Core
5968
5969**Parameters**
5970
5971| Name| Type  | Mandatory| Description                    |
5972| ------ | ------ | ---- | ------------------------ |
5973| fd     | number | Yes  | File descriptor to duplicate.|
5974
5975**Return value**
5976
5977| Type  | Description                |
5978| ------ | -------------------- |
5979| number | New file descriptor.|
5980
5981**Example**
5982
5983  ```ts
5984  import { fileIo } from '@kit.CoreFileKit';
5985
5986  let filePath = "path/to/file";
5987  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
5988  rpc.MessageParcel.dupFileDescriptor(file.fd);
5989  ```
5990
5991### containFileDescriptors<sup>8+</sup>
5992
5993containFileDescriptors(): boolean
5994
5995Checks whether this **MessageParcel** object contains file descriptors.
5996
5997**System capability**: SystemCapability.Communication.IPC.Core
5998
5999**Return value**
6000
6001| Type   | Description                                         |
6002| ------- | --------------------------------------------- |
6003| boolean |Returns **true** if the **MessageParcel** object contains file descriptors; returns **false** otherwise.|
6004
6005**Example**
6006
6007  ```ts
6008  import { fileIo } from '@kit.CoreFileKit';
6009  import { hilog } from '@kit.PerformanceAnalysisKit';
6010
6011  let parcel = new rpc.MessageParcel();
6012  let filePath = "path/to/file";
6013  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
6014  let writeResult = parcel.writeFileDescriptor(file.fd);
6015  hilog.info(0x0000, 'testTag', 'RpcTest: parcel writeFd result is ' + writeResult);
6016  let containFD = parcel.containFileDescriptors();
6017  hilog.info(0x0000, 'testTag', 'RpcTest: parcel after write fd containFd result is ' + containFD);
6018  ```
6019
6020### writeFileDescriptor<sup>8+</sup>
6021
6022writeFileDescriptor(fd: number): boolean
6023
6024Writes a file descriptor to this **MessageParcel** object.
6025
6026**System capability**: SystemCapability.Communication.IPC.Core
6027
6028**Parameters**
6029
6030| Name| Type  | Mandatory| Description        |
6031| ------ | ------ | ---- | ------------ |
6032| fd     | number | Yes  | File descriptor to write.|
6033
6034**Return value**
6035
6036| Type   | Description                            |
6037| ------- | -------------------------------- |
6038| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
6039
6040**Example**
6041
6042  ```ts
6043  import { fileIo } from '@kit.CoreFileKit';
6044  import { hilog } from '@kit.PerformanceAnalysisKit';
6045
6046  let parcel = new rpc.MessageParcel();
6047  let filePath = "path/to/file";
6048  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
6049  let writeResult = parcel.writeFileDescriptor(file.fd);
6050  hilog.info(0x0000, 'testTag', 'RpcTest: parcel writeFd result is ' + writeResult);
6051  ```
6052
6053### readFileDescriptor<sup>8+</sup>
6054
6055readFileDescriptor(): number
6056
6057Reads the file descriptor from this **MessageParcel** object.
6058
6059**System capability**: SystemCapability.Communication.IPC.Core
6060
6061**Return value**
6062
6063| Type  | Description            |
6064| ------ | ---------------- |
6065| number | File descriptor read.|
6066
6067**Example**
6068
6069  ```ts
6070  import { fileIo } from '@kit.CoreFileKit';
6071  import { hilog } from '@kit.PerformanceAnalysisKit';
6072
6073  let parcel = new rpc.MessageParcel();
6074  let filePath = "path/to/file";
6075  let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
6076  parcel.writeFileDescriptor(file.fd);
6077  let readFD = parcel.readFileDescriptor();
6078  hilog.info(0x0000, 'testTag', 'RpcTest: parcel read fd is ' + readFD);
6079  ```
6080
6081### writeAshmem<sup>8+</sup>
6082
6083writeAshmem(ashmem: Ashmem): boolean
6084
6085Writes an anonymous shared object to this **MessageParcel** object.
6086
6087**System capability**: SystemCapability.Communication.IPC.Core
6088
6089**Parameters**
6090
6091| Name| Type  | Mandatory| Description                               |
6092| ------ | ------ | ---- | ----------------------------------- |
6093| ashmem | [Ashmem](#ashmem8) | Yes  | Anonymous shared object to write.|
6094
6095**Return value**
6096
6097| Type   | Description                            |
6098| ------- | -------------------------------- |
6099| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
6100
6101**Example**
6102
6103  ```ts
6104  import { hilog } from '@kit.PerformanceAnalysisKit';
6105
6106  let parcel = new rpc.MessageParcel();
6107  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024);
6108  let isWriteSuccess = parcel.writeAshmem(ashmem);
6109  hilog.info(0x0000, 'testTag', 'RpcTest: write ashmem to result is ' + isWriteSuccess);
6110  ```
6111
6112### readAshmem<sup>8+</sup>
6113
6114readAshmem(): Ashmem
6115
6116Reads the anonymous shared object from this **MessageParcel** object.
6117
6118**System capability**: SystemCapability.Communication.IPC.Core
6119
6120**Return value**
6121
6122| Type  | Description              |
6123| ------ | ------------------ |
6124| [Ashmem](#ashmem8) | Anonymous share object obtained.|
6125
6126**Example**
6127
6128  ```ts
6129  import { hilog } from '@kit.PerformanceAnalysisKit';
6130
6131  let parcel = new rpc.MessageParcel();
6132  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024);
6133  let isWriteSuccess = parcel.writeAshmem(ashmem);
6134  hilog.info(0x0000, 'testTag', 'RpcTest: write ashmem to result is ' + isWriteSuccess);
6135  let readAshmem = parcel.readAshmem();
6136  hilog.info(0x0000, 'testTag', 'RpcTest: read ashmem to result is ' + readAshmem);
6137  ```
6138
6139### getRawDataCapacity<sup>8+</sup>
6140
6141getRawDataCapacity(): number
6142
6143Obtains the maximum amount of raw data that can be held by this **MessageParcel** object.
6144
6145**System capability**: SystemCapability.Communication.IPC.Core
6146
6147**Return value**
6148
6149| Type  | Description                                                      |
6150| ------ | ---------------------------------------------------------- |
6151| number | Maximum amount of raw data that **MessageParcel** can hold, that is, 128 MB.|
6152
6153**Example**
6154
6155  ```ts
6156  import { hilog } from '@kit.PerformanceAnalysisKit';
6157
6158  let parcel = new rpc.MessageParcel();
6159  let result = parcel.getRawDataCapacity();
6160  hilog.info(0x0000, 'testTag', 'RpcTest: parcel get RawDataCapacity result is ' + result);
6161  ```
6162
6163### writeRawData<sup>8+</sup>
6164
6165writeRawData(rawData: number[], size: number): boolean
6166
6167Writes raw data to this **MessageParcel** object.
6168
6169**System capability**: SystemCapability.Communication.IPC.Core
6170
6171**Parameters**
6172
6173| Name | Type    | Mandatory| Description                              |
6174| ------- | -------- | ---- | ---------------------------------- |
6175| rawData | number[] | Yes  | Raw data to write.                |
6176| size    | number   | Yes  | Size of the raw data, in bytes.|
6177
6178**Return value**
6179
6180| Type   | Description                            |
6181| ------- | -------------------------------- |
6182| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
6183
6184**Example**
6185
6186  ```ts
6187  import { hilog } from '@kit.PerformanceAnalysisKit';
6188
6189  let parcel = new rpc.MessageParcel();
6190  let arr = [1, 2, 3, 4, 5];
6191  let isWriteSuccess = parcel.writeRawData(arr, arr.length);
6192  hilog.info(0x0000, 'testTag', 'RpcTest: parcel write raw data result is ' + isWriteSuccess);
6193  ```
6194
6195### readRawData<sup>8+</sup>
6196
6197readRawData(size: number): number[]
6198
6199Reads raw data from this **MessageParcel** object.
6200
6201**System capability**: SystemCapability.Communication.IPC.Core
6202
6203**Parameters**
6204
6205| Name| Type  | Mandatory| Description                    |
6206| ------ | ------ | ---- | ------------------------ |
6207| size   | number | Yes  | Size of the raw data to read.|
6208
6209**Return value**
6210
6211| Type    | Description                          |
6212| -------- | ------------------------------ |
6213| number[] | Raw data obtained, in bytes.|
6214
6215**Example**
6216
6217  ```ts
6218  import { hilog } from '@kit.PerformanceAnalysisKit';
6219
6220  let parcel = new rpc.MessageParcel();
6221  let arr = [1, 2, 3, 4, 5];
6222  let isWriteSuccess = parcel.writeRawData(arr, arr.length);
6223  hilog.info(0x0000, 'testTag', 'RpcTest: parcel write raw data result is ' + isWriteSuccess);
6224  let result = parcel.readRawData(5);
6225  hilog.info(0x0000, 'testTag', 'RpcTest: parcel read raw data result is ' + result);
6226  ```
6227
6228## Parcelable<sup>9+</sup>
6229
6230Writes an object to a **MessageSequence** and reads it from the **MessageSequence** during IPC.
6231
6232### marshalling
6233
6234marshalling(dataOut: MessageSequence): boolean
6235
6236Marshals this **Parcelable** object into a **MessageSequence** object.
6237
6238**System capability**: SystemCapability.Communication.IPC.Core
6239
6240**Parameters**
6241
6242| Name | Type           | Mandatory| Description                                       |
6243| ------- | --------------- | ---- | ------------------------------------------- |
6244| dataOut |[MessageSequence](#messagesequence9)| Yes  | **MessageSequence** object to which the **Parcelable** object is to be marshaled.|
6245
6246**Return value**
6247
6248| Type   | Description                            |
6249| ------- | -------------------------------- |
6250| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
6251
6252**Example**
6253
6254  ```ts
6255  import { hilog } from '@kit.PerformanceAnalysisKit';
6256
6257  class MyParcelable implements rpc.Parcelable {
6258    num: number = 0;
6259    str: string = '';
6260    constructor(num: number, str: string) {
6261      this.num = num;
6262      this.str = str;
6263    }
6264    marshalling(messageSequence: rpc.MessageSequence): boolean {
6265      messageSequence.writeInt(this.num);
6266      messageSequence.writeString(this.str);
6267      return true;
6268    }
6269    unmarshalling(messageSequence: rpc.MessageSequence): boolean {
6270      this.num = messageSequence.readInt();
6271      this.str = messageSequence.readString();
6272      return true;
6273    }
6274  }
6275  let parcelable = new MyParcelable(1, "aaa");
6276  let data = rpc.MessageSequence.create();
6277  let result = data.writeParcelable(parcelable);
6278  hilog.info(0x0000, 'testTag', 'RpcClient: writeParcelable is ' + result);
6279  let ret = new MyParcelable(0, "");
6280  let result2 = data.readParcelable(ret);
6281  hilog.info(0x0000, 'testTag', 'RpcClient: readParcelable is ' + result2);
6282  ```
6283
6284### unmarshalling
6285
6286unmarshalling(dataIn: MessageSequence): boolean
6287
6288Unmarshals this **Parcelable** object from a **MessageSequence** object.
6289
6290**System capability**: SystemCapability.Communication.IPC.Core
6291
6292**Parameters**
6293
6294| Name| Type           | Mandatory| Description                                           |
6295| ------ | --------------- | ---- | ----------------------------------------------- |
6296| dataIn | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object from which the **Parcelable** object is to be unmarshaled.|
6297
6298**Return value**
6299
6300| Type   | Description                                    |
6301| ------- | ---------------------------------------- |
6302| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
6303
6304**Example**
6305
6306  ```ts
6307  import { hilog } from '@kit.PerformanceAnalysisKit';
6308
6309  class MyParcelable implements rpc.Parcelable {
6310    num: number = 0;
6311    str: string = '';
6312    constructor(num: number, str: string) {
6313      this.num = num;
6314      this.str = str;
6315    }
6316    marshalling(messageSequence: rpc.MessageSequence): boolean {
6317      messageSequence.writeInt(this.num);
6318      messageSequence.writeString(this.str);
6319      return true;
6320    }
6321    unmarshalling(messageSequence: rpc.MessageSequence): boolean {
6322      this.num = messageSequence.readInt();
6323      this.str = messageSequence.readString();
6324      return true;
6325    }
6326  }
6327  let parcelable = new MyParcelable(1, "aaa");
6328  let data = rpc.MessageSequence.create();
6329  let result = data.writeParcelable(parcelable);
6330  hilog.info(0x0000, 'testTag', 'RpcClient: writeParcelable is ' + result);
6331  let ret = new MyParcelable(0, "");
6332  let result2 = data.readParcelable(ret);
6333  hilog.info(0x0000, 'testTag', 'RpcClient: readParcelable is ' + result2);
6334  ```
6335
6336## Sequenceable<sup>(deprecated)</sup>
6337
6338>**NOTE**<br>This class is no longer maintained since API version 9. Use [Parcelable](#parcelable9) instead.
6339
6340Writes objects of classes to a **MessageParcel** and reads them from the **MessageParcel** during IPC.
6341
6342### marshalling
6343
6344marshalling(dataOut: MessageParcel): boolean
6345
6346Marshals the sequenceable object into a **MessageParcel** object.
6347
6348**System capability**: SystemCapability.Communication.IPC.Core
6349
6350**Parameters**
6351
6352| Name | Type                                     | Mandatory| Description                                     |
6353| ------- | ----------------------------------------- | ---- | ----------------------------------------- |
6354| dataOut | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object to which the sequenceable object is to be marshaled.|
6355
6356**Return value**
6357
6358| Type   | Description                             |
6359| ------- | --------------------------------  |
6360| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
6361
6362**Example**
6363
6364  ```ts
6365  import { hilog } from '@kit.PerformanceAnalysisKit';
6366
6367  class MySequenceable implements rpc.Sequenceable {
6368    num: number = 0;
6369    str: string = '';
6370    constructor(num: number, str: string) {
6371      this.num = num;
6372      this.str = str;
6373    }
6374    marshalling(messageParcel: rpc.MessageParcel): boolean {
6375      messageParcel.writeInt(this.num);
6376      messageParcel.writeString(this.str);
6377      return true;
6378    }
6379    unmarshalling(messageParcel: rpc.MessageParcel): boolean {
6380      this.num = messageParcel.readInt();
6381      this.str = messageParcel.readString();
6382      return true;
6383    }
6384  }
6385  let sequenceable = new MySequenceable(1, "aaa");
6386  let data = rpc.MessageParcel.create();
6387  let result = data.writeSequenceable(sequenceable);
6388  hilog.info(0x0000, 'testTag', 'RpcClient: writeSequenceable is ' + result);
6389  let ret = new MySequenceable(0, "");
6390  let result2 = data.readSequenceable(ret);
6391  hilog.info(0x0000, 'testTag', 'RpcClient: readSequenceable is ' + result2);
6392  ```
6393
6394### unmarshalling
6395
6396unmarshalling(dataIn: MessageParcel): boolean
6397
6398Unmarshals this sequenceable object from a **MessageParcel** object.
6399
6400**System capability**: SystemCapability.Communication.IPC.Core
6401
6402**Parameters**
6403
6404| Name| Type                                     | Mandatory| Description                                         |
6405| ------ | ----------------------------------------- | ---- | --------------------------------------------- |
6406| dataIn | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
6407
6408**Return value**
6409
6410| Type   | Description                                    |
6411| ------- | ---------------------------------------- |
6412| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
6413
6414**Example**
6415
6416  ```ts
6417  import { hilog } from '@kit.PerformanceAnalysisKit';
6418
6419  class MySequenceable implements rpc.Sequenceable {
6420    num: number = 0;
6421    str: string = '';
6422    constructor(num: number, str: string) {
6423      this.num = num;
6424      this.str = str;
6425    }
6426    marshalling(messageParcel: rpc.MessageParcel): boolean {
6427      messageParcel.writeInt(this.num);
6428      messageParcel.writeString(this.str);
6429      return true;
6430    }
6431    unmarshalling(messageParcel: rpc.MessageParcel): boolean {
6432      this.num = messageParcel.readInt();
6433      this.str = messageParcel.readString();
6434      return true;
6435    }
6436  }
6437  let sequenceable = new MySequenceable(1, "aaa");
6438  let data = rpc.MessageParcel.create();
6439  let result = data.writeSequenceable(sequenceable);
6440  hilog.info(0x0000, 'testTag', 'RpcClient: writeSequenceable is ' + result);
6441  let ret = new MySequenceable(0, "");
6442  let result2 = data.readSequenceable(ret);
6443  hilog.info(0x0000, 'testTag', 'RpcClient: readSequenceable is ' + result2);
6444  ```
6445
6446## IRemoteBroker
6447
6448Provides the holder of a remote proxy object.
6449
6450### asObject
6451
6452asObject(): IRemoteObject
6453
6454Obtains a proxy or remote object. This API must be implemented by its derived classes.
6455
6456**System capability**: SystemCapability.Communication.IPC.Core
6457
6458**Return value**
6459
6460| Type | Description |
6461| ----- | ----- |
6462| [IRemoteObject](#iremoteobject) | Returns the **RemoteObject** if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.|
6463
6464**Example**
6465
6466  ```ts
6467  class TestAbility extends rpc.RemoteObject {
6468    asObject() {
6469      return this;
6470    }
6471  }
6472  let remoteObject = new TestAbility("testObject").asObject();
6473  ```
6474
6475**Example**
6476
6477  ```ts
6478  // If the FA model is used, import featureAbility from @kit.AbilityKit.
6479  // import { featureAbility } from '@kit.AbilityKit';
6480  import { Want, common } from '@kit.AbilityKit';
6481  import { hilog } from '@kit.PerformanceAnalysisKit';
6482
6483  let proxy: rpc.IRemoteObject | undefined;
6484  let connect: common.ConnectOptions = {
6485    onConnect: (elementName, remoteProxy) => {
6486      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
6487      proxy = remoteProxy;
6488    },
6489    onDisconnect: (elementName) => {
6490      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
6491    },
6492    onFailed: () => {
6493      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
6494    }
6495  };
6496  let want: Want  = {
6497    bundleName: "com.ohos.server",
6498    abilityName: "com.ohos.server.EntryAbility",
6499  };
6500
6501  // Use this method to connect to the ability for the FA model.
6502  // FA.connectAbility(want,connect);
6503
6504  // Save the connection ID, which will be used for the subsequent service disconnection.
6505  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
6506  // Save the connection ID, which will be used for the subsequent service disconnection.
6507  let connectionId = context.connectServiceExtensionAbility(want, connect);
6508  ```
6509
6510  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **asObject()** of the proxy object is called to obtain the proxy or remote object.
6511
6512  ```ts
6513  class TestProxy {
6514    remote: rpc.IRemoteObject;
6515    constructor(remote: rpc.IRemoteObject) {
6516      this.remote = remote;
6517    }
6518    asObject() {
6519      return this.remote;
6520    }
6521  }
6522  if (proxy != undefined) {
6523    let iRemoteObject = new TestProxy(proxy).asObject();
6524  }
6525  ```
6526
6527## DeathRecipient
6528
6529Subscribes to death notifications of a remote object. When the remote object is dead, the local end will receive a notification and **[onRemoteDied](#onremotedied)** will be called. A remote object is dead when the process holding the object is terminated or the device of the remote object is shut down or restarted. If the local and remote objects belong to different devices, the remote object is dead when the device holding the remote object is detached from the network. 
6530
6531### onRemoteDied
6532
6533onRemoteDied(): void
6534
6535Called to perform subsequent operations when a death notification of the remote object is received.
6536
6537**System capability**: SystemCapability.Communication.IPC.Core
6538
6539**Example**
6540
6541  ```ts
6542  import { hilog } from '@kit.PerformanceAnalysisKit';
6543
6544  class MyDeathRecipient implements rpc.DeathRecipient {
6545    onRemoteDied() {
6546      hilog.info(0x0000, 'testTag', 'server died');
6547    }
6548  }
6549  ```
6550
6551## RequestResult<sup>9+</sup>
6552
6553Defines the response to the request.
6554
6555**System capability**: SystemCapability.Communication.IPC.Core
6556
6557| Name   | Type           | Readable| Writable| Description                                 |
6558| ------- | --------------- | ---- | ---- |-------------------------------------- |
6559| errCode | number          | Yes  | No  | Error code.                             |
6560| code    | number          | Yes  | No  | Message code.                           |
6561| data    | [MessageSequence](#messagesequence9) | Yes  | No  | **MessageSequence** object sent to the remote process.|
6562| reply   | [MessageSequence](#messagesequence9) | Yes  | No  | **MessageSequence** object returned by the remote process.  |
6563
6564## SendRequestResult<sup>8+(deprecated)</sup>
6565
6566>**NOTE**<br>This API is no longer maintained since API version 9. Use [RequestResult](#requestresult9) instead.
6567
6568Defines the response to the request.
6569
6570**System capability**: SystemCapability.Communication.IPC.Core
6571
6572| Name   | Type         | Readable| Writable| Description                               |
6573| ------- | ------------- | ---- | ---- | ----------------------------------- |
6574| errCode | number        | Yes  | No  | Error code.                           |
6575| code    | number        | Yes  | No  | Message code.                         |
6576| data    | [MessageParcel](#messageparceldeprecated) | Yes  | No  | **MessageParcel** object sent to the remote process.|
6577| reply   | [MessageParcel](#messageparceldeprecated) | Yes  | No  | **MessageParcel** object returned by the remote process.  |
6578
6579## IRemoteObject
6580
6581Provides methods to query of obtain interface descriptors, add or delete death notifications, dump object status to specific files, and send messages.
6582
6583### getLocalInterface<sup>9+</sup>
6584
6585getLocalInterface(descriptor: string): IRemoteBroker
6586
6587Obtains the string of the interface descriptor.
6588
6589**System capability**: SystemCapability.Communication.IPC.Core
6590
6591**Parameters**
6592
6593| Name    | Type  | Mandatory| Description                |
6594| ---------- | ------ | ---- | -------------------- |
6595| descriptor | string | Yes  | Interface descriptor.|
6596
6597**Return value**
6598
6599| Type         | Description                                         |
6600| ------------- | --------------------------------------------- |
6601| [IRemoteBroker](#iremotebroker) | **IRemoteBroker** object bound to the specified interface token.|
6602
6603**Error codes**
6604
6605For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
6606
6607| ID| Error Message|
6608| -------- | -------- |
6609| 401      | check param failed |
6610
6611### queryLocalInterface<sup>(deprecated)</sup>
6612
6613>**NOTE**<br>This API is no longer maintained since API version 9. Use [getLocalInterface](#getlocalinterface9) instead.
6614
6615queryLocalInterface(descriptor: string): IRemoteBroker
6616
6617Queries the string of the interface descriptor.
6618
6619**System capability**: SystemCapability.Communication.IPC.Core
6620
6621**Parameters**
6622
6623| Name    | Type  | Mandatory| Description                |
6624| ---------- | ------ | ---- | -------------------- |
6625| descriptor | string | Yes  | Interface descriptor.|
6626
6627**Return value**
6628
6629| Type         | Description                                         |
6630| ------------- | --------------------------------------------- |
6631| [IRemoteBroker](#iremotebroker) | **IRemoteBroker** object bound to the specified interface token.|
6632
6633### sendRequest<sup>(deprecated)</sup>
6634
6635>**NOTE**<br>This API is no longer maintained since API version 8. Use [sendMessageRequest](#sendmessagerequest9) instead.
6636
6637sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
6638
6639Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message does not contain any content. If synchronous mode is set in **options** , a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
6640
6641**System capability**: SystemCapability.Communication.IPC.Core
6642
6643**Parameters**
6644
6645| Name | Type                                     | Mandatory| Description                                                                                  |
6646| ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
6647| code    | number                                    | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6648| data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
6649| reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
6650| options | [MessageOption](#messageoption)           | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6651
6652**Return value**
6653
6654| Type   | Description                            |
6655| ------- | -------------------------------- |
6656| boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
6657
6658### sendMessageRequest<sup>9+</sup>
6659
6660sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
6661
6662Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
6663
6664**System capability**: SystemCapability.Communication.IPC.Core
6665
6666**Parameters**
6667
6668| Name | Type                                | Mandatory| Description                                                                                  |
6669| ------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- |
6670| code    | number                               | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6671| data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
6672| reply   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
6673| options | [MessageOption](#messageoption)      | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6674
6675**Return value**
6676
6677| Type                        | Description                                     |
6678| ---------------------------- | ----------------------------------------- |
6679| Promise&lt;[RequestResult](#requestresult9)&gt; | Promise used to return the **requestResult** object.|
6680
6681**Error codes**
6682
6683For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
6684
6685| ID| Error Message|
6686| -------- | -------- |
6687| 401      | check param failed |
6688
6689### sendRequest<sup>8+(deprecated)</sup>
6690
6691>**NOTE**<br>This API is no longer maintained since API version 9. Use [sendMessageRequest](#sendmessagerequest9) instead.
6692
6693sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
6694
6695Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
6696
6697**System capability**: SystemCapability.Communication.IPC.Core
6698
6699**Parameters**
6700
6701| Name | Type                                     | Mandatory| Description                                                                                  |
6702| ------- | ----------------------------------------  | ---- | -------------------------------------------------------------------------------------- |
6703| code    | number                                    | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6704| data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                              |
6705| reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
6706| options | [MessageOption](#messageoption)           | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6707
6708**Return value**
6709
6710| Type                                                        | Description                                         |
6711| ------------------------------------------------------------ | --------------------------------------------- |
6712| Promise&lt;[SendRequestResult](#sendrequestresult8deprecated)&gt; | Promise used to return the **sendRequestResult** object.|
6713
6714### sendMessageRequest<sup>9+</sup>
6715
6716sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void
6717
6718Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
6719
6720**System capability**: SystemCapability.Communication.IPC.Core
6721
6722**Parameters**
6723
6724| Name  | Type                                | Mandatory| Description                                                                                  |
6725| -------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- |
6726| code     | number                               | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6727| data     | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                            |
6728| reply    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
6729| options  | [MessageOption](#messageoption)      | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6730| callback | AsyncCallback&lt;[RequestResult](#requestresult9)&gt;   | Yes  | Callback for receiving the sending result.                                                                  |
6731
6732**Error codes**
6733
6734For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
6735
6736| ID| Error Message|
6737| -------- | -------- |
6738| 401      | check param failed |
6739
6740### sendRequest<sup>8+(deprecated)</sup>
6741
6742>**NOTE**<br>This API is no longer maintained since API version 9. Use [sendMessageRequest](#sendmessagerequest9-1) instead.
6743
6744sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void
6745
6746Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
6747
6748**System capability**: SystemCapability.Communication.IPC.Core
6749
6750**Parameters**
6751
6752| Name  | Type                                                        | Mandatory| Description                                                        |
6753| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6754| code     | number                                                       | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6755| data     | [MessageParcel](#messageparceldeprecated)                    | Yes  | **MessageParcel** object holding the data to send.                    |
6756| reply    | [MessageParcel](#messageparceldeprecated)                    | Yes  | **MessageParcel** object that receives the response.                           |
6757| options  | [MessageOption](#messageoption)                              | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                        |
6758| callback | AsyncCallback&lt;[SendRequestResult](#sendrequestresult8deprecated)&gt; | Yes  | Callback for receiving the sending result.                                        |
6759
6760### registerDeathRecipient<sup>9+</sup>
6761
6762registerDeathRecipient(recipient: DeathRecipient, flags: number): void
6763
6764Registers a callback for receiving death notifications of the remote object. The callback will be called if the remote object process matching the **RemoteProxy** object is killed.
6765
6766**System capability**: SystemCapability.Communication.IPC.Core
6767
6768**Parameters**
6769
6770| Name   | Type                             | Mandatory| Description          |
6771| --------- | --------------------------------- | ---- | -------------- |
6772| recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to register.|
6773| flags     | number                            | Yes  | Flag of the death notification.|
6774
6775**Error codes**
6776
6777For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
6778
6779| ID| Error Message|
6780| -------- | -------- |
6781| 401      | check param failed |
6782| 1900008  | proxy or remote object is invalid |
6783
6784### addDeathrecipient<sup>(deprecated)</sup>
6785
6786>**NOTE**<br>This API is no longer maintained since API version 9. Use [registerDeathRecipient](#registerdeathrecipient9) instead.
6787
6788addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
6789
6790Adds a callback for receiving death notifications of the remote object. This method is called if the remote object process matching the **RemoteProxy** object is killed.
6791
6792**System capability**: SystemCapability.Communication.IPC.Core
6793
6794**Parameters**
6795
6796| Name   | Type                             | Mandatory| Description          |
6797| --------- | --------------------------------- | ---- | -------------- |
6798| recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.|
6799| flags     | number                            | Yes  | Flag of the death notification.|
6800
6801**Return value**
6802
6803| Type   | Description                                    |
6804| ------- | ---------------------------------------- |
6805| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
6806
6807### unregisterDeathRecipient<sup>9+</sup>
6808
6809unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void
6810
6811Unregisters the callback used to receive death notifications of the remote object.
6812
6813**System capability**: SystemCapability.Communication.IPC.Core
6814
6815**Parameters**
6816
6817| Name   | Type                             | Mandatory| Description          |
6818| --------- | --------------------------------- | ---- | -------------- |
6819| recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to unregister.|
6820| flags     | number                            | Yes  | Flag of the death notification.|
6821
6822**Error codes**
6823
6824For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
6825
6826| ID| Error Message|
6827| -------- | -------- |
6828| 401      | check param failed |
6829| 1900008  | proxy or remote object is invalid |
6830
6831### removeDeathRecipient<sup>(deprecated)</sup>
6832
6833>**NOTE**<br>This API is no longer maintained since API version 9. Use [unregisterDeathRecipient](#unregisterdeathrecipient9) instead.
6834
6835removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
6836
6837Removes the callback used to receive death notifications of the remote object.
6838
6839**System capability**: SystemCapability.Communication.IPC.Core
6840
6841**Parameters**
6842
6843| Name   | Type                             | Mandatory| Description          |
6844| --------- | --------------------------------- | ---- | -------------- |
6845| recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.|
6846| flags     | number                            | Yes  | Flag of the death notification.|
6847
6848**Return value**
6849
6850| Type   | Description                                    |
6851| ------- | -----------------------------------------|
6852| boolean | Returns **true** if the callback is removed; returns **false** otherwise.|
6853
6854### getDescriptor<sup>9+</sup>
6855
6856getDescriptor(): string
6857
6858Obtains the interface descriptor (which is a string) of this object.
6859
6860**System capability**: SystemCapability.Communication.IPC.Core
6861
6862**Return value**
6863
6864| Type  | Description            |
6865| ------ | ---------------- |
6866| string | Interface descriptor obtained.|
6867
6868**Error codes**
6869
6870For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
6871
6872| ID| Error Message|
6873| -------- | -------- |
6874| 1900008  | proxy or remote object is invalid |
6875
6876### getInterfaceDescriptor<sup>(deprecated)</sup>
6877
6878>**NOTE**<br>This API is no longer maintained since API version 9. Use [getDescriptor](#getdescriptor9) instead.
6879
6880getInterfaceDescriptor(): string
6881
6882Obtains the interface descriptor (which is a string) of this object.
6883
6884**System capability**: SystemCapability.Communication.IPC.Core
6885
6886**Return value**
6887
6888| Type  | Description            |
6889| ------ | ---------------- |
6890| string | Interface descriptor obtained.|
6891
6892### isObjectDead
6893
6894isObjectDead(): boolean
6895
6896Checks whether this object is dead.
6897
6898**System capability**: SystemCapability.Communication.IPC.Core
6899
6900**Return value**
6901
6902| Type   | Description                              |
6903| ------- | ---------------------------------- |
6904| boolean | Returns **true** if the object is dead; returns **false** otherwise.|
6905
6906
6907
6908## RemoteProxy
6909
6910Provides APIs to implement **IRemoteObject**.
6911
6912**System capability**: SystemCapability.Communication.IPC.Core
6913
6914| Name                 | Value                     | Description                             |
6915| --------------------- | ----------------------- | --------------------------------- |
6916| PING_TRANSACTION      | 1599098439 (0x5f504e47) | Internal instruction code used to test whether the IPC service is normal.|
6917| DUMP_TRANSACTION      | 1598311760 (0x5f444d50) | Internal instruction code used to obtain the internal status of the binder. |
6918| INTERFACE_TRANSACTION | 1598968902 (0x5f4e5446) | Internal instruction code used to obtain the remote interface token. |
6919| MIN_TRANSACTION_ID    | 1 (0x00000001)          | Minimum valid instruction code.                 |
6920| MAX_TRANSACTION_ID    | 16777215 (0x00FFFFFF)   | Maximum valid instruction code.                 |
6921
6922### sendRequest<sup>(deprecated)</sup>
6923
6924>**NOTE**<br>This API is no longer maintained since API version 8. Use [sendMessageRequest](#sendmessagerequest9-2) instead.
6925
6926sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
6927
6928Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
6929
6930**System capability**: SystemCapability.Communication.IPC.Core
6931
6932**Parameters**
6933
6934| Name | Type                                     | Mandatory| Description                                                                                  |
6935| ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
6936| code    | number                                    | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6937| data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
6938| reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
6939| options | [MessageOption](#messageoption)           | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6940
6941**Return value**
6942
6943| Type   | Description                            |
6944| ------- | ---------------------------------|
6945| boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
6946
6947**Example**
6948
6949  ```ts
6950  // If the FA model is used, import featureAbility from @kit.AbilityKit.
6951  // import { featureAbility } from '@kit.AbilityKit';
6952  import { Want, common } from '@kit.AbilityKit';
6953  import { hilog } from '@kit.PerformanceAnalysisKit';
6954
6955  let proxy: rpc.IRemoteObject | undefined;
6956  let connect: common.ConnectOptions = {
6957     onConnect: (elementName, remoteProxy) => {
6958        hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
6959        proxy = remoteProxy;
6960     },
6961     onDisconnect: (elementName) => {
6962        hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
6963     },
6964     onFailed: () => {
6965        hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
6966     }
6967  };
6968  let want: Want = {
6969    bundleName: "com.ohos.server",
6970    abilityName: "com.ohos.server.EntryAbility",
6971  };
6972
6973  // Use this method to connect to the ability for the FA model.
6974  // FA.connectAbility(want,connect);
6975
6976  // Save the connection ID, which will be used for the subsequent service disconnection.
6977  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
6978  // Save the connection ID, which will be used for the subsequent service disconnection.
6979  let connectionId = context.connectServiceExtensionAbility(want, connect);
6980  ```
6981
6982  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
6983
6984  ```ts
6985  import { hilog } from '@kit.PerformanceAnalysisKit';
6986
6987  let option = new rpc.MessageOption();
6988  let data = rpc.MessageParcel.create();
6989  let reply = rpc.MessageParcel.create();
6990  data.writeInt(1);
6991  data.writeString("hello");
6992  if (proxy != undefined) {
6993    let ret: boolean = proxy.sendRequest(1, data, reply, option);
6994    if (ret) {
6995    hilog.info(0x0000, 'testTag', 'sendRequest got result');
6996    let msg = reply.readString();
6997    hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
6998    } else {
6999      hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed');
7000    }
7001    hilog.info(0x0000, 'testTag', 'RPCTest: sendRequest ends, reclaim parcel');
7002    data.reclaim();
7003    reply.reclaim();
7004  }
7005  ```
7006
7007### sendMessageRequest<sup>9+</sup>
7008
7009sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
7010
7011Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
7012
7013**System capability**: SystemCapability.Communication.IPC.Core
7014
7015**Parameters**
7016
7017| Name | Type                                | Mandatory| Description                                                                                  |
7018| ------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- |
7019| code    | number                               | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7020| data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
7021| reply   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
7022| options | [MessageOption](#messageoption)      | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
7023
7024**Return value**
7025
7026| Type                        | Description                                     |
7027| ---------------------------- | ----------------------------------------- |
7028| Promise&lt;[RequestResult](#requestresult9)&gt; | Promise used to return a **requestResult** instance.|
7029
7030
7031**Error codes**
7032
7033For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
7034
7035| ID| Error Message|
7036| -------- | -------- |
7037| 401      | check param failed |
7038
7039**Example**
7040
7041  ```ts
7042  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7043  // import { featureAbility } from '@kit.AbilityKit';
7044  import { Want, common } from '@kit.AbilityKit';
7045  import { hilog } from '@kit.PerformanceAnalysisKit';
7046
7047  let proxy: rpc.IRemoteObject | undefined;
7048  let connect: common.ConnectOptions = {
7049    onConnect: (elementName, remoteProxy) => {
7050      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7051      proxy = remoteProxy;
7052    },
7053    onDisconnect: (elementName) => {
7054      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7055    },
7056    onFailed: () => {
7057      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7058    }
7059  };
7060  let want: Want = {
7061    bundleName: "com.ohos.server",
7062    abilityName: "com.ohos.server.EntryAbility",
7063  };
7064
7065  // Use this method to connect to the ability for the FA model.
7066  // FA.connectAbility(want,connect);
7067
7068  // Save the connection ID, which will be used for the subsequent service disconnection.
7069  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7070  // Save the connection ID, which will be used for the subsequent service disconnection.
7071  let connectionId = context.connectServiceExtensionAbility(want, connect);
7072  ```
7073
7074  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
7075
7076  ```ts
7077  import { hilog } from '@kit.PerformanceAnalysisKit';
7078
7079  let option = new rpc.MessageOption();
7080  let data = rpc.MessageSequence.create();
7081  let reply = rpc.MessageSequence.create();
7082  data.writeInt(1);
7083  data.writeString("hello");
7084  if (proxy != undefined) {
7085    proxy.sendMessageRequest(1, data, reply, option)
7086    .then((result: rpc.RequestResult) => {
7087      if (result.errCode === 0) {
7088        hilog.info(0x0000, 'testTag', 'sendMessageRequest got result');
7089        let num = result.reply.readInt();
7090        let msg = result.reply.readString();
7091        hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
7092        hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
7093      } else {
7094        hilog.error(0x0000, 'testTag', 'RPCTest: sendMessageRequest failed, errCode: ' + result.errCode);
7095      }
7096    }).catch((e: Error) => {
7097      hilog.error(0x0000, 'testTag', 'RPCTest: sendMessageRequest failed, message: ' + e.message);
7098    }).finally (() => {
7099      hilog.info(0x0000, 'testTag', 'RPCTest: sendMessageRequest ends, reclaim parcel');
7100      data.reclaim();
7101      reply.reclaim();
7102    });
7103  }
7104  ```
7105
7106### sendRequest<sup>8+(deprecated)</sup>
7107
7108>**NOTE**<br>This API is no longer maintained since API version 9. Use [sendMessageRequest](#sendmessagerequest9-2) instead.
7109
7110sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
7111
7112Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
7113
7114**System capability**: SystemCapability.Communication.IPC.Core
7115
7116**Parameters**
7117
7118| Name | Type                                     | Mandatory| Description                                                                                  |
7119| ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
7120| code    | number                                    | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7121| data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
7122| reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
7123| options | [MessageOption](#messageoption)           | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
7124
7125**Return value**
7126
7127| Type                                                        | Description                                         |
7128| ------------------------------------------------------------ | --------------------------------------------- |
7129| Promise&lt;[SendRequestResult](#sendrequestresult8deprecated)&gt; | Promise used to return a **sendRequestResult** instance.|
7130
7131**Example**
7132
7133  ```ts
7134  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7135  // import { featureAbility } from '@kit.AbilityKit';
7136  import { Want, common } from '@kit.AbilityKit';
7137  import { hilog } from '@kit.PerformanceAnalysisKit';
7138
7139  let proxy: rpc.IRemoteObject | undefined;
7140  let connect: common.ConnectOptions = {
7141    onConnect: (elementName, remoteProxy) => {
7142      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7143      proxy = remoteProxy;
7144    },
7145    onDisconnect: (elementName) => {
7146      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7147    },
7148    onFailed: () => {
7149      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7150    }
7151  };
7152  let want: Want = {
7153    bundleName: "com.ohos.server",
7154    abilityName: "com.ohos.server.EntryAbility",
7155  };
7156
7157  // Use this method to connect to the ability for the FA model.
7158  // FA.connectAbility(want,connect);
7159
7160  // Save the connection ID, which will be used for the subsequent service disconnection.
7161  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7162  // Save the connection ID, which will be used for the subsequent service disconnection.
7163  let connectionId = context.connectServiceExtensionAbility(want, connect);
7164  ```
7165
7166  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
7167
7168  ```ts
7169  import { hilog } from '@kit.PerformanceAnalysisKit';
7170
7171  let option = new rpc.MessageOption();
7172  let data = rpc.MessageParcel.create();
7173  let reply = rpc.MessageParcel.create();
7174  data.writeInt(1);
7175  data.writeString("hello");
7176  if (proxy != undefined) {
7177    let a = proxy.sendRequest(1, data, reply, option) as Object;
7178    let b = a as Promise<rpc.SendRequestResult>;
7179    b.then((result: rpc.SendRequestResult) => {
7180      if (result.errCode === 0) {
7181        hilog.info(0x0000, 'testTag', 'sendRequest got result');
7182        let num = result.reply.readInt();
7183        let msg = result.reply.readString();
7184        hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
7185        hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
7186      } else {
7187        hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed, errCode: ' + result.errCode);
7188      }
7189    }).catch((e: Error) => {
7190      hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed, message: ' + e.message);
7191    }).finally (() => {
7192      hilog.info(0x0000, 'testTag', 'RPCTest: sendRequest ends, reclaim parcel');
7193      data.reclaim();
7194      reply.reclaim();
7195    });
7196  }
7197  ```
7198
7199### sendMessageRequest<sup>9+</sup>
7200
7201sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void
7202
7203Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked at certain time after the response to **sendMessageRequest** is returned, and the reply contains the returned information.
7204
7205**System capability**: SystemCapability.Communication.IPC.Core
7206
7207**Parameters**
7208
7209| Name  | Type                                | Mandatory| Description                                                                                  |
7210| -------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- |
7211| code     | number                               | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7212| data     | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
7213| reply    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
7214| options  | [MessageOption](#messageoption)      | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
7215| callback | AsyncCallback&lt;[RequestResult](#requestresult9)&gt;   | Yes  | Callback for receiving the sending result.                                                                  |
7216
7217
7218**Error codes**
7219
7220For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
7221
7222| ID| Error Message|
7223| -------- | -------- |
7224| 401      | check param failed |
7225
7226**Example**
7227
7228  ```ts
7229  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7230  // import { featureAbility } from '@kit.AbilityKit';
7231  import { Want, common } from '@kit.AbilityKit';
7232  import { hilog } from '@kit.PerformanceAnalysisKit';
7233  import { BusinessError } from '@kit.BasicServicesKit';
7234
7235  let proxy: rpc.IRemoteObject | undefined;
7236  let connect: common.ConnectOptions = {
7237    onConnect: (elementName, remoteProxy) => {
7238      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7239      proxy = remoteProxy;
7240    },
7241    onDisconnect: (elementName) => {
7242      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7243    },
7244    onFailed: () => {
7245      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7246    }
7247  };
7248  let want: Want = {
7249    bundleName: "com.ohos.server",
7250    abilityName: "com.ohos.server.EntryAbility",
7251  };
7252  function sendMessageRequestCallback(err: BusinessError, result: rpc.RequestResult) {
7253    if (result.errCode === 0) {
7254      hilog.info(0x0000, 'testTag', 'sendMessageRequest got result');
7255      let num = result.reply.readInt();
7256      let msg = result.reply.readString();
7257      hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
7258      hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
7259    } else {
7260      hilog.error(0x0000, 'testTag', 'RPCTest: sendMessageRequest failed, errCode: ' + result.errCode);
7261    }
7262    hilog.info(0x0000, 'testTag', 'RPCTest: sendMessageRequest ends, reclaim parcel');
7263    result.data.reclaim();
7264    result.reply.reclaim();
7265}
7266
7267  // Use this method to connect to the ability for the FA model.
7268  // FA.connectAbility(want,connect);
7269
7270  // Save the connection ID, which will be used for the subsequent service disconnection.
7271  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7272  // Save the connection ID, which will be used for the subsequent service disconnection.
7273  let connectionId = context.connectServiceExtensionAbility(want, connect);
7274  ```
7275
7276  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
7277
7278  ```ts
7279  import { hilog } from '@kit.PerformanceAnalysisKit';
7280  import { BusinessError } from '@kit.BasicServicesKit';
7281
7282  let option = new rpc.MessageOption();
7283  let data = rpc.MessageSequence.create();
7284  let reply = rpc.MessageSequence.create();
7285  data.writeInt(1);
7286  data.writeString("hello");
7287  if (proxy != undefined) {
7288    try {
7289      proxy.sendMessageRequest(1, data, reply, option, sendMessageRequestCallback);
7290    } catch (error) {
7291      let e: BusinessError = error as BusinessError;
7292      hilog.error(0x0000, 'testTag', 'rpc sendMessageRequest fail, errorCode ' + e.code);
7293      hilog.error(0x0000, 'testTag', 'rpc sendMessageRequest fail, errorMessage ' + e.message);
7294    }
7295  }
7296  ```
7297
7298### sendRequest<sup>8+(deprecated)</sup>
7299
7300>**NOTE**<br>This API is no longer maintained since API version 9. Use [sendMessageRequest](#sendmessagerequest9-3) instead.
7301
7302sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void
7303
7304Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to **sendRequest** is returned, and the reply message contains the returned information.
7305
7306**System capability**: SystemCapability.Communication.IPC.Core
7307
7308**Parameters**
7309
7310| Name  | Type                                                        | Mandatory| Description                                                        |
7311| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7312| code     | number                                                       | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7313| data     | [MessageParcel](#messageparceldeprecated)                    | Yes  | **MessageParcel** object holding the data to send.                   |
7314| reply    | [MessageParcel](#messageparceldeprecated)                    | Yes  | **MessageParcel** object that receives the response.                           |
7315| options  | [MessageOption](#messageoption)                              | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                        |
7316| callback | AsyncCallback&lt;[SendRequestResult](#sendrequestresult8deprecated)&gt; | Yes  | Callback for receiving the sending result.                                        |
7317
7318**Example**
7319
7320  ```ts
7321  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7322  // import { featureAbility } from '@kit.AbilityKit';
7323  import { Want, common } from '@kit.AbilityKit';
7324  import { hilog } from '@kit.PerformanceAnalysisKit';
7325  import { BusinessError } from '@kit.BasicServicesKit';
7326
7327  let proxy: rpc.IRemoteObject | undefined;
7328  let connect: common.ConnectOptions = {
7329    onConnect: (elementName, remoteProxy) => {
7330      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7331      proxy = remoteProxy;
7332    },
7333    onDisconnect: (elementName) => {
7334      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7335    },
7336    onFailed: () => {
7337      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7338    }
7339  };
7340  let want: Want = {
7341      bundleName: "com.ohos.server",
7342      abilityName: "com.ohos.server.EntryAbility",
7343  };
7344  function sendRequestCallback(err: BusinessError, result: rpc.SendRequestResult) {
7345    if (result.errCode === 0) {
7346      hilog.info(0x0000, 'testTag', 'sendRequest got result');
7347      let num = result.reply.readInt();
7348      let msg = result.reply.readString();
7349      hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
7350      hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
7351    } else {
7352      hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed, errCode: ' + result.errCode);
7353    }
7354    hilog.info(0x0000, 'testTag', 'RPCTest: sendRequest ends, reclaim parcel');
7355    result.data.reclaim();
7356    result.reply.reclaim();
7357}
7358
7359  // Use this method to connect to the ability for the FA model.
7360  // FA.connectAbility(want,connect);
7361
7362  // Save the connection ID, which will be used for the subsequent service disconnection.
7363  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7364  // Save the connection ID, which will be used for the subsequent service disconnection.
7365  let connectionId = context.connectServiceExtensionAbility(want, connect);
7366  ```
7367
7368  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
7369
7370  ```ts
7371  let option = new rpc.MessageOption();
7372  let data = rpc.MessageParcel.create();
7373  let reply = rpc.MessageParcel.create();
7374  data.writeInt(1);
7375  data.writeString("hello");
7376  if (proxy != undefined) {
7377    proxy.sendRequest(1, data, reply, option, sendRequestCallback);
7378  }
7379  ```
7380
7381### getLocalInterface<sup>9+</sup>
7382
7383getLocalInterface(interface: string): IRemoteBroker
7384
7385Obtains the **LocalInterface** object of an interface token.
7386
7387**System capability**: SystemCapability.Communication.IPC.Core
7388
7389**Parameters**
7390
7391| Name   | Type  | Mandatory| Description                  |
7392| --------- | ------ | ---- | ---------------------- |
7393| interface | string | Yes  | Interface descriptor.|
7394
7395**Return value**
7396
7397| Type                           | Description                                      |
7398| ------------------------------- | ------------------------------------------ |
7399| [IRemoteBroker](#iremotebroker) | Returns **Null** by default, which indicates a proxy interface.|
7400
7401**Error codes**
7402
7403For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
7404
7405| ID| Error Message|
7406| -------- | -------- |
7407| 401      | check param failed |
7408| 1900006  | only remote object permitted |
7409
7410**Example**
7411
7412  ```ts
7413  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7414  // import { featureAbility } from '@kit.AbilityKit';
7415  import { Want, common } from '@kit.AbilityKit';
7416  import { hilog } from '@kit.PerformanceAnalysisKit';
7417
7418  let proxy: rpc.IRemoteObject | undefined;
7419  let connect: common.ConnectOptions = {
7420    onConnect: (elementName, remoteProxy) => {
7421      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7422      proxy = remoteProxy;
7423    },
7424    onDisconnect: (elementName) => {
7425      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7426    },
7427    onFailed: () => {
7428      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7429    }
7430  };
7431  let want: Want = {
7432    bundleName: "com.ohos.server",
7433    abilityName: "com.ohos.server.EntryAbility",
7434  };
7435
7436  // Use this method to connect to the ability for the FA model.
7437  // FA.connectAbility(want,connect);
7438
7439  // Save the connection ID, which will be used for the subsequent service disconnection.
7440  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7441  // Save the connection ID, which will be used for the subsequent service disconnection.
7442  let connectionId = context.connectServiceExtensionAbility(want, connect);
7443  ```
7444
7445  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **getLocalInterface()** of the proxy object is called to obtain the interface descriptor.
7446
7447  ```ts
7448  import { hilog } from '@kit.PerformanceAnalysisKit';
7449  import { BusinessError } from '@kit.BasicServicesKit';
7450
7451  if (proxy != undefined) {
7452    try {
7453    let broker: rpc.IRemoteBroker = proxy.getLocalInterface("testObject");
7454    hilog.info(0x0000, 'testTag', 'RpcClient: getLocalInterface is ' + broker);
7455    } catch (error) {
7456      let e: BusinessError = error as BusinessError;
7457      hilog.error(0x0000, 'testTag', 'rpc get local interface fail, errorCode ' + e.code);
7458      hilog.error(0x0000, 'testTag', 'rpc get local interface fail, errorMessage ' + e.message);
7459    }
7460  }
7461  ```
7462
7463### queryLocalInterface<sup>(deprecated)</sup>
7464
7465>**NOTE**<br>This API is no longer maintained since API version 9. Use [getLocalInterface](#getlocalinterface9-1) instead.
7466
7467queryLocalInterface(interface: string): IRemoteBroker
7468
7469Obtains the **LocalInterface** object of an interface token.
7470
7471**System capability**: SystemCapability.Communication.IPC.Core
7472
7473**Parameters**
7474
7475| Name   | Type  | Mandatory| Description                  |
7476| --------- | ------ | ---- | ---------------------- |
7477| interface | string | Yes  | Interface descriptor.|
7478
7479**Return value**
7480
7481| Type                           | Description                                      |
7482| ------------------------------- | ------------------------------------------ |
7483| [IRemoteBroker](#iremotebroker) | Returns **Null** by default, which indicates a proxy interface.|
7484
7485**Example**
7486
7487  ```ts
7488  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7489  // import { featureAbility } from '@kit.AbilityKit';
7490  import { Want, common } from '@kit.AbilityKit';
7491  import { hilog } from '@kit.PerformanceAnalysisKit';
7492
7493  let proxy: rpc.IRemoteObject | undefined;
7494  let connect: common.ConnectOptions = {
7495    onConnect: (elementName, remoteProxy) => {
7496      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7497      proxy = remoteProxy;
7498    },
7499    onDisconnect: (elementName) => {
7500      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7501    },
7502    onFailed: () => {
7503      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7504    }
7505  };
7506  let want: Want = {
7507    bundleName: "com.ohos.server",
7508    abilityName: "com.ohos.server.EntryAbility",
7509  };
7510
7511  // Use this method to connect to the ability for the FA model.
7512  // FA.connectAbility(want,connect);
7513
7514  // Save the connection ID, which will be used for the subsequent service disconnection.
7515  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7516  // Save the connection ID, which will be used for the subsequent service disconnection.
7517  let connectionId = context.connectServiceExtensionAbility(want, connect);
7518  ```
7519
7520  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **queryLocalInterface()** of the proxy object is called to obtain the interface descriptor.
7521
7522  ```ts
7523  import { hilog } from '@kit.PerformanceAnalysisKit';
7524
7525  if (proxy != undefined) {
7526    let broker: rpc.IRemoteBroker = proxy.queryLocalInterface("testObject");
7527    hilog.info(0x0000, 'testTag', 'RpcClient: queryLocalInterface is ' + broker);
7528  }
7529  ```
7530
7531### registerDeathRecipient<sup>9+</sup>
7532
7533registerDeathRecipient(recipient: DeathRecipient, flags: number): void
7534
7535Registers a callback for receiving death notifications of the remote object. The callback will be invoked when the remote object process matching the **RemoteProxy** object is killed.
7536
7537**System capability**: SystemCapability.Communication.IPC.Core
7538
7539**Parameters**
7540
7541| Name   | Type                             | Mandatory| Description          |
7542| --------- | --------------------------------- | ---- | -------------- |
7543| recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to register.|
7544| flags     | number                            | Yes  | Flag of the death notification.|
7545
7546**Error codes**
7547
7548For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
7549
7550| ID| Error Message|
7551| -------- | -------- |
7552| 401      | check param failed |
7553| 1900008  | proxy or remote object is invalid |
7554
7555**Example**
7556
7557  ```ts
7558  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7559  // import { featureAbility } from '@kit.AbilityKit';
7560  import { Want, common } from '@kit.AbilityKit';
7561  import { hilog } from '@kit.PerformanceAnalysisKit';
7562
7563  let proxy: rpc.IRemoteObject | undefined;
7564  let connect: common.ConnectOptions = {
7565    onConnect: (elementName, remoteProxy) => {
7566      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7567      proxy = remoteProxy;
7568    },
7569    onDisconnect: (elementName) => {
7570      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7571    },
7572    onFailed: () => {
7573      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7574    }
7575  };
7576  let want: Want = {
7577    bundleName: "com.ohos.server",
7578    abilityName: "com.ohos.server.EntryAbility",
7579  };
7580
7581  // Use this method to connect to the ability for the FA model.
7582  // FA.connectAbility(want,connect);
7583
7584  // Save the connection ID, which will be used for the subsequent service disconnection.
7585  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7586  // Save the connection ID, which will be used for the subsequent service disconnection.
7587  let connectionId = context.connectServiceExtensionAbility(want, connect);
7588  ```
7589
7590The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **registerDeathRecipient()** of the proxy object is called to register a callback for receiving the death notification of the remote object.
7591
7592  ```ts
7593  import { hilog } from '@kit.PerformanceAnalysisKit';
7594  import { BusinessError } from '@kit.BasicServicesKit';
7595
7596  class MyDeathRecipient implements rpc.DeathRecipient {
7597    onRemoteDied() {
7598      hilog.info(0x0000, 'testTag', 'server died');
7599    }
7600  }
7601  let deathRecipient = new MyDeathRecipient();
7602  if (proxy != undefined) {
7603    try {
7604      proxy.registerDeathRecipient(deathRecipient, 0);
7605    } catch (error) {
7606      let e: BusinessError = error as BusinessError;
7607      hilog.error(0x0000, 'testTag', 'proxy register deathRecipient fail, errorCode ' + e.code);
7608      hilog.error(0x0000, 'testTag', 'proxy register deathRecipient fail, errorMessage ' + e.message);
7609    }
7610  }
7611  ```
7612
7613### addDeathRecipient<sup>(deprecated)</sup>
7614
7615>**NOTE**<br>This API is no longer maintained since API version 9. Use [registerDeathRecipient](#registerdeathrecipient9-1) instead.
7616
7617addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
7618
7619Adds a callback for receiving the death notifications of the remote object, including the death notifications of the remote proxy.
7620
7621**System capability**: SystemCapability.Communication.IPC.Core
7622
7623**Parameters**
7624
7625| Name   | Type                             | Mandatory| Description                             |
7626| --------- | --------------------------------- | ---- | --------------------------------- |
7627| recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.         |
7628| flags     | number                            | Yes  | Flag of the death notification. This parameter is reserved. It is set to **0**.|
7629
7630**Return value**
7631
7632| Type   | Description                                    |
7633| ------- | ---------------------------------------- |
7634| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
7635
7636**Example**
7637
7638  ```ts
7639  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7640  // import { featureAbility } from '@kit.AbilityKit';
7641  import { Want, common } from '@kit.AbilityKit';
7642  import { hilog } from '@kit.PerformanceAnalysisKit';
7643
7644  let proxy: rpc.IRemoteObject | undefined;
7645  let connect: common.ConnectOptions = {
7646    onConnect: (elementName, remoteProxy) => {
7647      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7648      proxy = remoteProxy;
7649    },
7650    onDisconnect: (elementName) => {
7651      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7652    },
7653    onFailed: () => {
7654      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7655    }
7656  };
7657  let want: Want = {
7658    bundleName: "com.ohos.server",
7659    abilityName: "com.ohos.server.EntryAbility",
7660  };
7661
7662  // Use this method to connect to the ability for the FA model.
7663  // FA.connectAbility(want,connect);
7664
7665  // Save the connection ID, which will be used for the subsequent service disconnection.
7666  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7667  // Save the connection ID, which will be used for the subsequent service disconnection.
7668  let connectionId = context.connectServiceExtensionAbility(want, connect);
7669  ```
7670
7671The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **addDeathRecipient()** of the proxy object is called to add a callback for receiving the death notification of the remove object.
7672
7673  ```ts
7674  import { hilog } from '@kit.PerformanceAnalysisKit';
7675
7676  class MyDeathRecipient implements rpc.DeathRecipient {
7677    onRemoteDied() {
7678      hilog.info(0x0000, 'testTag', 'server died');
7679    }
7680  }
7681  let deathRecipient = new MyDeathRecipient();
7682  if (proxy != undefined) {
7683    proxy.addDeathRecipient(deathRecipient, 0);
7684  }
7685  ```
7686
7687### unregisterDeathRecipient<sup>9+</sup>
7688
7689unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void
7690
7691Unregisters the callback used to receive death notifications of the remote object.
7692
7693**System capability**: SystemCapability.Communication.IPC.Core
7694
7695**Parameters**
7696
7697| Name   | Type                             | Mandatory| Description          |
7698| --------- | --------------------------------- | ---- | -------------- |
7699| recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to unregister.|
7700| flags     | number                            | Yes  | Flag of the death notification.|
7701
7702**Error codes**
7703
7704For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
7705
7706| ID| Error Message|
7707| -------- | -------- |
7708| 401      | check param failed |
7709| 1900008  | proxy or remote object is invalid |
7710
7711**Example**
7712
7713  ```ts
7714  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7715  // import { featureAbility } from '@kit.AbilityKit';
7716  import { Want, common } from '@kit.AbilityKit';
7717  import { hilog } from '@kit.PerformanceAnalysisKit';
7718
7719  let proxy: rpc.IRemoteObject | undefined;
7720  let connect: common.ConnectOptions = {
7721    onConnect: (elementName, remoteProxy) => {
7722      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7723      proxy = remoteProxy;
7724    },
7725    onDisconnect: (elementName) => {
7726      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7727    },
7728    onFailed: () => {
7729      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7730    }
7731  };
7732  let want: Want = {
7733    bundleName: "com.ohos.server",
7734    abilityName: "com.ohos.server.EntryAbility",
7735  };
7736
7737  // Use this method to connect to the ability for the FA model.
7738  // FA.connectAbility(want,connect);
7739
7740  // Save the connection ID, which will be used for the subsequent service disconnection.
7741  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7742  // Save the connection ID, which will be used for the subsequent service disconnection.
7743  let connectionId = context.connectServiceExtensionAbility(want, connect);
7744  ```
7745
7746The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **unregisterDeathRecipient()** of the proxy object is called to unregister the callback for receiving the death notification of the remote object.
7747
7748  ```ts
7749  import { hilog } from '@kit.PerformanceAnalysisKit';
7750  import { BusinessError } from '@kit.BasicServicesKit';
7751
7752  class MyDeathRecipient implements rpc.DeathRecipient {
7753    onRemoteDied() {
7754      hilog.info(0x0000, 'testTag', 'server died');
7755    }
7756  }
7757  let deathRecipient = new MyDeathRecipient();
7758  if (proxy != undefined) {
7759    try {
7760      proxy.registerDeathRecipient(deathRecipient, 0);
7761      proxy.unregisterDeathRecipient(deathRecipient, 0);
7762    } catch (error) {
7763      let e: BusinessError = error as BusinessError;
7764      hilog.error(0x0000, 'testTag', 'proxy unregister deathRecipient fail, errorCode ' + e.code);
7765      hilog.error(0x0000, 'testTag', 'proxy unregister deathRecipient fail, errorMessage ' + e.message);
7766    }
7767  }
7768  ```
7769
7770### removeDeathRecipient<sup>(deprecated)</sup>
7771
7772>**NOTE**<br>This API is no longer maintained since API version 9. Use [unregisterDeathRecipient](#unregisterdeathrecipient9-1) instead.
7773
7774removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
7775
7776Removes the callback used to receive death notifications of the remote object.
7777
7778**System capability**: SystemCapability.Communication.IPC.Core
7779
7780**Parameters**
7781
7782| Name   | Type                             | Mandatory| Description                             |
7783| --------- | --------------------------------- | ---- | --------------------------------- |
7784| recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.               |
7785| flags     | number                            | Yes  | Flag of the death notification. This parameter is reserved. It is set to **0**.|
7786
7787**Return value**
7788
7789| Type   | Description                                    |
7790| ------- | ---------------------------------------- |
7791| boolean | Returns **true** if the callback is removed; returns **false** otherwise.|
7792
7793**Example**
7794
7795  ```ts
7796  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7797  // import { featureAbility } from '@kit.AbilityKit';
7798  import { Want, common } from '@kit.AbilityKit';
7799  import { hilog } from '@kit.PerformanceAnalysisKit';
7800
7801  let proxy: rpc.IRemoteObject | undefined;
7802  let connect: common.ConnectOptions = {
7803    onConnect: (elementName, remoteProxy) => {
7804      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7805      proxy = remoteProxy;
7806    },
7807    onDisconnect: (elementName) => {
7808      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7809    },
7810    onFailed: () => {
7811      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7812    }
7813  };
7814  let want: Want = {
7815    bundleName: "com.ohos.server",
7816    abilityName: "com.ohos.server.EntryAbility",
7817  };
7818
7819  // Use this method to connect to the ability for the FA model.
7820  // FA.connectAbility(want,connect);
7821
7822  // Save the connection ID, which will be used for the subsequent service disconnection.
7823  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7824  // Save the connection ID, which will be used for the subsequent service disconnection.
7825  let connectionId = context.connectServiceExtensionAbility(want, connect);
7826  ```
7827
7828  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **removeDeathRecipient()** of the proxy object is called to remove the callback used to receive the death notification of the remote object.
7829
7830  ```ts
7831  import { hilog } from '@kit.PerformanceAnalysisKit';
7832
7833  class MyDeathRecipient implements rpc.DeathRecipient {
7834    onRemoteDied() {
7835      hilog.info(0x0000, 'testTag', 'server died');
7836    }
7837  }
7838  let deathRecipient = new MyDeathRecipient();
7839  if (proxy != undefined) {
7840    proxy.addDeathRecipient(deathRecipient, 0);
7841    proxy.removeDeathRecipient(deathRecipient, 0);
7842  }
7843  ```
7844
7845### getDescriptor<sup>9+</sup>
7846
7847getDescriptor(): string
7848
7849Obtains the interface descriptor (which is a string) of this object.
7850
7851**System capability**: SystemCapability.Communication.IPC.Core
7852
7853**Return value**
7854
7855| Type  | Description            |
7856| ------ | ---------------- |
7857| string | Interface descriptor obtained.|
7858
7859**Error codes**
7860
7861For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
7862
7863| ID| Error Message|
7864| -------- | -------- |
7865| 1900008  | proxy or remote object is invalid |
7866| 1900007  | communication failed              |
7867
7868**Example**
7869
7870  ```ts
7871  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7872  // import { featureAbility } from '@kit.AbilityKit';
7873  import { Want, common } from '@kit.AbilityKit';
7874  import { hilog } from '@kit.PerformanceAnalysisKit';
7875
7876  let proxy: rpc.IRemoteObject | undefined;
7877  let connect: common.ConnectOptions = {
7878    onConnect: (elementName, remoteProxy) => {
7879      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7880      proxy = remoteProxy;
7881    },
7882    onDisconnect: (elementName) => {
7883      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7884    },
7885    onFailed: () => {
7886      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7887    }
7888  };
7889  let want: Want = {
7890    bundleName: "com.ohos.server",
7891    abilityName: "com.ohos.server.EntryAbility",
7892  };
7893
7894  // Use this method to connect to the ability for the FA model.
7895  // FA.connectAbility(want,connect);
7896
7897  // Save the connection ID, which will be used for the subsequent service disconnection.
7898  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7899  // Save the connection ID, which will be used for the subsequent service disconnection.
7900  let connectionId = context.connectServiceExtensionAbility(want, connect);
7901  ```
7902  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **getDescriptor()** of the proxy object is called to obtain the interface descriptor of the object.
7903
7904  ```ts
7905  import { hilog } from '@kit.PerformanceAnalysisKit';
7906  import { BusinessError } from '@kit.BasicServicesKit';
7907
7908  if (proxy != undefined) {
7909    try {
7910      let descriptor: string = proxy.getDescriptor();
7911      hilog.info(0x0000, 'testTag', 'RpcClient: descriptor is ' + descriptor);
7912    } catch (error) {
7913      let e: BusinessError = error as BusinessError;
7914      hilog.error(0x0000, 'testTag', 'rpc get interface descriptor fail, errorCode ' + e.code);
7915      hilog.error(0x0000, 'testTag', 'rpc get interface descriptor fail, errorMessage ' + e.message);
7916    }
7917  }
7918  ```
7919
7920### getInterfaceDescriptor<sup>(deprecated)</sup>
7921
7922>**NOTE**<br>This API is no longer maintained since API version 9. Use [getDescriptor](#getdescriptor9-1) instead.
7923
7924getInterfaceDescriptor(): string
7925
7926Obtains the interface descriptor of this proxy object.
7927
7928**System capability**: SystemCapability.Communication.IPC.Core
7929
7930**Return value**
7931
7932| Type  | Description              |
7933| ------ | ------------------ |
7934| string | Interface descriptor obtained.|
7935
7936**Example**
7937
7938  ```ts
7939  // If the FA model is used, import featureAbility from @kit.AbilityKit.
7940  // import { featureAbility } from '@kit.AbilityKit';
7941  import { Want, common } from '@kit.AbilityKit';
7942  import { hilog } from '@kit.PerformanceAnalysisKit';
7943
7944  let proxy: rpc.IRemoteObject | undefined;
7945  let connect: common.ConnectOptions = {
7946    onConnect: (elementName, remoteProxy) => {
7947      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
7948      proxy = remoteProxy;
7949    },
7950    onDisconnect: (elementName) => {
7951      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
7952    },
7953    onFailed: () => {
7954      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
7955    }
7956  };
7957  let want: Want = {
7958    bundleName: "com.ohos.server",
7959    abilityName: "com.ohos.server.EntryAbility",
7960  };
7961
7962  // Use this method to connect to the ability for the FA model.
7963  // FA.connectAbility(want,connect);
7964
7965  // Save the connection ID, which will be used for the subsequent service disconnection.
7966  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
7967  // Save the connection ID, which will be used for the subsequent service disconnection.
7968  let connectionId = context.connectServiceExtensionAbility(want, connect);
7969  ```
7970
7971  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **getInterfaceDescriptor()** of the proxy object is called to obtain the interface descriptor of the current proxy object.
7972
7973  ```ts
7974  import { hilog } from '@kit.PerformanceAnalysisKit';
7975
7976  if (proxy != undefined) {
7977    let descriptor: string = proxy.getInterfaceDescriptor();
7978    hilog.info(0x0000, 'testTag', 'RpcClient: descriptor is ' + descriptor);
7979  }
7980  ```
7981
7982### isObjectDead
7983
7984isObjectDead(): boolean
7985
7986Checks whether the **RemoteObject** is dead.
7987
7988**System capability**: SystemCapability.Communication.IPC.Core
7989
7990**Return value**
7991
7992| Type   | Description                                             |
7993| ------- | ------------------------------------------------- |
7994| boolean | Returns **true** if **RemoteObject** is dead; returns **false** otherwise.|
7995
7996**Example**
7997
7998  ```ts
7999  // If the FA model is used, import featureAbility from @kit.AbilityKit.
8000  // import { featureAbility } from '@kit.AbilityKit';
8001  import { Want, common } from '@kit.AbilityKit';
8002  import { hilog } from '@kit.PerformanceAnalysisKit';
8003
8004  let proxy: rpc.IRemoteObject | undefined;
8005  let connect: common.ConnectOptions = {
8006    onConnect: (elementName, remoteProxy) => {
8007      hilog.info(0x0000, 'testTag', 'RpcClient: js onConnect called');
8008      proxy = remoteProxy;
8009    },
8010    onDisconnect: (elementName) => {
8011      hilog.info(0x0000, 'testTag', 'RpcClient: onDisconnect');
8012    },
8013    onFailed: () => {
8014      hilog.info(0x0000, 'testTag', 'RpcClient: onFailed');
8015    }
8016  };
8017  let want: Want = {
8018    bundleName: "com.ohos.server",
8019    abilityName: "com.ohos.server.EntryAbility",
8020  };
8021
8022  // Use this method to connect to the ability for the FA model.
8023  // FA.connectAbility(want,connect);
8024
8025  // Save the connection ID, which will be used for the subsequent service disconnection.
8026  let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
8027  // Save the connection ID, which will be used for the subsequent service disconnection.
8028  let connectionId = context.connectServiceExtensionAbility(want, connect);
8029  ```
8030
8031  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **isObjectDead()** of the proxy object is called to check whether this object is dead.
8032
8033  ```ts
8034  import { hilog } from '@kit.PerformanceAnalysisKit';
8035
8036  if (proxy != undefined) {
8037    let isDead: boolean = proxy.isObjectDead();
8038    hilog.info(0x0000, 'testTag', 'RpcClient: isObjectDead is ' + isDead);
8039  }
8040  ```
8041
8042## MessageOption
8043
8044Defines the options used to construct the **MessageOption** object.
8045
8046**System capability**: SystemCapability.Communication.IPC.Core
8047
8048| Name         | Value       | Description                                                       |
8049| ------------- | --------- | ----------------------------------------------------------- |
8050| TF_SYNC       | 0 (0x00)  | Synchronous call.                                             |
8051| TF_ASYNC      | 1 (0x01)  | Asynchronous call.                                             |
8052| TF_ACCEPT_FDS | 16 (0x10) | Indication to **sendMessageRequest<sup>9+</sup>** for returning the file descriptor.|
8053| TF_WAIT_TIME  | 8 (0x8)   | RPC wait time, in seconds. This parameter cannot be used in IPC.                                    |
8054
8055### constructor<sup>9+</sup>
8056
8057constructor(async?: boolean)
8058
8059A constructor used to create a **MessageOption** object.
8060
8061**System capability**: SystemCapability.Communication.IPC.Core
8062
8063**Parameters**
8064
8065| Name| Type   | Mandatory| Description                                                        |
8066| ------ | ------- | ---- | ------------------------------------------------------------ |
8067| async  | boolean | No  | Whether to execute the call asynchronously. The value **true** means to execute the call asynchronously; the value **false** means to execute the call synchronously. By default, calls are made synchronously.|
8068
8069**Example**
8070
8071  ```ts
8072  class TestRemoteObject extends rpc.MessageOption {
8073    constructor(async: boolean) {
8074      super(async);
8075    }
8076  }
8077  ```
8078
8079### constructor
8080
8081constructor(syncFlags?: number, waitTime?: number)
8082
8083A constructor used to create a **MessageOption** object.
8084
8085**System capability**: SystemCapability.Communication.IPC.Core
8086
8087**Parameters**
8088
8089| Name   | Type  | Mandatory| Description                                         |
8090| --------- | ------ | ---- | --------------------------------------------- |
8091| syncFlags | number | No  | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.       |
8092| waitTime  | number | No  | Maximum wait time for an RPC call. The default value is **TF_WAIT_TIME**.|
8093
8094**Example**
8095
8096  ```ts
8097  class TestRemoteObject extends rpc.MessageOption {
8098    constructor(syncFlags?: number,waitTime?: number) {
8099      super(syncFlags,waitTime);
8100    }
8101  }
8102  ```
8103### isAsync<sup>9+</sup>
8104
8105isAsync(): boolean
8106
8107Checks whether **SendMessageRequest** is called synchronously or asynchronously.
8108
8109**System capability**: SystemCapability.Communication.IPC.Core
8110
8111**Return value**
8112
8113| Type   | Description                                    |
8114| ------- | ---------------------------------------- |
8115| boolean | Returns **true** if **SendMessageRequest** is called asynchronously; returns **false** if it is called synchronously.|
8116
8117**Example**
8118
8119  ```ts
8120  let option = new rpc.MessageOption();
8121  option.isAsync();
8122  ```
8123
8124### setAsync<sup>9+</sup>
8125
8126setAsync(async: boolean): void
8127
8128Sets the calling flag in **SendMessageRequest**.
8129
8130**System capability**: SystemCapability.Communication.IPC.Core
8131
8132**Parameters**
8133
8134| Name| Type   | Mandatory| Description                                             |
8135| ------ | ------- | ---- | ------------------------------------------------- |
8136| async  | boolean | Yes  | Whether to execute the call asynchronously. The value **true** means to execute the call asynchronously; the value **false** means to execute the call synchronously.|
8137
8138**Example**
8139
8140  ```ts
8141  import { hilog } from '@kit.PerformanceAnalysisKit';
8142
8143  let option = new rpc.MessageOption();
8144  option.setAsync(true);
8145  hilog.info(0x0000, 'testTag', 'Set asynchronization flag');
8146  ```
8147
8148### getFlags
8149
8150getFlags(): number
8151
8152Obtains the call flag, which can be synchronous or asynchronous.
8153
8154**System capability**: SystemCapability.Communication.IPC.Core
8155
8156**Return value**
8157
8158| Type  | Description                                |
8159| ------ | ------------------------------------ |
8160| number | Call mode obtained.|
8161
8162**Example**
8163
8164  ```ts
8165  import { hilog } from '@kit.PerformanceAnalysisKit';
8166
8167  try {
8168    let option = new rpc.MessageOption();
8169    hilog.info(0x0000, 'testTag', 'create object successfully');
8170    let flog = option.getFlags();
8171    hilog.info(0x0000, 'testTag', 'run getFlags success, flog is ' + flog);
8172    option.setFlags(1)
8173    hilog.info(0x0000, 'testTag', 'run setFlags success');
8174    let flog2 = option.getFlags();
8175    hilog.info(0x0000, 'testTag', 'run getFlags success, flog2 is ' + flog2);
8176  } catch (error) {
8177    hilog.error(0x0000, 'testTag', 'error ' + error);
8178  }
8179  ```
8180
8181### setFlags
8182
8183setFlags(flags: number): void
8184
8185Sets the call flag, which can be synchronous or asynchronous.
8186
8187**System capability**: SystemCapability.Communication.IPC.Core
8188
8189**Parameters**
8190
8191| Name| Type  | Mandatory| Description                    |
8192| ------ | ------ | ---- | ------------------------ |
8193| flags  | number | Yes  | Call flag to set.|
8194
8195**Example**
8196
8197  ```ts
8198  import { hilog } from '@kit.PerformanceAnalysisKit';
8199
8200  try {
8201    let option = new rpc.MessageOption();
8202    option.setFlags(1)
8203    hilog.info(0x0000, 'testTag', 'run setFlags success');
8204    let flog = option.getFlags();
8205    hilog.info(0x0000, 'testTag', 'run getFlags success, flog is ' + flog);
8206  } catch (error) {
8207    hilog.error(0x0000, 'testTag', 'error ' + error);
8208  }
8209  ```
8210
8211### getWaitTime
8212
8213getWaitTime(): number
8214
8215Obtains the maximum wait time for this RPC call.
8216
8217**System capability**: SystemCapability.Communication.IPC.Core
8218
8219**Return value**
8220
8221| Type  | Description             |
8222| ------ | ----------------- |
8223| number | Maximum wait time obtained.|
8224
8225**Example**
8226
8227  ```ts
8228  import { hilog } from '@kit.PerformanceAnalysisKit';
8229
8230  try {
8231    let option = new rpc.MessageOption();
8232    let time = option.getWaitTime();
8233    hilog.info(0x0000, 'testTag', 'run getWaitTime success, time is ' + time);
8234    option.setWaitTime(16);
8235    let time2 = option.getWaitTime();
8236    hilog.info(0x0000, 'testTag', 'run getWaitTime success, time is ' + time2);
8237  } catch (error) {
8238    hilog.error(0x0000, 'testTag', 'error ' + error);
8239  }
8240  ```
8241
8242### setWaitTime
8243
8244setWaitTime(waitTime: number): void
8245
8246Sets the maximum wait time for this RPC call.
8247
8248**System capability**: SystemCapability.Communication.IPC.Core
8249
8250**Parameters**
8251
8252| Name  | Type  | Mandatory| Description                 |
8253| -------- | ------ | ---- | --------------------- |
8254| waitTime | number | Yes  | Maximum wait time to set. The upper limit is 3000 seconds.|
8255
8256**Example**
8257
8258  ```ts
8259  import { hilog } from '@kit.PerformanceAnalysisKit';
8260
8261  try {
8262    let option = new rpc.MessageOption();
8263    option.setWaitTime(16);
8264    let time = option.getWaitTime();
8265    hilog.info(0x0000, 'testTag', 'run getWaitTime success, time is ' + time);
8266  } catch (error) {
8267    hilog.error(0x0000, 'testTag', 'error ' + error);
8268  }
8269  ```
8270
8271## IPCSkeleton
8272
8273Obtains IPC context information, including the UID and PID, local and remote device IDs, and whether the method is invoked on the same device.
8274
8275### getContextObject
8276
8277static getContextObject(): IRemoteObject
8278
8279Obtains the system capability manager. This API is a static method.
8280
8281**System capability**: SystemCapability.Communication.IPC.Core
8282
8283**Return value**
8284
8285| Type                           | Description                |
8286| ------------------------------- | -------------------- |
8287| [IRemoteObject](#iremoteobject) | System capability manager obtained.|
8288
8289**Example**
8290
8291  ```ts
8292  import { hilog } from '@kit.PerformanceAnalysisKit';
8293
8294  let samgr = rpc.IPCSkeleton.getContextObject();
8295  hilog.info(0x0000, 'testTag', 'RpcServer: getContextObject result: ' + samgr);
8296  ```
8297
8298### getCallingPid
8299
8300static getCallingPid(): number
8301
8302Obtains the PID of the caller. This API is a static method, which is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the PID of the process will be returned.
8303
8304**System capability**: SystemCapability.Communication.IPC.Core
8305
8306**Return value**
8307
8308| Type  | Description             |
8309| ------ | ----------------- |
8310| number | PID of the caller.|
8311
8312**Example**
8313
8314  ```ts
8315  import { hilog } from '@kit.PerformanceAnalysisKit';
8316
8317  class Stub extends rpc.RemoteObject {
8318    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8319      let callerPid = rpc.IPCSkeleton.getCallingPid();
8320      hilog.info(0x0000, 'testTag', 'RpcServer: getCallingPid result: ' + callerPid);
8321      return true;
8322    }
8323 }
8324  ```
8325
8326### getCallingUid
8327
8328static getCallingUid(): number
8329
8330Obtains the UID of the caller. This API is a static method, which is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the UID of the process will be returned.
8331
8332**System capability**: SystemCapability.Communication.IPC.Core
8333
8334**Return value**
8335
8336| Type  | Description             |
8337| ------ | ----------------- |
8338| number | UID of the caller.|
8339
8340**Example**
8341
8342  ```ts
8343  import { hilog } from '@kit.PerformanceAnalysisKit';
8344
8345  class Stub extends rpc.RemoteObject {
8346    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8347      let callerUid = rpc.IPCSkeleton.getCallingUid();
8348      hilog.info(0x0000, 'testTag', 'RpcServer: getCallingUid result: ' + callerUid);
8349      return true;
8350    }
8351  }
8352  ```
8353
8354### getCallingTokenId<sup>8+</sup>
8355
8356static getCallingTokenId(): number
8357
8358Obtains the caller's token ID, which is used to verify the caller identity.
8359
8360**System capability**: SystemCapability.Communication.IPC.Core
8361
8362**Return value**
8363
8364| Type  | Description                 |
8365| ------ | --------------------- |
8366| number | Token ID of the caller obtained.|
8367
8368**Example**
8369
8370  ```ts
8371  import { hilog } from '@kit.PerformanceAnalysisKit';
8372
8373  class Stub extends rpc.RemoteObject {
8374    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8375      let callerTokenId = rpc.IPCSkeleton.getCallingTokenId();
8376      hilog.info(0x0000, 'testTag', 'RpcServer: getCallingTokenId result: ' + callerTokenId);
8377      return true;
8378    }
8379  }
8380  ```
8381
8382### getCallingDeviceID
8383
8384static getCallingDeviceID(): string
8385
8386Obtains the ID of the device hosting the caller's process. This API is a static method.
8387
8388**System capability**: SystemCapability.Communication.IPC.Core
8389
8390**Return value**
8391
8392| Type  | Description                        |
8393| ------ | ---------------------------- |
8394| string | Device ID obtained.|
8395
8396**Example**
8397
8398  ```ts
8399  import { hilog } from '@kit.PerformanceAnalysisKit';
8400
8401  class Stub extends rpc.RemoteObject {
8402    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8403      let callerDeviceID = rpc.IPCSkeleton.getCallingDeviceID();
8404      hilog.info(0x0000, 'testTag', 'RpcServer: callerDeviceID is ' + callerDeviceID);
8405      return true;
8406    }
8407  }
8408  ```
8409
8410### getLocalDeviceID
8411
8412static getLocalDeviceID(): string
8413
8414Obtains the local device ID. This API is a static method.
8415
8416**System capability**: SystemCapability.Communication.IPC.Core
8417
8418**Return value**
8419
8420| Type  | Description              |
8421| ------ | ------------------ |
8422| string | Local device ID obtained.|
8423
8424**Example**
8425
8426  ```ts
8427  import { hilog } from '@kit.PerformanceAnalysisKit';
8428
8429  class Stub extends rpc.RemoteObject {
8430    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8431      let localDeviceID = rpc.IPCSkeleton.getLocalDeviceID();
8432      hilog.info(0x0000, 'testTag', 'RpcServer: localDeviceID is ' + localDeviceID);
8433      return true;
8434    }
8435  }
8436  ```
8437
8438### isLocalCalling
8439
8440static isLocalCalling(): boolean
8441
8442Checks whether the remote process is a process of the local device. This API is a static method.
8443
8444**System capability**: SystemCapability.Communication.IPC.Core
8445
8446**Return value**
8447
8448| Type   | Description                                              |
8449| ------- | -------------------------------------------------- |
8450| boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
8451
8452**Example**
8453
8454  ```ts
8455  import { hilog } from '@kit.PerformanceAnalysisKit';
8456
8457  class Stub extends rpc.RemoteObject {
8458    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8459      let isLocalCalling = rpc.IPCSkeleton.isLocalCalling();
8460      hilog.info(0x0000, 'testTag', 'RpcServer: isLocalCalling is ' + isLocalCalling);
8461      return true;
8462    }
8463  }
8464  ```
8465
8466### flushCmdBuffer<sup>9+</sup>
8467
8468static flushCmdBuffer(object: IRemoteObject): void
8469
8470Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. This API is a static method. You are advised to call this API before performing any sensitive operation.
8471
8472**System capability**: SystemCapability.Communication.IPC.Core
8473
8474**Parameters**
8475
8476| Name| Type                           | Mandatory| Description               |
8477| ------ | ------------------------------- | ---- | ------------------- |
8478| object | [IRemoteObject](#iremoteobject) | Yes  | **RemoteProxy** specified. |
8479
8480**Error codes**
8481
8482For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
8483
8484| ID| Error Message|
8485| -------- | -------- |
8486| 401      | check param failed |
8487
8488**Example**
8489
8490  ```ts
8491  import { hilog } from '@kit.PerformanceAnalysisKit';
8492  import { BusinessError } from '@kit.BasicServicesKit';
8493
8494  class TestRemoteObject extends rpc.RemoteObject {
8495    constructor(descriptor: string) {
8496      super(descriptor);
8497    }
8498  }
8499  let remoteObject = new TestRemoteObject("aaa");
8500  try {
8501    rpc.IPCSkeleton.flushCmdBuffer(remoteObject);
8502  } catch (error) {
8503    let e: BusinessError = error as BusinessError;
8504    hilog.error(0x0000, 'testTag', 'proxy flushCmdBuffer fail, errorCode ' + e.code);
8505    hilog.error(0x0000, 'testTag', 'proxy flushCmdBuffer fail, errorMessage ' + e.message);
8506  }
8507  ```
8508
8509### flushCommands<sup>(deprecated)</sup>
8510
8511>**NOTE**<br>This API is no longer maintained since API version 9. Use [flushCmdBuffer](#flushcmdbuffer9) instead.
8512
8513static flushCommands(object: IRemoteObject): number
8514
8515Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. This API is a static method. You are advised to call this API before performing any sensitive operation.
8516
8517**System capability**: SystemCapability.Communication.IPC.Core
8518
8519**Parameters**
8520
8521| Name| Type                           | Mandatory| Description               |
8522| ------ | ------------------------------- | ---- | ------------------- |
8523| object | [IRemoteObject](#iremoteobject) | Yes  | **RemoteProxy** specified. |
8524
8525**Return value**
8526
8527| Type  | Description                                                                             |
8528| ------ | --------------------------------------------------------------------------------- |
8529| number | Returns **0** if the operation is successful; returns an error code if the input object is null or a **RemoteObject**, or if the operation fails.|
8530
8531**Example**
8532
8533  ```ts
8534  import { hilog } from '@kit.PerformanceAnalysisKit';
8535
8536  class MyDeathRecipient implements rpc.DeathRecipient {
8537    onRemoteDied() {
8538      hilog.info(0x0000, 'testTag', 'server died');
8539    }
8540  }
8541  class TestRemoteObject extends rpc.RemoteObject {
8542    constructor(descriptor: string) {
8543      super(descriptor);
8544    }
8545    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8546      return true;
8547    }
8548    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8549      return true;
8550    }
8551    isObjectDead(): boolean {
8552      return false;
8553    }
8554  }
8555  let remoteObject = new TestRemoteObject("aaa");
8556  let ret = rpc.IPCSkeleton.flushCommands(remoteObject);
8557  hilog.info(0x0000, 'testTag', 'RpcServer: flushCommands result: ' + ret);
8558  ```
8559
8560### resetCallingIdentity
8561
8562static resetCallingIdentity(): string
8563
8564Resets the UID and PID of the remote user to those of the local user. This API is a static method and is used in scenarios such as identity authentication.
8565
8566**System capability**: SystemCapability.Communication.IPC.Core
8567
8568**Return value**
8569
8570| Type  | Description                                |
8571| ------ | ------------------------------------ |
8572| string | String containing the UID and PID of the remote user.|
8573
8574**Example**
8575
8576  ```ts
8577  import { hilog } from '@kit.PerformanceAnalysisKit';
8578
8579  class Stub extends rpc.RemoteObject {
8580    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8581      let callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
8582      hilog.info(0x0000, 'testTag', 'RpcServer: callingIdentity is ' + callingIdentity);
8583      return true;
8584    }
8585  }
8586  ```
8587
8588### restoreCallingIdentity<sup>9+</sup>
8589
8590static restoreCallingIdentity(identity: string): void
8591
8592Restores the UID and PID of the remote user. This API is a static method. It is usually called after **resetCallingIdentity**, and the UID and PID of the remote user returned by **resetCallingIdentity** are required.
8593
8594**System capability**: SystemCapability.Communication.IPC.Core
8595
8596**Parameters**
8597
8598| Name  | Type  | Mandatory| Description                                                              |
8599| -------- | ------ | ---- | ------------------------------------------------------------------ |
8600| identity | string | Yes  | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
8601
8602**Error codes**
8603
8604For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
8605
8606| ID| Error Message|
8607| -------- | -------- |
8608| 401      | check param failed |
8609
8610**Example**
8611
8612  ```ts
8613  import { hilog } from '@kit.PerformanceAnalysisKit';
8614
8615  class Stub extends rpc.RemoteObject {
8616    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8617      let callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
8618      hilog.info(0x0000, 'testTag', 'RpcServer: callingIdentity is ' + callingIdentity);
8619      rpc.IPCSkeleton.restoreCallingIdentity(callingIdentity);
8620      return true;
8621    }
8622  }
8623  ```
8624
8625### setCallingIdentity<sup>(deprecated)</sup>
8626
8627>**NOTE**<br>This API is no longer maintained since API version 9. Use [restoreCallingIdentity](#restorecallingidentity9) instead.
8628
8629static setCallingIdentity(identity: string): boolean
8630
8631Sets the UID and PID of the remote user. This API is a static method. It is usually called after **resetCallingIdentity**, and the UID and PID of the remote user returned by **resetCallingIdentity** are required.
8632
8633**System capability**: SystemCapability.Communication.IPC.Core
8634
8635**Parameters**
8636
8637| Name  | Type  | Mandatory| Description                                                              |
8638| -------- | ------ | ---- | ------------------------------------------------------------------ |
8639| identity | string | Yes  | String containing the remote user's UID and PID, which are returned by **resetCallingIdentity**. |
8640
8641**Return value**
8642
8643| Type   | Description                            |
8644| ------- | ---------------------------------|
8645| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
8646
8647**Example**
8648
8649  ```ts
8650  import { hilog } from '@kit.PerformanceAnalysisKit';
8651
8652  class Stub extends rpc.RemoteObject {
8653    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
8654      let callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
8655      hilog.info(0x0000, 'testTag', 'RpcServer: callingIdentity is ' + callingIdentity);
8656      let ret = rpc.IPCSkeleton.setCallingIdentity(callingIdentity);
8657      hilog.info(0x0000, 'testTag', 'RpcServer: setCallingIdentity is ' + ret);
8658      return true;
8659    }
8660  }
8661  ```
8662
8663## RemoteObject
8664
8665Provides methods to implement **RemoteObject**. The service provider must inherit from this class.
8666
8667### constructor
8668
8669constructor(descriptor: string)
8670
8671A constructor used to create a **RemoteObject** object.
8672
8673**System capability**: SystemCapability.Communication.IPC.Core
8674
8675**Parameters**
8676
8677| Name    | Type  | Mandatory| Description        |
8678| ---------- | ------ | ---- | ------------ |
8679| descriptor | string | Yes  | Interface descriptor.|
8680
8681### sendRequest<sup>(deprecated)</sup>
8682
8683>**NOTE**<br>This API is no longer maintained since API version 8. Use [sendMessageRequest](#sendmessagerequest9-4) instead.
8684
8685sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
8686
8687Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
8688
8689**System capability**: SystemCapability.Communication.IPC.Core
8690
8691**Parameters**
8692
8693| Name | Type                                     | Mandatory| Description                                                                                  |
8694| ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
8695| code    | number                                    | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
8696| data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
8697| reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
8698| options | [MessageOption](#messageoption)           | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
8699
8700**Return value**
8701
8702| Type   | Description                            |
8703| ------- | -------------------------------- |
8704| boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
8705
8706**Example**
8707
8708  ```ts
8709  import { hilog } from '@kit.PerformanceAnalysisKit';
8710
8711  class MyDeathRecipient implements rpc.DeathRecipient {
8712    onRemoteDied() {
8713      hilog.info(0x0000, 'testTag', 'server died');
8714    }
8715  }
8716  class TestRemoteObject extends rpc.RemoteObject {
8717    constructor(descriptor: string) {
8718      super(descriptor);
8719    }
8720    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8721      return true;
8722    }
8723    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8724      return true;
8725    }
8726    isObjectDead(): boolean {
8727      return false;
8728    }
8729  }
8730  let testRemoteObject = new TestRemoteObject("testObject");
8731  let option = new rpc.MessageOption();
8732  let data = rpc.MessageParcel.create();
8733  let reply = rpc.MessageParcel.create();
8734  data.writeInt(1);
8735  data.writeString("hello");
8736  let ret: boolean = testRemoteObject.sendRequest(1, data, reply, option);
8737  if (ret) {
8738    hilog.info(0x0000, 'testTag', 'sendRequest got result');
8739    let msg = reply.readString();
8740    hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
8741  } else {
8742    hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed');
8743  }
8744  hilog.info(0x0000, 'testTag', 'RPCTest: sendRequest ends, reclaim parcel');
8745  data.reclaim();
8746  reply.reclaim();
8747  ```
8748
8749### sendMessageRequest<sup>9+</sup>
8750
8751sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
8752
8753Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
8754
8755**System capability**: SystemCapability.Communication.IPC.Core
8756
8757**Parameters**
8758
8759| Name | Type                                | Mandatory| Description                                                                                  |
8760| ------- | ------------------------------------ | ---- | -------------------------------------------------------------------------------------- |
8761| code    | number                               | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
8762| data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
8763| reply   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
8764| options | [MessageOption](#messageoption)      | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
8765
8766**Return value**
8767
8768| Type                                           | Description                                     |
8769| ----------------------------------------------- | ----------------------------------------- |
8770| Promise&lt;[RequestResult](#requestresult9)&gt; | Promise used to return a **RequestResult** instance.|
8771
8772
8773**Error codes**
8774
8775For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
8776
8777| ID| Error Message|
8778| -------- | -------- |
8779| 401      | check param failed |
8780
8781**Example**
8782
8783  ```ts
8784  import { hilog } from '@kit.PerformanceAnalysisKit';
8785
8786  class TestRemoteObject extends rpc.RemoteObject {
8787    constructor(descriptor: string) {
8788      super(descriptor);
8789    }
8790  }
8791  let testRemoteObject = new TestRemoteObject("testObject");
8792  let option = new rpc.MessageOption();
8793  let data = rpc.MessageSequence.create();
8794  let reply = rpc.MessageSequence.create();
8795  data.writeInt(1);
8796  data.writeString("hello");
8797  testRemoteObject.sendMessageRequest(1, data, reply, option)
8798    .then((result: rpc.RequestResult) => {
8799      if (result.errCode === 0) {
8800        hilog.info(0x0000, 'testTag', 'sendMessageRequest got result');
8801        let num = result.reply.readInt();
8802        let msg = result.reply.readString();
8803        hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
8804        hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
8805      } else {
8806        hilog.error(0x0000, 'testTag', 'RPCTest: sendMessageRequest failed, errCode: ' + result.errCode);
8807      }
8808    }).catch((e: Error) => {
8809      hilog.error(0x0000, 'testTag', 'RPCTest: sendMessageRequest failed, message: ' + e.message);
8810    }).finally (() => {
8811      hilog.info(0x0000, 'testTag', 'RPCTest: sendMessageRequest ends, reclaim parcel');
8812      data.reclaim();
8813      reply.reclaim();
8814    });
8815  ```
8816
8817### sendRequest<sup>8+(deprecated)</sup>
8818
8819>**NOTE**<br>This API is no longer maintained since API version 9. Use [sendMessageRequest](#sendmessagerequest9-4) instead.
8820
8821sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
8822
8823Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
8824
8825**System capability**: SystemCapability.Communication.IPC.Core
8826
8827**Parameters**
8828
8829| Name | Type                                     | Mandatory| Description                                                                                  |
8830| ------- | ----------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
8831| code    | number                                    | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
8832| data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
8833| reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
8834| options | [MessageOption](#messageoption)           | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
8835
8836**Return value**
8837
8838| Type                                                        | Description                                         |
8839| ------------------------------------------------------------ | --------------------------------------------- |
8840| Promise&lt;[SendRequestResult](#sendrequestresult8deprecated)&gt; | Promise used to return a **sendRequestResult** instance.|
8841
8842**Example**
8843
8844  ```ts
8845  import { hilog } from '@kit.PerformanceAnalysisKit';
8846
8847  class MyDeathRecipient implements rpc.DeathRecipient {
8848    onRemoteDied() {
8849      hilog.info(0x0000, 'testTag', 'server died');
8850    }
8851  }
8852  class TestRemoteObject extends rpc.RemoteObject {
8853    constructor(descriptor: string) {
8854      super(descriptor);
8855    }
8856    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8857      return true;
8858    }
8859    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8860      return true;
8861    }
8862    isObjectDead(): boolean {
8863      return false;
8864    }
8865  }
8866  let testRemoteObject = new TestRemoteObject("testObject");
8867  let option = new rpc.MessageOption();
8868  let data = rpc.MessageParcel.create();
8869  let reply = rpc.MessageParcel.create();
8870  data.writeInt(1);
8871  data.writeString("hello");
8872  let a = testRemoteObject.sendRequest(1, data, reply, option) as Object;
8873  let b = a as Promise<rpc.SendRequestResult>;
8874  b.then((result: rpc.SendRequestResult) => {
8875    if (result.errCode === 0) {
8876      hilog.info(0x0000, 'testTag', 'sendRequest got result');
8877      let num = result.reply.readInt();
8878      let msg = result.reply.readString();
8879      hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
8880      hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
8881    } else {
8882      hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed, errCode: ' + result.errCode);
8883    }
8884  }).catch((e: Error) => {
8885    hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed, message: ' + e.message);
8886  }).finally (() => {
8887    hilog.info(0x0000, 'testTag', 'RPCTest: sendRequest ends, reclaim parcel');
8888    data.reclaim();
8889    reply.reclaim();
8890  });
8891  ```
8892
8893### sendMessageRequest<sup>9+</sup>
8894
8895sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void
8896
8897Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
8898
8899**System capability**: SystemCapability.Communication.IPC.Core
8900
8901**Parameters**
8902
8903| Name       | Type                                                 | Mandatory| Description                                                        |
8904| ------------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
8905| code          | number                                                | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
8906| data          | [MessageSequence](#messagesequence9)                  | Yes  | **MessageSequence** object holding the data to send.                 |
8907| reply         | [MessageSequence](#messagesequence9)                  | Yes  | **MessageSequence** object that receives the response.                         |
8908| options       | [MessageOption](#messageoption)                       | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                        |
8909| callback      | AsyncCallback&lt;[RequestResult](#requestresult9)&gt; | Yes  | Callback for receiving the sending result.                                        |
8910
8911
8912**Error codes**
8913
8914For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
8915
8916| ID| Error Message|
8917| -------- | -------- |
8918| 401      | check param failed |
8919
8920**Example**
8921
8922  ```ts
8923  import { hilog } from '@kit.PerformanceAnalysisKit';
8924  import { BusinessError } from '@kit.BasicServicesKit';
8925
8926  class TestRemoteObject extends rpc.RemoteObject {
8927    constructor(descriptor: string) {
8928      super(descriptor);
8929    }
8930  }
8931  function sendRequestCallback(err: BusinessError, result: rpc.RequestResult) {
8932    if (result.errCode === 0) {
8933      hilog.info(0x0000, 'testTag', 'sendRequest got result');
8934      let num = result.reply.readInt();
8935      let msg = result.reply.readString();
8936      hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
8937      hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
8938    } else {
8939      hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed, errCode: ' + result.errCode);
8940    }
8941    hilog.info(0x0000, 'testTag', 'RPCTest: sendRequest ends, reclaim parcel');
8942    result.data.reclaim();
8943    result.reply.reclaim();
8944  }
8945  let testRemoteObject = new TestRemoteObject("testObject");
8946  let option = new rpc.MessageOption();
8947  let data = rpc.MessageSequence.create();
8948  let reply = rpc.MessageSequence.create();
8949  data.writeInt(1);
8950  data.writeString("hello");
8951  testRemoteObject.sendMessageRequest(1, data, reply, option, sendRequestCallback);
8952  ```
8953
8954### sendRequest<sup>8+(deprecated)</sup>
8955
8956>**NOTE**<br>This API is no longer maintained since API version 9. Use [sendMessageRequest](#sendmessagerequest9-5) instead.
8957
8958sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void
8959
8960Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to **sendRequest** is returned, and the reply message contains the returned information.
8961
8962**System capability**: SystemCapability.Communication.IPC.Core
8963
8964**Parameters**
8965
8966| Name       | Type                                                        | Mandatory| Description                                                        |
8967| ------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
8968| code          | number                                                       | Yes  | Message code (1-16777215) called by the request, which is determined by the communication parties. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
8969| data          | [MessageParcel](#messageparceldeprecated)                    | Yes  | **MessageParcel** object holding the data to send.                   |
8970| reply         | [MessageParcel](#messageparceldeprecated)                    | Yes  | **MessageParcel** object that receives the response.                           |
8971| options       | [MessageOption](#messageoption)                              | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                        |
8972| callback      | AsyncCallback&lt;[SendRequestResult](#sendrequestresult8deprecated)&gt; | Yes  | Callback for receiving the sending result.                                        |
8973
8974**Example**
8975
8976  ```ts
8977  import { hilog } from '@kit.PerformanceAnalysisKit';
8978  import { BusinessError } from '@kit.BasicServicesKit';
8979
8980  class MyDeathRecipient implements rpc.DeathRecipient {
8981    onRemoteDied() {
8982      hilog.info(0x0000, 'testTag', 'server died');
8983    }
8984  }
8985  class TestRemoteObject extends rpc.RemoteObject {
8986    constructor(descriptor: string) {
8987      super(descriptor);
8988    }
8989    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8990      return true;
8991    }
8992    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8993      return true;
8994    }
8995    isObjectDead(): boolean {
8996      return false;
8997    }
8998  }
8999  function sendRequestCallback(err: BusinessError, result: rpc.SendRequestResult) {
9000    if (result.errCode === 0) {
9001      hilog.info(0x0000, 'testTag', 'sendRequest got result');
9002      let num = result.reply.readInt();
9003      let msg = result.reply.readString();
9004      hilog.info(0x0000, 'testTag', 'RPCTest: reply num: ' + num);
9005      hilog.info(0x0000, 'testTag', 'RPCTest: reply msg: ' + msg);
9006    } else {
9007      hilog.error(0x0000, 'testTag', 'RPCTest: sendRequest failed, errCode: ' + result.errCode);
9008    }
9009    hilog.info(0x0000, 'testTag', 'RPCTest: sendRequest ends, reclaim parcel');
9010    result.data.reclaim();
9011    result.reply.reclaim();
9012  }
9013  let testRemoteObject = new TestRemoteObject("testObject");
9014  let option = new rpc.MessageOption();
9015  let data = rpc.MessageParcel.create();
9016  let reply = rpc.MessageParcel.create();
9017  data.writeInt(1);
9018  data.writeString("hello");
9019  testRemoteObject.sendRequest(1, data, reply, option, sendRequestCallback);
9020  ```
9021
9022### onRemoteMessageRequest<sup>9+</sup>
9023
9024onRemoteMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): boolean | Promise\<boolean>
9025
9026> **NOTE**
9027>
9028>* You are advised to overload **onRemoteMessageRequest** preferentially, which implements synchronous and asynchronous message processing.
9029>* If both **onRemoteRequest()** and **onRemoteMessageRequest()** are overloaded, only the onRemoteMessageRequest() takes effect.
9030
9031Called to return a response to **sendMessageRequest()**. The server processes the request synchronously or asynchronously and returns the result in this API.
9032
9033**System capability**: SystemCapability.Communication.IPC.Core
9034
9035**Parameters**
9036
9037| Name| Type                                | Mandatory| Description                                     |
9038| ------ | ------------------------------------ | ---- | ----------------------------------------- |
9039| code   | number                               | Yes  | Service request code sent by the remote end.                   |
9040| data   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that holds the parameters called by the client.|
9041| reply  | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object to which the result is written.          |
9042| options | [MessageOption](#messageoption)      | Yes  | Whether the operation is synchronous or asynchronous.                 |
9043
9044**Return value**
9045
9046| Type             | Description                                                                                           |
9047| ----------------- | ----------------------------------------------------------------------------------------------- |
9048| boolean           | Returns a Boolean value if the request is processed synchronously in **onRemoteMessageRequest**. The value **true** means the operation is successful; the value **false** means the opposite.|
9049| Promise\<boolean> | Returns a promise object if the request is processed asynchronously in **onRemoteMessageRequest**.                                |
9050
9051**Example**: Overload **onRemoteMessageRequest** to process requests synchronously.
9052
9053  ```ts
9054  import { hilog } from '@kit.PerformanceAnalysisKit';
9055
9056  class TestRemoteObject extends rpc.RemoteObject {
9057    constructor(descriptor: string) {
9058      super(descriptor);
9059    }
9060
9061    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
9062      if (code === 1) {
9063        hilog.info(0x0000, 'testTag', 'RpcServer: sync onRemoteMessageRequest is called');
9064        return true;
9065      } else {
9066        hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
9067        return false;
9068      }
9069    }
9070  }
9071  ```
9072
9073  **Example**: Overload **onRemoteMessageRequest** to process requests asynchronously.
9074
9075  ```ts
9076  import { hilog } from '@kit.PerformanceAnalysisKit';
9077
9078  class TestRemoteObject extends rpc.RemoteObject {
9079    constructor(descriptor: string) {
9080      super(descriptor);
9081    }
9082
9083    async onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): Promise<boolean> {
9084      if (code === 1) {
9085        hilog.info(0x0000, 'testTag', 'RpcServer: async onRemoteMessageRequest is called');
9086      } else {
9087        hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
9088        return false;
9089      }
9090      await new Promise((resolve: (data: rpc.RequestResult) => void) => {
9091        setTimeout(resolve, 100);
9092      })
9093      return true;
9094    }
9095  }
9096  ```
9097
9098**Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests synchronously.
9099
9100  ```ts
9101  import { hilog } from '@kit.PerformanceAnalysisKit';
9102
9103  class TestRemoteObject extends rpc.RemoteObject {
9104    constructor(descriptor: string) {
9105      super(descriptor);
9106    }
9107
9108    onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, option: rpc.MessageOption): boolean {
9109       if (code === 1) {
9110          hilog.info(0x0000, 'testTag', 'RpcServer: sync onRemoteMessageRequest is called');
9111          return true;
9112       } else {
9113          hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
9114          return false;
9115       }
9116    }
9117      // Only onRemoteMessageRequest is executed.
9118    onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): boolean | Promise<boolean> {
9119      if (code === 1) {
9120        hilog.info(0x0000, 'testTag', 'RpcServer: async onRemoteMessageRequest is called');
9121      } else {
9122        hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
9123        return false;
9124      }
9125      return true;
9126    }
9127  }
9128  ```
9129
9130  **Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests asynchronously.
9131
9132  ```ts
9133  import { hilog } from '@kit.PerformanceAnalysisKit';
9134  class TestRemoteObject extends rpc.RemoteObject {
9135    constructor(descriptor: string) {
9136      super(descriptor);
9137    }
9138
9139    onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, option: rpc.MessageOption): boolean {
9140      if (code === 1) {
9141        hilog.info(0x0000, 'testTag', 'RpcServer: sync onRemoteRequest is called');
9142        return true;
9143      } else {
9144        hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
9145        return false;
9146      }
9147    }
9148    // Only onRemoteMessageRequest is executed.
9149    async onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): Promise<boolean> {
9150      if (code === 1) {
9151        hilog.info(0x0000, 'testTag', 'RpcServer: async onRemoteMessageRequest is called');
9152      } else {
9153        hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
9154        return false;
9155      }
9156      await new Promise((resolve: (data: rpc.RequestResult) => void) => {
9157        setTimeout(resolve, 100);
9158      })
9159      return true;
9160    }
9161  }
9162  ```
9163
9164### onRemoteRequest<sup>(deprecated)</sup>
9165
9166>**NOTE**<br>This API is no longer maintained since API version 9. Use [onRemoteMessageRequest](#onremotemessagerequest9) instead.
9167
9168onRemoteRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
9169
9170Called to return a response to **sendRequest()**. The server processes the request and returns a response in this function.
9171
9172**System capability**: SystemCapability.Communication.IPC.Core
9173
9174**Parameters**
9175
9176| Name| Type                                     | Mandatory| Description                                   |
9177| ------ | ----------------------------------------- | ---- | --------------------------------------- |
9178| code   | number                                    | Yes  | Service request code sent by the remote end.                 |
9179| data   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that holds the parameters called by the client.|
9180| reply  | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object carrying the result.          |
9181| options | [MessageOption](#messageoption)           | Yes  | Whether the operation is synchronous or asynchronous.               |
9182
9183**Return value**
9184
9185| Type   | Description                            |
9186| ------- | -------------------------------- |
9187| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
9188
9189**Example**
9190
9191  ```ts
9192  import { hilog } from '@kit.PerformanceAnalysisKit';
9193
9194  class MyDeathRecipient implements rpc.DeathRecipient {
9195    onRemoteDied() {
9196      hilog.info(0x0000, 'testTag', 'server died');
9197    }
9198  }
9199  class TestRemoteObject extends rpc.RemoteObject {
9200    constructor(descriptor: string) {
9201      super(descriptor);
9202    }
9203    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
9204      return true;
9205    }
9206    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
9207      return true;
9208    }
9209    isObjectDead(): boolean {
9210      return false;
9211    }
9212    onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, option: rpc.MessageOption): boolean {
9213      if (code === 1) {
9214        hilog.info(0x0000, 'testTag', 'RpcServer: onRemoteRequest called');
9215        return true;
9216      } else {
9217        hilog.error(0x0000, 'testTag', 'RpcServer: unknown code: ' + code);
9218        return false;
9219      }
9220    }
9221  }
9222  ```
9223
9224### getCallingUid
9225
9226getCallingUid(): number
9227
9228Obtains the UID of the remote process.
9229
9230**System capability**: SystemCapability.Communication.IPC.Core
9231
9232**Return value**
9233| Type  | Description                   |
9234| ------ | ----------------------- |
9235| number | UID of the remote process obtained.|
9236
9237**Example**
9238
9239  ```ts
9240  import { hilog } from '@kit.PerformanceAnalysisKit';
9241
9242  class TestRemoteObject extends rpc.RemoteObject {
9243    constructor(descriptor: string) {
9244      super(descriptor);
9245    }
9246  }
9247  let testRemoteObject = new TestRemoteObject("testObject");
9248  hilog.info(0x0000, 'testTag', 'RpcServer: getCallingUid: ' + testRemoteObject.getCallingUid());
9249  ```
9250
9251### getCallingPid
9252
9253getCallingPid(): number
9254
9255Obtains the PID of the remote process.
9256
9257**System capability**: SystemCapability.Communication.IPC.Core
9258
9259**Return value**
9260
9261| Type  | Description                   |
9262| ------ | ----------------------- |
9263| number | PID of the remote process obtained.|
9264
9265**Example**
9266
9267  ```ts
9268  import { hilog } from '@kit.PerformanceAnalysisKit';
9269
9270  class TestRemoteObject extends rpc.RemoteObject {
9271    constructor(descriptor: string) {
9272      super(descriptor);
9273    }
9274  }
9275  let testRemoteObject = new TestRemoteObject("testObject");
9276  hilog.info(0x0000, 'testTag', 'RpcServer: getCallingPid: ' + testRemoteObject.getCallingPid());
9277  ```
9278
9279### getLocalInterface<sup>9+</sup>
9280
9281getLocalInterface(descriptor: string): IRemoteBroker
9282
9283Obtains the string of the interface descriptor.
9284
9285**System capability**: SystemCapability.Communication.IPC.Core
9286
9287**Parameters**
9288
9289| Name    | Type  | Mandatory| Description                |
9290| ---------- | ------ | ---- | -------------------- |
9291| descriptor | string | Yes  | Interface descriptor.|
9292
9293**Return value**
9294
9295| Type         | Description                                         |
9296| ------------- | --------------------------------------------- |
9297| IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
9298
9299**Error codes**
9300
9301For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
9302
9303| ID| Error Message|
9304| -------- | -------- |
9305| 401      | check param failed |
9306
9307**Example**
9308
9309  ```ts
9310  import { hilog } from '@kit.PerformanceAnalysisKit';
9311  import { BusinessError } from '@kit.BasicServicesKit';
9312
9313  class MyDeathRecipient implements rpc.DeathRecipient {
9314    onRemoteDied() {
9315      hilog.info(0x0000, 'testTag', 'server died');
9316    }
9317  }
9318  class TestRemoteObject extends rpc.RemoteObject {
9319    constructor(descriptor: string) {
9320      super(descriptor);
9321      this.modifyLocalInterface(this, descriptor);
9322    }
9323    registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
9324      // Implement the method logic based on service requirements.
9325    }
9326    unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
9327      // Implement the method logic based on service requirements.
9328    }
9329    isObjectDead(): boolean {
9330      return false;
9331    }
9332    asObject(): rpc.IRemoteObject {
9333      return this;
9334    }
9335  }
9336  let testRemoteObject = new TestRemoteObject("testObject");
9337  try {
9338    testRemoteObject.getLocalInterface("testObject");
9339  } catch (error) {
9340    let e: BusinessError = error as BusinessError;
9341    hilog.error(0x0000, 'testTag', 'rpc get local interface fail, errorCode ' + e.code);
9342    hilog.error(0x0000, 'testTag', 'rpc get local interface fail, errorMessage ' + e.message);
9343  }
9344  ```
9345
9346### queryLocalInterface<sup>(deprecated)</sup>
9347
9348>**NOTE**<br>This API is no longer maintained since API version 9. Use [getLocalInterface](#getlocalinterface9-2) instead.
9349
9350queryLocalInterface(descriptor: string): IRemoteBroker
9351
9352Checks whether the remote object corresponding to the specified interface token exists.
9353
9354**System capability**: SystemCapability.Communication.IPC.Core
9355
9356**Parameters**
9357
9358| Name    | Type  | Mandatory| Description                  |
9359| ---------- | ------ | ---- | ---------------------- |
9360| descriptor | string | Yes  | Interface descriptor.|
9361
9362**Return value**
9363
9364| Type         | Description                                                              |
9365| ------------- | ------------------------------------------------------------------ |
9366| IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.|
9367
9368**Example**
9369
9370  ```ts
9371  import { hilog } from '@kit.PerformanceAnalysisKit';
9372
9373  class MyDeathRecipient implements rpc.DeathRecipient {
9374    onRemoteDied() {
9375      hilog.info(0x0000, 'testTag', 'server died');
9376    }
9377  }
9378  class TestRemoteObject extends rpc.RemoteObject {
9379    constructor(descriptor: string) {
9380      super(descriptor);
9381      this.attachLocalInterface(this, descriptor);
9382    }
9383    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
9384      return true;
9385    }
9386    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
9387      return true;
9388    }
9389    isObjectDead(): boolean {
9390      return false;
9391    }
9392    asObject(): rpc.IRemoteObject {
9393      return this;
9394    }
9395  }
9396  let testRemoteObject = new TestRemoteObject("testObject");
9397  testRemoteObject.queryLocalInterface("testObject");
9398  ```
9399
9400### getDescriptor<sup>9+</sup>
9401
9402getDescriptor(): string
9403
9404Obtains the interface descriptor of this object. The interface descriptor is a string.
9405
9406**System capability**: SystemCapability.Communication.IPC.Core
9407
9408**Return value**
9409
9410| Type  | Description            |
9411| ------ | ---------------- |
9412| string | Interface descriptor obtained.|
9413
9414**Error codes**
9415
9416For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
9417
9418| ID| Error Message|
9419| -------- | -------- |
9420| 1900008  | proxy or remote object is invalid |
9421
9422**Example**
9423
9424  ```ts
9425  import { hilog } from '@kit.PerformanceAnalysisKit';
9426  import { BusinessError } from '@kit.BasicServicesKit';
9427
9428  class MyDeathRecipient implements rpc.DeathRecipient {
9429    onRemoteDied() {
9430      hilog.info(0x0000, 'testTag', 'server died');
9431    }
9432  }
9433  class TestRemoteObject extends rpc.RemoteObject {
9434    constructor(descriptor: string) {
9435      super(descriptor);
9436    }
9437    registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
9438      // Implement the method logic based on service requirements.
9439    }
9440    unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
9441      // Implement the method logic based on service requirements.
9442    }
9443    isObjectDead(): boolean {
9444      return false;
9445    }
9446  }
9447  let testRemoteObject = new TestRemoteObject("testObject");
9448  try {
9449    let descriptor = testRemoteObject.getDescriptor();
9450    hilog.info(0x0000, 'testTag', 'RpcServer: descriptor is ' + descriptor);
9451  } catch (error) {
9452    let e: BusinessError = error as BusinessError;
9453    hilog.error(0x0000, 'testTag', 'rpc get local interface fail, errorCode ' + e.code);
9454    hilog.error(0x0000, 'testTag', 'rpc get local interface fail, errorMessage ' + e.message);
9455  }
9456  ```
9457
9458### getInterfaceDescriptor<sup>(deprecated)</sup>
9459
9460>**NOTE**<br>This API is no longer maintained since API version 9. Use [getDescriptor](#getdescriptor9-2) instead.
9461
9462getInterfaceDescriptor(): string
9463
9464Obtains the interface descriptor.
9465
9466**System capability**: SystemCapability.Communication.IPC.Core
9467
9468**Return value**
9469
9470| Type  | Description            |
9471| ------ | ---------------- |
9472| string | Interface descriptor obtained.|
9473
9474**Example**
9475
9476  ```ts
9477  import { hilog } from '@kit.PerformanceAnalysisKit';
9478
9479  class MyDeathRecipient implements rpc.DeathRecipient {
9480    onRemoteDied() {
9481      hilog.info(0x0000, 'testTag', 'server died');
9482    }
9483  }
9484  class TestRemoteObject extends rpc.RemoteObject {
9485    constructor(descriptor: string) {
9486      super(descriptor);
9487    }
9488    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
9489      return true;
9490    }
9491    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
9492      return true;
9493    }
9494    isObjectDead(): boolean {
9495      return false;
9496    }
9497  }
9498  let testRemoteObject = new TestRemoteObject("testObject");
9499  let descriptor = testRemoteObject.getInterfaceDescriptor();
9500  hilog.info(0x0000, 'testTag', 'RpcServer: descriptor is: ' + descriptor);
9501  ```
9502
9503### modifyLocalInterface<sup>9+</sup>
9504
9505modifyLocalInterface(localInterface: IRemoteBroker, descriptor: string): void
9506
9507Binds an interface descriptor to an **IRemoteBroker** object.
9508
9509**System capability**: SystemCapability.Communication.IPC.Core
9510
9511**Parameters**
9512
9513| Name        | Type                           | Mandatory| Description                                 |
9514| -------------- | ------------------------------- | ---- | ------------------------------------- |
9515| localInterface | [IRemoteBroker](#iremotebroker) | Yes  | **IRemoteBroker** object.  |
9516| descriptor     | string                          | Yes  | Interface descriptor.|
9517
9518**Error codes**
9519
9520For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
9521
9522| ID| Error Message|
9523| -------- | -------- |
9524| 401      | check param failed |
9525
9526**Example**
9527
9528  ```ts
9529  import { hilog } from '@kit.PerformanceAnalysisKit';
9530  import { BusinessError } from '@kit.BasicServicesKit';
9531
9532  class MyDeathRecipient implements rpc.DeathRecipient {
9533    onRemoteDied() {
9534      hilog.info(0x0000, 'testTag', 'server died');
9535    }
9536  }
9537  class TestRemoteObject extends rpc.RemoteObject {
9538    constructor(descriptor: string) {
9539      super(descriptor);
9540      try {
9541        this.modifyLocalInterface(this, descriptor);
9542      } catch (error) {
9543        let e: BusinessError = error as BusinessError;
9544        hilog.error(0x0000, 'testTag', ' rpc attach local interface fail, errorCode ' + e.code);
9545        hilog.error(0x0000, 'testTag', ' rpc attach local interface fail, errorMessage ' + e.message);
9546      }
9547    }
9548    registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
9549      // Implement the method logic based on service requirements.
9550    }
9551    unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
9552      // Implement the method logic based on service requirements.
9553    }
9554    isObjectDead(): boolean {
9555      return false;
9556    }
9557    asObject(): rpc.IRemoteObject {
9558      return this;
9559    }
9560  }
9561  let testRemoteObject = new TestRemoteObject("testObject");
9562  ```
9563
9564### attachLocalInterface<sup>(deprecated)</sup>
9565
9566>**NOTE**<br>This API is no longer maintained since API version 9. Use [modifyLocalInterface](#modifylocalinterface9) instead.
9567
9568attachLocalInterface(localInterface: IRemoteBroker, descriptor: string): void
9569
9570Binds an interface descriptor to an **IRemoteBroker** object.
9571
9572**System capability**: SystemCapability.Communication.IPC.Core
9573
9574**Parameters**
9575
9576| Name        | Type                           | Mandatory| Description                                 |
9577| -------------- | ------------------------------- | ---- | ------------------------------------- |
9578| localInterface | [IRemoteBroker](#iremotebroker) | Yes  | **IRemoteBroker** object.  |
9579| descriptor     | string                          | Yes  | Interface descriptor.|
9580
9581**Example**
9582
9583  ```ts
9584  import { hilog } from '@kit.PerformanceAnalysisKit';
9585
9586  class MyDeathRecipient implements rpc.DeathRecipient {
9587    onRemoteDied() {
9588      hilog.info(0x0000, 'testTag', 'server died');
9589    }
9590  }
9591  class TestRemoteObject extends rpc.RemoteObject {
9592    constructor(descriptor: string) {
9593      super(descriptor);
9594      this.attachLocalInterface(this, descriptor);
9595    }
9596    addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
9597      return true;
9598    }
9599    removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
9600      return true;
9601    }
9602    isObjectDead(): boolean {
9603      return false;
9604    }
9605    asObject(): rpc.IRemoteObject {
9606      return this;
9607    }
9608  }
9609  let testRemoteObject = new TestRemoteObject("testObject");
9610  ```
9611
9612## Ashmem<sup>8+</sup>
9613
9614Provides methods related to anonymous shared memory objects, including creating, closing, mapping, and unmapping an **Ashmem** object, reading data from and writing data to an **Ashmem** object, obtaining the **Ashmem** size, and setting **Ashmem** protection.
9615
9616**System capability**: SystemCapability.Communication.IPC.Core
9617
9618The table below describes the protection types of the mapped memory.
9619
9620| Name      | Value | Description              |
9621| ---------- | --- | ------------------ |
9622| PROT_EXEC  | 4   | The mapped memory is executable.  |
9623| PROT_NONE  | 0   | The mapped memory is inaccessible.|
9624| PROT_READ  | 1   | The mapped memory is readable.    |
9625| PROT_WRITE | 2   | The mapped memory is writeable.    |
9626
9627### create<sup>9+</sup>
9628
9629static create(name: string, size: number): Ashmem
9630
9631Creates an **Ashmem** object with the specified name and size. This API is a static method.
9632
9633**System capability**: SystemCapability.Communication.IPC.Core
9634
9635**Parameters**
9636
9637| Name| Type  | Mandatory| Description                        |
9638| ------ | ------ | ---- | ---------------------------- |
9639| name   | string | Yes  | Name of the **Ashmem** object to create.  |
9640| size   | number | Yes  | Size (in bytes) of the **Ashmem** object to create.|
9641
9642**Return value**
9643
9644| Type              | Description                                          |
9645| ------------------ | ---------------------------------------------- |
9646| [Ashmem](#ashmem8) | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
9647
9648**Error codes**
9649
9650For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
9651
9652| ID| Error Message|
9653| -------- | -------- |
9654| 401      | check param failed |
9655
9656**Example**
9657
9658  ```ts
9659  import { hilog } from '@kit.PerformanceAnalysisKit';
9660  import { BusinessError } from '@kit.BasicServicesKit';
9661
9662  let ashmem: rpc.Ashmem | undefined = undefined;
9663  try {
9664    ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9665    let size = ashmem.getAshmemSize();
9666    hilog.info(0x0000, 'testTag', 'RpcTest: get ashemm by create: ' + ashmem + ' size is ' + size);
9667  } catch (error) {
9668    let e: BusinessError = error as BusinessError;
9669    hilog.error(0x0000, 'testTag', 'Rpc creat ashmem fail, errorCode ' + e.code);
9670    hilog.error(0x0000, 'testTag', 'Rpc creat ashmem  fail, errorMessage ' + e.message);
9671  }
9672  ```
9673
9674### createAshmem<sup>8+(deprecated)</sup>
9675
9676>**NOTE**<br>This API is no longer maintained since API version 9. Use [create](#create9) instead.
9677
9678static createAshmem(name: string, size: number): Ashmem
9679
9680Creates an **Ashmem** object with the specified name and size. This API is a static method.
9681
9682**System capability**: SystemCapability.Communication.IPC.Core
9683
9684**Parameters**
9685
9686| Name| Type  | Mandatory| Description                        |
9687| ------ | ------ | ---- | ---------------------------- |
9688| name   | string | Yes  | Name of the **Ashmem** object to create.  |
9689| size   | number | Yes  | Size (in bytes) of the **Ashmem** object to create.|
9690
9691**Return value**
9692
9693| Type              | Description                                          |
9694| ------------------ | ---------------------------------------------- |
9695| [Ashmem](#ashmem8) | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
9696
9697**Example**
9698
9699  ```ts
9700  import { hilog } from '@kit.PerformanceAnalysisKit';
9701
9702  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
9703  let size = ashmem.getAshmemSize();
9704  hilog.info(0x0000, 'testTag', 'RpcTest: get ashemm by createAshmem: ' + ashmem + ' size is ' + size);
9705  ```
9706
9707### create<sup>9+</sup>
9708
9709static create(ashmem: Ashmem): Ashmem
9710
9711Creates an **Ashmem** object by copying the file descriptor of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
9712
9713**System capability**: SystemCapability.Communication.IPC.Core
9714
9715**Parameters**
9716
9717| Name| Type              | Mandatory| Description                |
9718| ------ | ------------------ | ---- | -------------------- |
9719| ashmem | [Ashmem](#ashmem8) | Yes  | Existing **Ashmem** object.|
9720
9721**Return value**
9722
9723| Type              | Description                  |
9724| ------------------ | ---------------------- |
9725| [Ashmem](#ashmem8) | **Ashmem** object created.|
9726
9727**Error codes**
9728
9729For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
9730
9731| ID| Error Message|
9732| -------- | -------- |
9733| 401      | check param failed |
9734
9735**Example**
9736
9737  ```ts
9738  import { hilog } from '@kit.PerformanceAnalysisKit';
9739  import { BusinessError } from '@kit.BasicServicesKit';
9740
9741  try {
9742    let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9743    let ashmem2 = rpc.Ashmem.create(ashmem);
9744    let size = ashmem2.getAshmemSize();
9745    hilog.info(0x0000, 'testTag', 'RpcTest: get ashemm by create: ' + ashmem2 + ' size is ' + size);
9746  } catch (error) {
9747    let e: BusinessError = error as BusinessError;
9748    hilog.error(0x0000, 'testTag', 'Rpc creat ashmem from existing fail, errorCode ' + e.code);
9749    hilog.error(0x0000, 'testTag', 'Rpc creat ashmem from existing fail, errorMessage ' + e.message);
9750  }
9751  ```
9752
9753### createAshmemFromExisting<sup>8+(deprecated)</sup>
9754
9755>**NOTE**<br>This API is no longer maintained since API version 9. Use [create](#create9-1) instead.
9756
9757static createAshmemFromExisting(ashmem: Ashmem): Ashmem
9758
9759Creates an **Ashmem** object by copying the file descriptor of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
9760
9761**System capability**: SystemCapability.Communication.IPC.Core
9762
9763**Parameters**
9764
9765| Name| Type              | Mandatory| Description                |
9766| ------ | ------------------ | ---- | -------------------- |
9767| ashmem | [Ashmem](#ashmem8) | Yes  | Existing **Ashmem** object.|
9768
9769**Return value**
9770
9771| Type              | Description                  |
9772| ------------------ | ---------------------- |
9773| [Ashmem](#ashmem8) | **Ashmem** object created.|
9774
9775**Example**
9776
9777  ```ts
9778  import { hilog } from '@kit.PerformanceAnalysisKit';
9779
9780  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9781  let ashmem2 = rpc.Ashmem.createAshmemFromExisting(ashmem);
9782  let size = ashmem2.getAshmemSize();
9783  hilog.info(0x0000, 'testTag', 'RpcTest: get ashemm by createAshmemFromExisting: ' + ashmem2 + ' size is ' + size);
9784  ```
9785
9786### closeAshmem<sup>8+</sup>
9787
9788closeAshmem(): void
9789
9790Closes this **Ashmem** object.
9791
9792**System capability**: SystemCapability.Communication.IPC.Core
9793
9794**Example**
9795
9796  ```ts
9797  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9798  ashmem.closeAshmem();
9799  ```
9800
9801### unmapAshmem<sup>8+</sup>
9802
9803unmapAshmem(): void
9804
9805Deletes the mappings for the specified address range of this **Ashmem** object.
9806
9807**System capability**: SystemCapability.Communication.IPC.Core
9808
9809**Example**
9810
9811  ```ts
9812  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9813  ashmem.unmapAshmem();
9814  ```
9815
9816### getAshmemSize<sup>8+</sup>
9817
9818getAshmemSize(): number
9819
9820Obtains the memory size of this **Ashmem** object.
9821
9822**System capability**: SystemCapability.Communication.IPC.Core
9823
9824**Return value**
9825
9826| Type  | Description                      |
9827| ------ | -------------------------- |
9828| number | **Ashmem** size obtained.|
9829
9830**Example**
9831
9832  ```ts
9833  import { hilog } from '@kit.PerformanceAnalysisKit';
9834
9835  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9836  let size = ashmem.getAshmemSize();
9837  hilog.info(0x0000, 'testTag', 'RpcTest: get ashmem is ' + ashmem + ' size is ' + size);
9838  ```
9839
9840### mapTypedAshmem<sup>9+</sup>
9841
9842mapTypedAshmem(mapType: number): void
9843
9844Creates the shared file mapping on the virtual address space of this process. The size of the mapping region is specified by this **Ashmem** object.
9845
9846**System capability**: SystemCapability.Communication.IPC.Core
9847
9848**Parameters**
9849
9850| Name | Type  | Mandatory| Description                          |
9851| ------- | ------ | ---- | ------------------------------ |
9852| mapType | number | Yes  | Protection level of the memory region to which the shared file is mapped.|
9853
9854**Error codes**
9855
9856For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
9857
9858| ID| Error Message|
9859| -------- | -------- |
9860| 401      | check param failed |
9861| 1900001  | call mmap function failed |
9862
9863**Example**
9864
9865  ```ts
9866  import { hilog } from '@kit.PerformanceAnalysisKit';
9867  import { BusinessError } from '@kit.BasicServicesKit';
9868
9869  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9870  try {
9871    ashmem.mapTypedAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
9872  } catch (error) {
9873    let e: BusinessError = error as BusinessError;
9874    hilog.error(0x0000, 'testTag', 'Rpc map ashmem fail, errorCode ' + e.code);
9875    hilog.error(0x0000, 'testTag', 'Rpc map ashmem fail, errorMessage ' + e.message);
9876  }
9877  ```
9878
9879### mapAshmem<sup>8+(deprecated)</sup>
9880
9881>**NOTE**<br>This API is no longer maintained since API version 9. Use [mapTypedAshmem](#maptypedashmem9) instead.
9882
9883mapAshmem(mapType: number): boolean
9884
9885Creates the shared file mapping on the virtual address space of this process. The size of the mapping region is specified by this **Ashmem** object.
9886
9887**System capability**: SystemCapability.Communication.IPC.Core
9888
9889**Parameters**
9890
9891| Name | Type  | Mandatory| Description                          |
9892| ------- | ------ | ---- | ------------------------------ |
9893| mapType | number | Yes  | Protection level of the memory region to which the shared file is mapped.|
9894
9895**Return value**
9896
9897| Type   | Description                            |
9898| ------- | -------------------------------- |
9899| boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
9900
9901**Example**
9902
9903  ```ts
9904  import { hilog } from '@kit.PerformanceAnalysisKit';
9905
9906  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9907  let mapReadAndWrite = ashmem.mapAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
9908  hilog.info(0x0000, 'testTag', 'RpcTest: map ashmem result is ' + mapReadAndWrite);
9909  ```
9910
9911### mapReadWriteAshmem<sup>9+</sup>
9912
9913mapReadWriteAshmem(): void
9914
9915Maps the shared file to the readable and writable virtual address space of the process.
9916
9917**System capability**: SystemCapability.Communication.IPC.Core
9918
9919**Error codes**
9920
9921For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
9922
9923| ID| Error Message|
9924| -------- | -------- |
9925| 1900001  | call mmap function failed |
9926
9927**Example**
9928
9929  ```ts
9930  import { hilog } from '@kit.PerformanceAnalysisKit';
9931  import { BusinessError } from '@kit.BasicServicesKit';
9932
9933  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9934  try {
9935    ashmem.mapReadWriteAshmem();
9936  } catch (error) {
9937    let e: BusinessError = error as BusinessError;
9938    hilog.error(0x0000, 'testTag', 'Rpc map read and write ashmem fail, errorCode ' + e.code);
9939    hilog.error(0x0000, 'testTag', 'Rpc map read and write ashmem fail, errorMessage ' + e.message);
9940  }
9941  ```
9942
9943### mapReadAndWriteAshmem<sup>8+(deprecated)</sup>
9944
9945>**NOTE**<br>This API is no longer maintained since API version 9. Use [mapReadWriteAshmem](#mapreadwriteashmem9) instead.
9946
9947mapReadAndWriteAshmem(): boolean
9948
9949Maps the shared file to the readable and writable virtual address space of the process.
9950
9951**System capability**: SystemCapability.Communication.IPC.Core
9952
9953**Return value**
9954
9955| Type   | Description                            |
9956| ------- | -------------------------------- |
9957| boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
9958
9959**Example**
9960
9961  ```ts
9962  import { hilog } from '@kit.PerformanceAnalysisKit';
9963
9964  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9965  let mapResult = ashmem.mapReadAndWriteAshmem();
9966  hilog.info(0x0000, 'testTag', 'RpcTest: map ashmem result is ' + mapResult);
9967  ```
9968
9969### mapReadonlyAshmem<sup>9+</sup>
9970
9971mapReadonlyAshmem(): void
9972
9973Maps the shared file to the read-only virtual address space of the process.
9974
9975**System capability**: SystemCapability.Communication.IPC.Core
9976
9977**Error codes**
9978
9979For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
9980
9981| ID| Error Message|
9982| -------- | -------- |
9983| 1900001  | call mmap function failed |
9984
9985**Example**
9986
9987  ```ts
9988  import { hilog } from '@kit.PerformanceAnalysisKit';
9989  import { BusinessError } from '@kit.BasicServicesKit';
9990
9991  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
9992  try {
9993    ashmem.mapReadonlyAshmem();
9994  } catch (error) {
9995    let e: BusinessError = error as BusinessError;
9996    hilog.error(0x0000, 'testTag', 'Rpc map read and write ashmem fail, errorCode ' + e.code);
9997    hilog.error(0x0000, 'testTag', 'Rpc map read and write ashmem fail, errorMessage ' + e.message);
9998  }
9999  ```
10000
10001### mapReadOnlyAshmem<sup>8+(deprecated)</sup>
10002
10003>**NOTE**<br>This API is no longer maintained since API version 9. Use [mapReadonlyAshmem](#mapreadonlyashmem9) instead.
10004
10005mapReadOnlyAshmem(): boolean
10006
10007Maps the shared file to the read-only virtual address space of the process.
10008
10009**System capability**: SystemCapability.Communication.IPC.Core
10010
10011**Return value**
10012
10013| Type   | Description                            |
10014| ------- | -------------------------------- |
10015| boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
10016
10017**Example**
10018
10019  ```ts
10020  import { hilog } from '@kit.PerformanceAnalysisKit';
10021
10022  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10023  let mapResult = ashmem.mapReadOnlyAshmem();
10024  hilog.info(0x0000, 'testTag', 'RpcTest: Ashmem mapReadOnlyAshmem result is ' + mapResult);
10025  ```
10026
10027### setProtectionType<sup>9+</sup>
10028
10029setProtectionType(protectionType: number): void
10030
10031Sets the protection level of the memory region to which the shared file is mapped.
10032
10033**System capability**: SystemCapability.Communication.IPC.Core
10034
10035**Parameters**
10036
10037| Name        | Type  | Mandatory| Description              |
10038| -------------- | ------ | ---- | ------------------ |
10039| protectionType | number | Yes  | Protection type to set.|
10040
10041**Error codes**
10042
10043For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
10044
10045| ID| Error Message|
10046| -------- | -------- |
10047| 401      | check param failed |
10048| 1900002  | call os ioctl function failed |
10049
10050**Example**
10051
10052  ```ts
10053  import { hilog } from '@kit.PerformanceAnalysisKit';
10054  import { BusinessError } from '@kit.BasicServicesKit';
10055
10056  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10057  try {
10058    ashmem.setProtection(ashmem.PROT_READ);
10059  } catch (error) {
10060    let e: BusinessError = error as BusinessError;
10061    hilog.error(0x0000, 'testTag', 'Rpc set protection type fail, errorCode ' + e.code);
10062    hilog.error(0x0000, 'testTag', 'Rpc set protection type fail, errorMessage ' + e.message);
10063  }
10064  ```
10065
10066### setProtection<sup>8+(deprecated)</sup>
10067
10068>**NOTE**<br>This API is no longer maintained since API version 9. Use [setProtectionType](#setprotectiontype9) instead.
10069
10070setProtection(protectionType: number): boolean
10071
10072Sets the protection level of the memory region to which the shared file is mapped.
10073
10074**System capability**: SystemCapability.Communication.IPC.Core
10075
10076**Parameters**
10077
10078| Name        | Type  | Mandatory| Description              |
10079| -------------- | ------ | ---- | ------------------ |
10080| protectionType | number | Yes  | Protection type to set.|
10081
10082**Return value**
10083
10084| Type   | Description                            |
10085| ------- | -------------------------------- |
10086| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
10087
10088**Example**
10089
10090  ```ts
10091  import { hilog } from '@kit.PerformanceAnalysisKit';
10092
10093  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10094  let result = ashmem.setProtection(ashmem.PROT_READ);
10095  hilog.info(0x0000, 'testTag', 'RpcTest: Ashmem setProtection result is ' + result);
10096  ```
10097
10098### writeDataToAshmem<sup>11+</sup>
10099
10100writeDataToAshmem(buf: ArrayBuffer, size: number, offset: number): void
10101
10102Writes data to the shared file associated with this **Ashmem** object.
10103
10104**System capability**: SystemCapability.Communication.IPC.Core
10105
10106**Parameters**
10107
10108| Name| Type    | Mandatory| Description                                              |
10109| ------ | -------- | ---- | -------------------------------------------------- |
10110| buf    | ArrayBuffer | Yes  | Data to write.                            |
10111| size   | number   | Yes  | Size of the data to write.                                |
10112| offset | number   | Yes  | Start position of the data to write in the memory region associated with this **Ashmem** object.|
10113
10114**Error codes**
10115
10116For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
10117
10118| ID| Error Message|
10119| -------- | -------- |
10120| 401      | check param failed |
10121| 1900003  | write to ashmem failed |
10122
10123**Example**
10124
10125  ```ts
10126  import { hilog } from '@kit.PerformanceAnalysisKit';
10127  import { BusinessError } from '@kit.BasicServicesKit';
10128
10129  let buffer = new ArrayBuffer(1024);
10130  let int32View = new Int32Array(buffer);
10131  for (let i = 0; i < int32View.length; i++) {
10132    int32View[i] = i * 2 + 1;
10133  }
10134  let size = buffer.byteLength;
10135  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10136  ashmem.mapReadWriteAshmem();
10137  try {
10138    ashmem.writeDataToAshmem(buffer, size, 0);
10139  } catch (error) {
10140    let e: BusinessError = error as BusinessError;
10141    hilog.error(0x0000, 'testTag', 'Rpc write to ashmem fail, errorCode ' + e.code);
10142    hilog.error(0x0000, 'testTag', 'Rpc write to ashmem fail, errorMessage ' + e.message);
10143  }
10144  ```
10145
10146### writeAshmem<sup>9+(deprecated)</sup>
10147
10148>**NOTE**<br>This API is no longer maintained since API version 11. Use [writeDataToAshmem](#writedatatoashmem11) instead.
10149
10150writeAshmem(buf: number[], size: number, offset: number): void
10151
10152Writes data to the shared file associated with this **Ashmem** object.
10153
10154**System capability**: SystemCapability.Communication.IPC.Core
10155
10156**Parameters**
10157
10158| Name| Type    | Mandatory| Description                                              |
10159| ------ | -------- | ---- | -------------------------------------------------- |
10160| buf    | number[] | Yes  | Data to write.                            |
10161| size   | number   | Yes  | Size of the data to write.                                |
10162| offset | number   | Yes  | Start position of the data to write in the memory region associated with this **Ashmem** object.|
10163
10164**Error codes**
10165
10166For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
10167
10168| ID| Error Message|
10169| -------- | -------- |
10170| 401      | check param failed |
10171| 1900003  | write to ashmem failed |
10172
10173**Example**
10174
10175  ```ts
10176  import { hilog } from '@kit.PerformanceAnalysisKit';
10177  import { BusinessError } from '@kit.BasicServicesKit';
10178
10179  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10180  ashmem.mapReadWriteAshmem();
10181  let ByteArrayVar = [1, 2, 3, 4, 5];
10182  try {
10183    ashmem.writeAshmem(ByteArrayVar, 5, 0);
10184  } catch (error) {
10185    let e: BusinessError = error as BusinessError;
10186    hilog.error(0x0000, 'testTag', 'Rpc write to ashmem fail, errorCode ' + e.code);
10187    hilog.error(0x0000, 'testTag', 'Rpc write to ashmem fail, errorMessage ' + e.message);
10188  }
10189  ```
10190
10191### writeToAshmem<sup>8+(deprecated)</sup>
10192
10193>**NOTE**<br>This API is no longer maintained since API version 9. Use [writeDataToAshmem](#writedatatoashmem11) instead.
10194
10195writeToAshmem(buf: number[], size: number, offset: number): boolean
10196
10197Writes data to the shared file associated with this **Ashmem** object.
10198
10199**System capability**: SystemCapability.Communication.IPC.Core
10200
10201**Parameters**
10202
10203| Name| Type    | Mandatory| Description                                              |
10204| ------ | -------- | ---- | -------------------------------------------------- |
10205| buf    | number[] | Yes  | Data to write.                            |
10206| size   | number   | Yes  | Size of the data to write.                                |
10207| offset | number   | Yes  | Start position of the data to write in the memory region associated with this **Ashmem** object.|
10208
10209**Return value**
10210
10211| Type   | Description                                                                         |
10212| ------- | ----------------------------------------------------------------------------- |
10213| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
10214
10215**Example**
10216
10217  ```ts
10218  import { hilog } from '@kit.PerformanceAnalysisKit';
10219
10220  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10221  let mapResult = ashmem.mapReadAndWriteAshmem();
10222  hilog.info(0x0000, 'testTag', 'RpcTest map ashmem result is ' + mapResult);
10223  let ByteArrayVar = [1, 2, 3, 4, 5];
10224  let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
10225  hilog.info(0x0000, 'testTag', 'RpcTest: write to Ashmem result is ' + writeResult);
10226  ```
10227
10228### readDataFromAshmem<sup>11+</sup>
10229
10230readDataFromAshmem(size: number, offset: number): ArrayBuffer
10231
10232Reads data from the shared file associated with this **Ashmem** object.
10233
10234**System capability**: SystemCapability.Communication.IPC.Core
10235
10236**Parameters**
10237
10238| Name| Type  | Mandatory| Description                                              |
10239| ------ | ------ | ---- | -------------------------------------------------- |
10240| size   | number | Yes  | Size of the data to read.                              |
10241| offset | number | Yes  | Start position of the data to read in the memory region associated with this **Ashmem** object.|
10242
10243**Return value**
10244
10245| Type    | Description            |
10246| -------- | ---------------- |
10247| ArrayBuffer | Data read.|
10248
10249**Error codes**
10250
10251For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
10252
10253| ID| Error Message|
10254| -------- | -------- |
10255| 401      | check param failed |
10256| 1900004  | read from ashmem failed |
10257
10258**Example**
10259
10260  ```ts
10261  import { hilog } from '@kit.PerformanceAnalysisKit';
10262  import { BusinessError } from '@kit.BasicServicesKit';
10263
10264  let buffer = new ArrayBuffer(1024);
10265  let int32View = new Int32Array(buffer);
10266  for (let i = 0; i < int32View.length; i++) {
10267    int32View[i] = i * 2 + 1;
10268  }
10269  let size = buffer.byteLength;
10270  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10271  ashmem.mapReadWriteAshmem();
10272  try {
10273    ashmem.writeDataToAshmem(buffer, size, 0);
10274  } catch (error) {
10275    let e: BusinessError = error as BusinessError;
10276    hilog.error(0x0000, 'testTag', 'Rpc write to ashmem fail, errorCode ' + e.code);
10277    hilog.error(0x0000, 'testTag', 'Rpc write to ashmem fail, errorMessage ' + e.message);
10278  }
10279  try {
10280    let readResult = ashmem.readDataFromAshmem(size, 0);
10281    let readInt32View = new Int32Array(readResult);
10282    hilog.info(0x0000, 'testTag', 'RpcTest: read from Ashmem result is ' + readInt32View);
10283  } catch (error) {
10284    let e: BusinessError = error as BusinessError;
10285    hilog.error(0x0000, 'testTag', 'Rpc read from ashmem fail, errorCode ' + e.code);
10286    hilog.error(0x0000, 'testTag', 'Rpc read from ashmem fail, errorMessage ' + e.message);
10287  }
10288  ```
10289
10290### readAshmem<sup>9+(deprecated)</sup>
10291
10292>**NOTE**<br>This API is no longer maintained since API version 9. Use [readDataFromAshmem](#readdatafromashmem11) instead.
10293
10294readAshmem(size: number, offset: number): number[]
10295
10296Reads data from the shared file associated with this **Ashmem** object.
10297
10298**System capability**: SystemCapability.Communication.IPC.Core
10299
10300**Parameters**
10301
10302| Name| Type  | Mandatory| Description                                              |
10303| ------ | ------ | ---- | -------------------------------------------------- |
10304| size   | number | Yes  | Size of the data to read.                              |
10305| offset | number | Yes  | Start position of the data to read in the memory region associated with this **Ashmem** object.|
10306
10307**Return value**
10308
10309| Type    | Description            |
10310| -------- | ---------------- |
10311| number[] | Data read.|
10312
10313**Error codes**
10314
10315For details about the error codes, see [RPC Error Codes](errorcode-rpc.md).
10316
10317| ID| Error Message|
10318| -------- | -------- |
10319| 401      | check param failed |
10320| 1900004  | read from ashmem failed |
10321
10322**Example**
10323
10324  ```ts
10325  import { hilog } from '@kit.PerformanceAnalysisKit';
10326  import { BusinessError } from '@kit.BasicServicesKit';
10327
10328  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10329  ashmem.mapReadWriteAshmem();
10330  let ByteArrayVar = [1, 2, 3, 4, 5];
10331  ashmem.writeAshmem(ByteArrayVar, 5, 0);
10332  try {
10333    let readResult = ashmem.readAshmem(5, 0);
10334    hilog.info(0x0000, 'testTag', 'RpcTest: read from Ashmem result is ' + readResult);
10335  } catch (error) {
10336    let e: BusinessError = error as BusinessError;
10337    hilog.error(0x0000, 'testTag', 'Rpc read from ashmem fail, errorCode ' + e.code);
10338    hilog.error(0x0000, 'testTag', 'Rpc read from ashmem fail, errorMessage ' + e.message);
10339  }
10340  ```
10341
10342### readFromAshmem<sup>8+(deprecated)</sup>
10343
10344>**NOTE**<br>This API is no longer maintained since API version 9. Use [readDataFromAshmem](#readdatafromashmem11) instead.
10345
10346readFromAshmem(size: number, offset: number): number[]
10347
10348Reads data from the shared file associated with this **Ashmem** object.
10349
10350**System capability**: SystemCapability.Communication.IPC.Core
10351
10352**Parameters**
10353
10354| Name| Type  | Mandatory| Description                                              |
10355| ------ | ------ | ---- | -------------------------------------------------- |
10356| size   | number | Yes  | Size of the data to read.                              |
10357| offset | number | Yes  | Start position of the data to read in the memory region associated with this **Ashmem** object.|
10358
10359**Return value**
10360
10361| Type    | Description            |
10362| -------- | ---------------- |
10363| number[] | Data read.|
10364
10365**Example**
10366
10367 ``` ts
10368  import { hilog } from '@kit.PerformanceAnalysisKit';
10369
10370  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
10371  let mapResult = ashmem.mapReadAndWriteAshmem();
10372  hilog.info(0x0000, 'testTag', 'RpcTest map ashmem result is ' + mapResult);
10373  let ByteArrayVar = [1, 2, 3, 4, 5];
10374  let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
10375  hilog.info(0x0000, 'testTag', 'RpcTest: write to Ashmem result is ' + writeResult);
10376  let readResult = ashmem.readFromAshmem(5, 0);
10377  hilog.info(0x0000, 'testTag', 'RpcTest: read to Ashmem result is ' + readResult);
10378 ```
10379