• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 '@ohos.rpc';
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## MessageSequence<sup>9+</sup>
42
43Provides APIs for reading and writing data in specific format.
44
45During 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.
46
47### create
48
49  static create(): MessageSequence
50
51  Creates a **MessageSequence** object. This API is a static method.
52
53**System capability**: SystemCapability.Communication.IPC.Core
54
55**Return value**
56
57  | Type           | Description                           |
58  | --------------- | ------------------------------- |
59  | MessageSequence | **MessageSequence** object created.|
60
61**Example**
62
63  ```ts
64  let data = rpc.MessageSequence.create();
65  console.log("RpcClient: data is " + data);
66  ```
67
68### reclaim
69
70reclaim(): void
71
72Reclaims the **MessageSequence** object that is no longer used.
73
74**System capability**: SystemCapability.Communication.IPC.Core
75
76**Example**
77
78  ```ts
79  let reply = rpc.MessageSequence.create();
80  reply.reclaim();
81  ```
82
83### writeRemoteObject
84
85writeRemoteObject(object: [IRemoteObject](#iremoteobject)): void
86
87Serializes a remote object and writes it to this **MessageSequence** object.
88
89**System capability**: SystemCapability.Communication.IPC.Core
90
91**Parameters**
92
93  | Name| Type                           | Mandatory| Description                                     |
94  | ------ | ------------------------------- | ---- | ----------------------------------------- |
95  | object | [IRemoteObject](#iremoteobject) | Yes  | Remote object to serialize and write to the **MessageSequence** object.|
96
97**Error codes**
98
99For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
100
101  | ID| Error Message|
102  | -------- | ------- |
103  | 1900008 | proxy or remote object is invalid |
104  | 1900009 | write data to message sequence failed |
105
106**Example**
107
108  ```ts
109  class TestRemoteObject extends rpc.RemoteObject {
110      constructor(descriptor) {
111          super(descriptor);
112      }
113  }
114  let data = rpc.MessageSequence.create();
115  let testRemoteObject = new TestRemoteObject("testObject");
116  try {
117      data.writeRemoteObject(testRemoteObject);
118  } catch(error) {
119      console.info("Rpc write remote object fail, errorCode " + error.code);
120      console.info("Rpc write remote object fail, errorMessage " + error.message);
121  }
122  ```
123
124### readRemoteObject
125
126readRemoteObject(): IRemoteObject
127
128Reads 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.
129
130**System capability**: SystemCapability.Communication.IPC.Core
131
132**Return value**
133
134  | Type                           | Description              |
135  | ------------------------------- | ------------------ |
136  | [IRemoteObject](#iremoteobject) | Remote object obtained.|
137
138**Error codes**
139
140For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
141
142  | ID| Error Message|
143  | ------- | -------- |
144  | 1900008 | proxy or remote object is invalid |
145  | 1900010 | read data from message sequence failed |
146
147**Example**
148
149  ```ts
150  class TestRemoteObject extends rpc.RemoteObject {
151      constructor(descriptor) {
152          super(descriptor);
153      }
154  }
155  let data = rpc.MessageSequence.create();
156  let testRemoteObject = new TestRemoteObject("testObject");
157  try {
158      data.writeRemoteObject(testRemoteObject);
159      let proxy = data.readRemoteObject();
160  } catch(error) {
161      console.info("Rpc write remote object fail, errorCode " + error.code);
162      console.info("Rpc write remote object fail, errorMessage " + error.message);
163  }
164  ```
165
166### writeInterfaceToken
167
168writeInterfaceToken(token: string): void
169
170Writes an interface token to this **MessageSequence** object. The remote object can use this interface token to verify the communication.
171
172**System capability**: SystemCapability.Communication.IPC.Core
173
174**Parameters**
175
176  | Name| Type  | Mandatory| Description              |
177  | ------ | ------ | ---- | ------------------ |
178  | token  | string | Yes  | Interface token to write.|
179
180**Error codes**
181
182For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
183
184  | ID| Error Message|
185  | ------- | -------- |
186  | 1900009 | write data to message sequence failed |
187
188**Example**
189
190  ```ts
191  let data = rpc.MessageSequence.create();
192  try {
193      data.writeInterfaceToken("aaa");
194  } catch(error) {
195      console.info("rpc write interface fail, errorCode " + error.code);
196      console.info("rpc write interface fail, errorMessage " + error.message);
197  }
198  ```
199
200### readInterfaceToken
201
202readInterfaceToken(): string
203
204Reads 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.
205
206**System capability**: SystemCapability.Communication.IPC.Core
207
208**Return value**
209
210  | Type  | Description                    |
211  | ------ | ------------------------ |
212  | string | Interface token obtained.|
213
214**Error codes**
215
216For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
217
218  | ID| Error Message|
219  | ------- | ----- |
220  | 1900010 | read data from message sequence failed |
221
222**Example**
223
224```ts
225class Stub extends rpc.RemoteObject {
226    onRemoteRequest(code, data, reply, option) {
227        try {
228            let interfaceToken = data.readInterfaceToken();
229            console.log("RpcServer: interfaceToken is " + interfaceToken);
230        } catch(error) {
231            console.info("RpcServer: read interfaceToken failed, errorCode " + error.code);
232            console.info("RpcServer: read interfaceToken failed, errorMessage " + error.message);
233        }
234        return true;
235    }
236}
237  ```
238
239### getSize
240
241getSize(): number
242
243Obtains the data size of this **MessageSequence** object.
244
245**System capability**: SystemCapability.Communication.IPC.Core
246
247**Return value**
248
249  | Type  | Description                                           |
250  | ------ | ----------------------------------------------- |
251  | number | Size of the **MessageSequence** object obtained, in bytes.|
252
253**Example**
254
255  ```ts
256  let data = rpc.MessageSequence.create();
257  let size = data.getSize();
258  console.log("RpcClient: size is " + size);
259  ```
260
261### getCapacity
262
263getCapacity(): number
264
265Obtains the capacity of this **MessageSequence** object.
266
267**System capability**: SystemCapability.Communication.IPC.Core
268
269**Return value**
270
271  | Type  | Description|
272  | ------ | ----- |
273  | number | **MessageSequence** capacity obtained, in bytes.|
274
275**Example**
276
277  ```ts
278  let data = rpc.MessageSequence.create();
279  let result = data.getCapacity();
280  console.log("RpcClient: capacity is " + result);
281  ```
282
283### setSize
284
285setSize(size: number): void
286
287Sets the size of the data contained in this **MessageSequence** object.
288
289**System capability**: SystemCapability.Communication.IPC.Core
290
291**Parameters**
292
293  | Name| Type  | Mandatory| Description|
294  | ------ | ------ | ---- | ------ |
295  | size   | number | Yes  | Data size to set, in bytes.|
296
297**Example**
298
299  ```ts
300  let data = rpc.MessageSequence.create();
301  try {
302      data.setSize(16);
303      console.log("RpcClient: setSize is " + data.getSize());
304  } catch(error) {
305      console.info("rpc set size of MessageSequence fail, errorCode " + error.code);
306      console.info("rpc set size of MessageSequence fail, errorMessage " + error.message);
307  }
308  ```
309
310### setCapacity
311
312setCapacity(size: number): void
313
314Sets the storage capacity of this **MessageSequence** object.
315
316**System capability**: SystemCapability.Communication.IPC.Core
317
318**Parameters**
319
320  | Name| Type  | Mandatory| Description                                         |
321  | ------ | ------ | ---- | --------------------------------------------- |
322  | size   | number | Yes  | Storage capacity of the **MessageSequence** object to set, in bytes.|
323
324**Error codes**
325
326For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
327
328  | ID| Error Message|
329  | -------- | ------ |
330  | 1900011 | parcel memory alloc failed |
331
332**Example**
333
334  ```ts
335  let data = rpc.MessageSequence.create();
336  try {
337      data.setCapacity(100);
338      console.log("RpcClient: setCapacity is " + data.getCapacity());
339  } catch(error) {
340      console.info("rpc memory alloc fail, errorCode " + error.code);
341      console.info("rpc memory alloc fail, errorMessage " + error.message);
342  }
343  ```
344
345### getWritableBytes
346
347getWritableBytes(): number
348
349Obtains the writable capacity (in bytes) of this **MessageSequence** object.
350
351**System capability**: SystemCapability.Communication.IPC.Core
352
353**Return value**
354
355  | Type| Description|
356  | ------ | ------ |
357  | number | Writable capacity of the **MessageSequence** instance, in bytes.|
358
359**Example**
360
361```ts
362class Stub extends rpc.RemoteObject {
363    onRemoteRequest(code, data, reply, option) {
364        let getWritableBytes = data.getWritableBytes();
365        console.log("RpcServer: getWritableBytes is " + getWritableBytes);
366        return true;
367    }
368}
369  ```
370
371### getReadableBytes
372
373getReadableBytes(): number
374
375Obtains the readable capacity of this **MessageSequence** object.
376
377**System capability**: SystemCapability.Communication.IPC.Core
378
379**Return value**
380
381  | Type| Description|
382  | ------ | ------- |
383  | number | Readable capacity of the **MessageSequence** instance, in bytes.|
384
385**Example**
386
387  ```ts
388class Stub extends rpc.RemoteObject {
389    onRemoteRequest(code, data, reply, option) {
390        let result = data.getReadableBytes();
391        console.log("RpcServer: getReadableBytes is " + result);
392        return true;
393    }
394}
395  ```
396
397### getReadPosition
398
399getReadPosition(): number
400
401Obtains the read position of this **MessageSequence** object.
402
403**System capability**: SystemCapability.Communication.IPC.Core
404
405**Return value**
406
407  | Type| Description|
408  | ------ | ------ |
409  | number | Read position obtained.|
410
411**Example**
412
413  ```ts
414  let data = rpc.MessageSequence.create();
415  let readPos = data.getReadPosition();
416  console.log("RpcClient: readPos is " + readPos);
417  ```
418
419### getWritePosition
420
421getWritePosition(): number
422
423Obtains the write position of this **MessageSequence** object.
424
425**System capability**: SystemCapability.Communication.IPC.Core
426
427**Return value**
428
429  | Type| Description|
430  | ------ | ----- |
431  | number | Write position obtained.|
432
433**Example**
434
435  ```ts
436  let data = rpc.MessageSequence.create();
437  data.writeInt(10);
438  let bwPos = data.getWritePosition();
439  console.log("RpcClient: bwPos is " + bwPos);
440  ```
441
442### rewindRead
443
444rewindRead(pos: number): void
445
446Moves the read pointer to the specified position.
447
448**System capability**: SystemCapability.Communication.IPC.Core
449
450**Parameters**
451
452  | Name| Type| Mandatory| Description|
453  | ------ | ------ | ---- | ------- |
454  | pos    | number | Yes  | Position from which data is to read.|
455
456**Example**
457
458  ```ts
459  let data = rpc.MessageSequence.create();
460  data.writeInt(12);
461  data.writeString("sequence");
462  let number = data.readInt();
463  console.log("RpcClient: number is " + number);
464  try {
465      data.rewindRead(0);
466  } catch(error) {
467      console.info("rpc rewind read data fail, errorCode " + error.code);
468      console.info("rpc rewind read data fail, errorMessage " + error.message);
469  }
470  let number2 = data.readInt();
471  console.log("RpcClient: rewindRead is " + number2);
472  ```
473
474### rewindWrite
475
476rewindWrite(pos: number): void
477
478Moves the write pointer to the specified position.
479
480**System capability**: SystemCapability.Communication.IPC.Core
481
482**Parameters**
483
484  | Name| Type| Mandatory| Description|
485  | ------ | ------ | ---- | ----- |
486  | pos    | number | Yes  | Position from which data is to write.|
487
488**Example**
489
490  ```ts
491  let data = rpc.MessageSequence.create();
492  data.writeInt(4);
493  try {
494      data.rewindWrite(0);
495  } catch(error) {
496      console.info("rpc rewind read data fail, errorCode " + error.code);
497      console.info("rpc rewind read data fail, errorMessage " + error.message);
498  }
499  data.writeInt(5);
500  let number = data.readInt();
501  console.log("RpcClient: rewindWrite is: " + number);
502  ```
503
504### writeByte
505
506writeByte(val: number): void
507
508Writes a byte value to this **MessageSequence** object.
509
510**System capability**: SystemCapability.Communication.IPC.Core
511
512**Parameters**
513
514  | Name| Type  | Mandatory| Description|
515  | ----- | ------ | ---- | ----- |
516  | val | number | Yes| Byte value to write.|
517
518**Error codes**
519
520For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
521
522  | ID| Error Message|
523  | -------- | ------- |
524  | 1900009 | write data to message sequence failed |
525
526**Example**
527
528  ```ts
529  let data = rpc.MessageSequence.create();
530  try {
531      data.writeByte(2);
532  } catch(error) {
533    console.info("rpc write byte fail, errorCode " + error.code);
534    console.info("rpc write byte fail, errorMessage" + error.message);
535  }
536  ```
537
538### readByte
539
540readByte(): number
541
542Reads the byte value from this **MessageSequence** object.
543
544**System capability**: SystemCapability.Communication.IPC.Core
545
546**Return value**
547
548  | Type  | Description|
549  | ------ | ----- |
550  | number | Byte value read.|
551
552**Error codes**
553
554For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
555
556  | ID| Error Message|
557  | ------- | --------  |
558  | 1900010 | read data from message sequence failed |
559
560**Example**
561
562  ```ts
563  let data = rpc.MessageSequence.create();
564  try {
565      data.writeByte(2);
566  } catch(error) {
567    console.info("rpc write byte fail, errorCode " + error.code);
568    console.info("rpc write byte fail, errorMessage" + error.message);
569  }
570  try {
571      let ret = data.readByte();
572      console.log("RpcClient: readByte is: " + ret);
573  } catch(error) {
574    console.info("rpc write byte fail, errorCode " + error.code);
575    console.info("rpc write byte fail, errorMessage" + error.message);
576  }
577  ```
578
579### writeShort
580
581writeShort(val: number): void
582
583Writes a short integer to this **MessageSequence** object.
584
585**System capability**: SystemCapability.Communication.IPC.Core
586
587**Parameters**
588
589  | Name| Type  | Mandatory| Description|
590  | ------ | ------ | --- | --- |
591  | val | number | Yes| Short integer to write.|
592
593**Error codes**
594
595For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
596
597  | ID| Error Message|
598  | ------- | ------ |
599  | 1900009 | write data to message sequence failed |
600
601**Example**
602
603  ```ts
604  let data = rpc.MessageSequence.create();
605  try {
606      data.writeShort(8);
607  } catch(error) {
608      console.info("rpc write short fail, errorCode " + error.code);
609      console.info("rpc write short fail, errorMessage" + error.message);
610  }
611  ```
612
613### readShort
614
615readShort(): number
616
617Reads the short integer from this **MessageSequence** object.
618
619**System capability**: SystemCapability.Communication.IPC.Core
620
621**Return value**
622
623  | Type  | Description          |
624  | ------ | -------------- |
625  | number | Short integer read.|
626
627**Error codes**
628
629For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
630
631  | ID| Error Message|
632  | ------- | -------- |
633  | 1900010 | read data from message sequence failed |
634
635**Example**
636
637  ```ts
638  let data = rpc.MessageSequence.create();
639  try {
640      data.writeShort(8);
641  } catch(error) {
642      console.info("rpc write short fail, errorCode " + error.code);
643      console.info("rpc write short fail, errorMessage" + error.message);
644  }
645  try {
646      let ret = data.readShort();
647      console.log("RpcClient: readByte is: " + ret);
648  } catch(error) {
649      console.info("rpc read short fail, errorCode " + error.code);
650      console.info("rpc read short fail, errorMessage" + error.message);
651  }
652  ```
653
654### writeInt
655
656writeInt(val: number): void
657
658Writes an integer to this **MessageSequence** object.
659
660**System capability**: SystemCapability.Communication.IPC.Core
661
662**Parameters**
663
664  | Name| Type  | Mandatory| Description            |
665  | ------ | ------ | ---- | ---------------- |
666  | val    | number | Yes  | Integer to write.|
667
668**Error codes**
669
670For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
671
672  | ID| Error Message|
673  | -------- | ------- |
674  | 1900009 | write data to message sequence failed |
675
676**Example**
677
678  ```ts
679  let data = rpc.MessageSequence.create();
680  try {
681      data.writeInt(10);
682  } catch(error) {
683      console.info("rpc write int fail, errorCode " + error.code);
684      console.info("rpc write int fail, errorMessage" + error.message);
685  }
686  ```
687
688### readInt
689
690readInt(): number
691
692Reads the integer from this **MessageSequence** object.
693
694**System capability**: SystemCapability.Communication.IPC.Core
695
696**Return value**
697
698  | Type  | Description        |
699  | ------ | ------------ |
700  | number | Integer read.|
701
702**Error codes**
703
704For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
705
706  | ID| Error Message|
707  | ------- | ------- |
708  | 1900010 | read data from message sequence failed |
709
710**Example**
711
712  ```ts
713  let data = rpc.MessageSequence.create();
714  try {
715      data.writeInt(10);
716  } catch(error) {
717      console.info("rpc write int fail, errorCode " + error.code);
718      console.info("rpc write int fail, errorMessage" + error.message);
719  }
720  try {
721      let ret = data.readInt();
722      console.log("RpcClient: readInt is " + ret);
723  } catch(error) {
724      console.info("rpc read int fail, errorCode " + error.code);
725      console.info("rpc read int fail, errorMessage" + error.message);
726  }
727  ```
728
729### writeLong
730
731writeLong(val: number): void
732
733Writes a long integer to this **MessageSequence** object.
734
735**System capability**: SystemCapability.Communication.IPC.Core
736
737**Parameters**
738
739  | Name| Type  | Mandatory| Description            |
740  | ------ | ------ | ---- | ---------------- |
741  | val    | number | Yes  | Long integer to write.|
742
743**Error codes**
744
745For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
746
747  | ID| Error Message|
748  | ------- | ------- |
749  | 1900009 | write data to message sequence failed |
750
751**Example**
752
753  ```ts
754  let data = rpc.MessageSequence.create();
755  try {
756      data.writeLong(10000);
757  } catch(error) {
758      console.info("rpc write long fail, errorCode " + error.code);
759      console.info("rpc write long fail, errorMessage" + error.message);
760  }
761  ```
762
763### readLong
764
765readLong(): number
766
767Reads the long integer from this **MessageSequence** object.
768
769**System capability**: SystemCapability.Communication.IPC.Core
770
771**Return value**
772
773  | Type  | Description          |
774  | ------ | -------------- |
775  | number | Long integer read.|
776
777**Error codes**
778
779For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
780
781  | ID| Error Message|
782  | ------- | -------- |
783  | 1900010 | read data from message sequence failed |
784
785**Example**
786
787  ```ts
788  let data = rpc.MessageSequence.create();
789  try {
790      data.writeLong(10000);
791  } catch(error) {
792      console.info("rpc write long fail, errorCode " + error.code);
793      console.info("rpc write long fail, errorMessage" + error.message);
794  }
795  try {
796      let ret = data.readLong();
797      console.log("RpcClient: readLong is " + ret);
798  } catch(error) {
799      console.info("rpc read long fail, errorCode " + error.code);
800      console.info("rpc read long fail, errorMessage" + error.message);
801  }
802  ```
803
804### writeFloat
805
806writeFloat(val: number): void
807
808Writes a floating-point number to this **MessageSequence** object.
809
810**System capability**: SystemCapability.Communication.IPC.Core
811
812**Parameters**
813
814  | Name| Type| Mandatory| Description|
815  | ----- | ---- | ---- | ----- |
816  | val | number | Yes| Floating-point number to write.|
817
818**Error codes**
819
820For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
821
822  | ID| Error Message|
823  | ------- | ------- |
824  | 1900009 | write data to message sequence failed |
825
826**Example**
827
828  ```ts
829  let data = rpc.MessageSequence.create();
830  try {
831      data.writeFloat(1.2);
832  } catch(error) {
833      console.info("rpc write float fail, errorCode " + error.code);
834      console.info("rpc write float fail, errorMessage" + error.message);
835  }
836  ```
837
838### readFloat
839
840readFloat(): number
841
842Reads the floating-pointer number from this **MessageSequence** object.
843
844**System capability**: SystemCapability.Communication.IPC.Core
845
846**Return value**
847
848  | Type  | Description        |
849  | ------ | ------------ |
850  | number | Floating-point number read.|
851
852**Error codes**
853
854For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
855
856  | ID| Error Message|
857  | ------- | -------- |
858  | 1900010 | read data from message sequence failed |
859
860**Example**
861
862  ```ts
863  let data = rpc.MessageSequence.create();
864  try {
865      data.writeFloat(1.2);
866  } catch(error) {
867      console.info("rpc write float fail, errorCode " + error.code);
868      console.info("rpc write float fail, errorMessage" + error.message);
869  }
870  try {
871      let ret = data.readFloat();
872      console.log("RpcClient: readFloat is " + ret);
873  } catch(error) {
874      console.info("rpc read float fail, errorCode " + error.code);
875      console.info("rpc read float fail, errorMessage" + error.message);
876  }
877  ```
878
879### writeDouble
880
881writeDouble(val: number): void
882
883Writes a double-precision floating-point number to this **MessageSequence** object.
884
885**System capability**: SystemCapability.Communication.IPC.Core
886
887**Parameters**
888
889  | Name| Type  | Mandatory| Description                  |
890  | ------ | ------ | ---- | ---------------------- |
891  | val    | number | Yes  | Double-precision floating-point number to write.|
892
893**Error codes**
894
895For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
896
897  | ID| Error Message|
898  | ------- | -------- |
899  | 1900009 | write data to message sequence failed |
900
901**Example**
902
903  ```ts
904  let data = rpc.MessageSequence.create();
905  try {
906      data.writeDouble(10.2);
907  } catch(error) {
908      console.info("rpc read float fail, errorCode " + error.code);
909      console.info("rpc read float fail, errorMessage" + error.message);
910  }
911  ```
912
913### readDouble
914
915readDouble(): number
916
917Reads the double-precision floating-point number from this **MessageSequence** object.
918
919**System capability**: SystemCapability.Communication.IPC.Core
920
921**Return value**
922
923  | Type  | Description              |
924  | ------ | ------------------ |
925  | number | Double-precision floating-point number read.|
926
927**Error codes**
928
929For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
930
931  | ID| Error Message|
932  | ------- | -------- |
933  | 1900010 | read data from message sequence failed |
934
935**Example**
936
937  ```ts
938  let data = rpc.MessageSequence.create();
939  try {
940      data.writeDouble(10.2);
941  } catch(error) {
942      console.info("rpc write double fail, errorCode " + error.code);
943      console.info("rpc write double fail, errorMessage" + error.message);
944  }
945  try {
946      let ret = data.readDouble();
947      console.log("RpcClient: readDouble is " + ret);
948  } catch(error) {
949      console.info("rpc read double fail, errorCode " + error.code);
950      console.info("rpc read double fail, errorMessage" + error.message);
951  }
952  ```
953
954### writeBoolean
955
956writeBoolean(val: boolean): void
957
958Writes a Boolean value to this **MessageSequence** object.
959
960**System capability**: SystemCapability.Communication.IPC.Core
961
962**Parameters**
963
964  | Name| Type   | Mandatory| Description            |
965  | ------ | ------- | ---- | ---------------- |
966  | val    | boolean | Yes  | Boolean value to write.|
967
968**Error codes**
969
970For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
971
972  | ID| Error Message|
973  | ------- | ------- |
974  | 1900009 | write data to message sequence failed |
975
976**Example**
977
978  ```ts
979  let data = rpc.MessageSequence.create();
980  try {
981      data.writeBoolean(false);
982  } catch(error) {
983      console.info("rpc write boolean fail, errorCode " + error.code);
984      console.info("rpc write boolean fail, errorMessage" + error.message);
985  }
986  ```
987
988### readBoolean
989
990readBoolean(): boolean
991
992Reads the Boolean value from this **MessageSequence** object.
993
994**System capability**: SystemCapability.Communication.IPC.Core
995
996**Return value**
997
998  | Type   | Description                |
999  | ------- | -------------------- |
1000  | boolean | Boolean value read.|
1001
1002**Error codes**
1003
1004For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1005
1006  | ID| Error Message|
1007  | -------- | ------- |
1008  | 1900010 | read data from message sequence failed |
1009
1010**Example**
1011
1012  ```ts
1013  let data = rpc.MessageSequence.create();
1014  try {
1015      data.writeBoolean(false);
1016  } catch(error) {
1017      console.info("rpc write boolean fail, errorCode " + error.code);
1018      console.info("rpc write boolean fail, errorMessage" + error.message);
1019  }
1020  try {
1021      let ret = data.readBoolean();
1022      console.log("RpcClient: readBoolean is " + ret);
1023  } catch(error) {
1024      console.info("rpc read boolean fail, errorCode " + error.code);
1025      console.info("rpc read boolean fail, errorMessage" + error.message);
1026  }
1027  ```
1028
1029### writeChar
1030
1031writeChar(val: number): void
1032
1033Writes a character to this **MessageSequence** object.
1034
1035**System capability**: SystemCapability.Communication.IPC.Core
1036
1037**Parameters**
1038
1039  | Name| Type  | Mandatory| Description                |
1040  | ------ | ------ | ---- | -------------------- |
1041  | val    | number | Yes  | Single character to write.|
1042
1043**Error codes**
1044
1045For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1046
1047  | ID| Error Message|
1048  | ------- | -------- |
1049  | 1900009 | write data to message sequence failed |
1050
1051**Example**
1052
1053  ```ts
1054  let data = rpc.MessageSequence.create();
1055  try {
1056      data.writeChar(97);
1057  } catch(error) {
1058      console.info("rpc write char fail, errorCode " + error.code);
1059      console.info("rpc write char fail, errorMessage" + error.message);
1060  }
1061  ```
1062
1063### readChar
1064
1065readChar(): number
1066
1067Reads the character from this **MessageSequence** object.
1068
1069**System capability**: SystemCapability.Communication.IPC.Core
1070
1071**Return value**
1072
1073  | Type  | Description|
1074  | ------ | ---- |
1075  | number | Character read.|
1076
1077**Error codes**
1078
1079For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1080
1081  | ID| Error Message|
1082  | ------ | --------- |
1083  | 1900010 | read data from message sequence failed |
1084
1085**Example**
1086
1087  ```ts
1088  let data = rpc.MessageSequence.create();
1089  try {
1090      data.writeChar(97);
1091  } catch(error) {
1092      console.info("rpc write char fail, errorCode " + error.code);
1093      console.info("rpc write char fail, errorMessage" + error.message);
1094  }
1095  try {
1096      let ret = data.readChar();
1097      console.log("RpcClient: readChar is " + ret);
1098  } catch(error) {
1099      console.info("rpc read char fail, errorCode " + error.code);
1100      console.info("rpc read char fail, errorMessage" + error.message);
1101  }
1102  ```
1103
1104### writeString
1105
1106writeString(val: string): void
1107
1108Writes a string to this **MessageSequence** object.
1109
1110**System capability**: SystemCapability.Communication.IPC.Core
1111
1112**Parameters**
1113
1114  | Name| Type  | Mandatory| Description                                     |
1115  | ------ | ------ | ---- | ----------------------------------------- |
1116  | val    | string | Yes  | String to write. The length of the string must be less than 40960 bytes.|
1117
1118**Error codes**
1119
1120For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1121
1122  | ID| Error Message|
1123  | ------- | -------- |
1124  | 1900009 | write data to message sequence failed |
1125
1126**Example**
1127
1128  ```ts
1129  let data = rpc.MessageSequence.create();
1130  try {
1131      data.writeString('abc');
1132  } catch(error) {
1133      console.info("rpc write string fail, errorCode " + error.code);
1134      console.info("rpc write string fail, errorMessage" + error.message);
1135  }
1136  ```
1137
1138### readString
1139
1140readString(): string
1141
1142Reads the string from this **MessageSequence** object.
1143
1144**System capability**: SystemCapability.Communication.IPC.Core
1145
1146**Return value**
1147
1148  | Type  | Description          |
1149  | ------ | -------------- |
1150  | string | String read.|
1151
1152**Error codes**
1153
1154For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1155
1156  | ID| Error Message|
1157  | ------- | -------- |
1158  | 1900010 | read data from message sequence failed |
1159
1160**Example**
1161
1162  ```ts
1163  let data = rpc.MessageSequence.create();
1164  try {
1165      data.writeString('abc');
1166  } catch(error) {
1167      console.info("rpc write string fail, errorCode " + error.code);
1168      console.info("rpc write string fail, errorMessage" + error.message);
1169  }
1170  try {
1171      let ret = data.readString();
1172      console.log("RpcClient: readString is " + ret);
1173  } catch(error) {
1174      console.info("rpc read string fail, errorCode " + error.code);
1175      console.info("rpc read string fail, errorMessage" + error.message);
1176  }
1177  ```
1178
1179### writeParcelable
1180
1181writeParcelable(val: Parcelable): void
1182
1183Writes a **Parcelable** object to this **MessageSequence** object.
1184
1185**System capability**: SystemCapability.Communication.IPC.Core
1186
1187**Parameters**
1188
1189  | Name| Type| Mandatory| Description|
1190  | ------ | --------- | ---- | ------ |
1191  | val    | Parcelable | Yes  | **Parcelable** object to write.|
1192
1193**Error codes**
1194
1195For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1196
1197  | ID| Error Message|
1198  | ------- | -------- |
1199  | 1900009 | write data to message sequence failed |
1200
1201**Example**
1202
1203  ```ts
1204  class MySequenceable {
1205      num: number;
1206      str: string;
1207      constructor(num, str) {
1208          this.num = num;
1209          this.str = str;
1210      }
1211      marshalling(messageSequence) {
1212          messageSequence.writeInt(this.num);
1213          messageSequence.writeString(this.str);
1214          return true;
1215      }
1216      unmarshalling(messageSequence) {
1217          this.num = messageSequence.readInt();
1218          this.str = messageSequence.readString();
1219          return true;
1220      }
1221  }
1222  let parcelable = new MySequenceable(1, "aaa");
1223  let data = rpc.MessageSequence.create();
1224  try {
1225      data.writeParcelable(parcelable);
1226  } catch(error) {
1227      console.info("rpc write parcelable fail, errorCode " + error.code);
1228      console.info("rpc write parcelable fail, errorMessage" + error.message);
1229  }
1230  ```
1231
1232### readParcelable
1233
1234readParcelable(dataIn: Parcelable): void
1235
1236Reads a **Parcelable** object from this **MessageSequence** object to the specified object (**dataIn**).
1237
1238**System capability**: SystemCapability.Communication.IPC.Core
1239
1240**Parameters**
1241
1242  | Name| Type                     | Mandatory| Description                                     |
1243  | ------ | ------------------------- | ---- | ----------------------------------------- |
1244  | dataIn | Parcelable | Yes  | **Parcelable** object to read.|
1245
1246**Error codes**
1247
1248For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1249
1250  | ID| Error Message|
1251  | -------- | ------- |
1252  | 1900010 | read data from message sequence failed |
1253  | 1900012 | call js callback function failed |
1254
1255**Example**
1256
1257  ```ts
1258  class MySequenceable {
1259      num: number;
1260      str: string;
1261      constructor(num, str) {
1262          this.num = num;
1263          this.str = str;
1264      }
1265      marshalling(messageSequence) {
1266          messageSequence.writeInt(this.num);
1267          messageSequence.writeString(this.str);
1268          return true;
1269      }
1270      unmarshalling(messageSequence) {
1271          this.num = messageSequence.readInt();
1272          this.str = messageSequence.readString();
1273          return true;
1274      }
1275  }
1276  let parcelable = new MySequenceable(1, "aaa");
1277  let data = rpc.MessageSequence.create();
1278  data.writeParcelable(parcelable);
1279  let ret = new MySequenceable(0, "");
1280  try {
1281      data.readParcelable(ret);
1282  }catch(error) {
1283      console.info("rpc read parcelable fail, errorCode " + error.code);
1284      console.info("rpc read parcelable fail, errorMessage" + error.message);
1285  }
1286  ```
1287
1288### writeByteArray
1289
1290writeByteArray(byteArray: number[]): void
1291
1292Writes a byte array to this **MessageSequence** object.
1293
1294**System capability**: SystemCapability.Communication.IPC.Core
1295
1296**Parameters**
1297
1298  | Name   | Type    | Mandatory| Description              |
1299  | --------- | -------- | ---- | ------------------ |
1300  | byteArray | number[] | Yes  | Byte array to write.|
1301
1302**Error codes**
1303
1304For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1305
1306  | ID| Error Message|
1307  | ------- | -------- |
1308  | 1900009 | write data to message sequence failed |
1309
1310**Example**
1311
1312  ```ts
1313  let data = rpc.MessageSequence.create();
1314  let ByteArrayVar = [1, 2, 3, 4, 5];
1315  try {
1316      data.writeByteArray(ByteArrayVar);
1317  } catch(error) {
1318      console.info("rpc write byteArray fail, errorCode " + error.code);
1319      console.info("rpc write byteArray fail, errorMessage" + error.message);
1320  }
1321  ```
1322
1323### readByteArray
1324
1325readByteArray(dataIn: number[]): void
1326
1327Reads a byte array from this **MessageSequence** object.
1328
1329**System capability**: SystemCapability.Communication.IPC.Core
1330
1331**Parameters**
1332
1333  | Name| Type    | Mandatory| Description              |
1334  | ------ | -------- | ---- | ------------------ |
1335  | dataIn | number[] | Yes  | Byte array to read.|
1336
1337**Error codes**
1338
1339For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1340
1341  | ID| Error Message|
1342  | ------- | -------- |
1343  | 1900010 | read data from message sequence failed |
1344
1345**Example**
1346
1347  ```ts
1348  let data = rpc.MessageSequence.create();
1349  let ByteArrayVar = [1, 2, 3, 4, 5];
1350  try {
1351      data.writeByteArray(ByteArrayVar);
1352  } catch(error) {
1353      console.info("rpc write byteArray fail, errorCode " + error.code);
1354      console.info("rpc write byteArray fail, errorMessage" + error.message);
1355  }
1356  try {
1357      let array = new Array(5);
1358      data.readByteArray(array);
1359  } catch(error) {
1360      console.info("rpc write byteArray fail, errorCode " + error.code);
1361      console.info("rpc write byteArray fail, errorMessage" + error.message);
1362  }
1363  ```
1364
1365### readByteArray
1366
1367readByteArray(): number[]
1368
1369Reads the byte array from this **MessageSequence** object.
1370
1371**System capability**: SystemCapability.Communication.IPC.Core
1372
1373**Return value**
1374
1375  | Type    | Description          |
1376  | -------- | -------------- |
1377  | number[] | Byte array read.|
1378
1379**Error codes**
1380
1381For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1382
1383  | ID| Error Message|
1384  | -------- | ------- |
1385  | 1900010 | read data from message sequence failed |
1386
1387**Example**
1388
1389  ```ts
1390  let data = rpc.MessageSequence.create();
1391  let byteArrayVar = [1, 2, 3, 4, 5];
1392  try {
1393      data.writeByteArray(byteArrayVar);
1394  } catch(error) {
1395      console.info("rpc write byteArray fail, errorCode " + error.code);
1396      console.info("rpc write byteArray fail, errorMessage" + error.message);
1397  }
1398  try {
1399      let array = data.readByteArray();
1400      console.log("RpcClient: readByteArray is " + array);
1401  } catch(error) {
1402      console.info("rpc read byteArray fail, errorCode " + error.code);
1403      console.info("rpc read byteArray fail, errorMessage" + error.message);
1404  }
1405  ```
1406
1407### writeShortArray
1408
1409writeShortArray(shortArray: number[]): void
1410
1411Writes a short array to this **MessageSequence** object.
1412
1413**System capability**: SystemCapability.Communication.IPC.Core
1414
1415**Parameters**
1416
1417  | Name    | Type    | Mandatory| Description                |
1418  | ---------- | -------- | ---- | -------------------- |
1419  | shortArray | number[] | Yes  | Short array to write.|
1420
1421**Error codes**
1422
1423For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1424
1425  | ID| Error Message|
1426  | ----- | ----- |
1427  | 1900009 | write data to message sequence failed |
1428
1429**Example**
1430
1431  ```ts
1432  let data = rpc.MessageSequence.create();
1433  try {
1434      data.writeShortArray([11, 12, 13]);
1435  } catch(error) {
1436      console.info("rpc read byteArray fail, errorCode " + error.code);
1437      console.info("rpc read byteArray fail, errorMessage" + error.message);
1438  }
1439  ```
1440
1441### readShortArray
1442
1443readShortArray(dataIn: number[]): void
1444
1445Reads a short array from this **MessageSequence** object.
1446
1447**System capability**: SystemCapability.Communication.IPC.Core
1448
1449**Parameters**
1450
1451  | Name| Type    | Mandatory| Description                |
1452  | ------ | -------- | ---- | -------------------- |
1453  | dataIn | number[] | Yes  | Short array to read.|
1454
1455**Error codes**
1456
1457For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1458
1459  | ID| Error Message|
1460  | ------ | ------- |
1461  | 1900010 | read data from message sequence failed |
1462
1463**Example**
1464
1465  ```ts
1466  let data = rpc.MessageSequence.create();
1467  try {
1468      data.writeShortArray([11, 12, 13]);
1469  } catch(error) {
1470      console.info("rpc write shortArray fail, errorCode " + error.code);
1471      console.info("rpc write shortArray fail, errorMessage" + error.message);
1472  }
1473  try {
1474      let array = new Array(3);
1475      data.readShortArray(array);
1476  } catch(error) {
1477      console.info("rpc read shortArray fail, errorCode " + error.code);
1478      console.info("rpc read shortArray fail, errorMessage" + error.message);
1479  }
1480  ```
1481
1482### readShortArray
1483
1484readShortArray(): number[]
1485
1486Reads the short array from this **MessageSequence** object.
1487
1488**System capability**: SystemCapability.Communication.IPC.Core
1489
1490**Return value**
1491
1492  | Type    | Description            |
1493  | -------- | ---------------- |
1494  | number[] | Short array read.|
1495
1496**Error codes**
1497
1498For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1499
1500  | ID| Error Message|
1501  | -------- | ------- |
1502  | 1900010 | read data from message sequence failed |
1503
1504**Example**
1505
1506  ```ts
1507  let data = rpc.MessageSequence.create();
1508  try {
1509      data.writeShortArray([11, 12, 13]);
1510  } catch(error) {
1511      console.info("rpc write shortArray fail, errorCode " + error.code);
1512      console.info("rpc write shortArray fail, errorMessage" + error.message);
1513  }
1514  try {
1515      let array = data.readShortArray();
1516      console.log("RpcClient: readShortArray is " + array);
1517  } catch(error) {
1518      console.info("rpc read shortArray fail, errorCode " + error.code);
1519      console.info("rpc read shortArray fail, errorMessage" + error.message);
1520  }
1521  ```
1522
1523### writeIntArray
1524
1525writeIntArray(intArray: number[]): void
1526
1527Writes an integer array to this **MessageSequence** object.
1528
1529**System capability**: SystemCapability.Communication.IPC.Core
1530
1531**Parameters**
1532
1533  | Name  | Type    | Mandatory| Description              |
1534  | -------- | -------- | ---- | ------------------ |
1535  | intArray | number[] | Yes  | Integer array to write.|
1536
1537**Error codes**
1538
1539For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1540
1541  | ID| Error Message|
1542  | ----- | --------- |
1543  | 1900009 | write data to message sequence failed |
1544
1545**Example**
1546
1547  ```ts
1548  let data = rpc.MessageSequence.create();
1549  try {
1550      data.writeIntArray([100, 111, 112]);
1551  } catch(error) {
1552      console.info("rpc write intArray fail, errorCode " + error.code);
1553      console.info("rpc write intArray fail, errorMessage" + error.message);
1554  }
1555  ```
1556
1557### readIntArray
1558
1559readIntArray(dataIn: number[]): void
1560
1561Reads an integer array from this **MessageSequence** object.
1562
1563**System capability**: SystemCapability.Communication.IPC.Core
1564
1565**Parameters**
1566
1567  | Name| Type    | Mandatory| Description              |
1568  | ------ | -------- | ---- | ------------------ |
1569  | dataIn | number[] | Yes  | Integer array to read.|
1570
1571**Error codes**
1572
1573For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1574
1575  | ID| Error Message|
1576  | ------- | -------- |
1577  | 1900010 | read data from message sequence failed |
1578
1579**Example**
1580
1581  ```ts
1582  let data = rpc.MessageSequence.create();
1583  try {
1584      data.writeIntArray([100, 111, 112]);
1585  } catch(error) {
1586      console.info("rpc write intArray fail, errorCode " + error.code);
1587      console.info("rpc write intArray fail, errorMessage" + error.message);
1588  }
1589  let array = new Array(3);
1590  try {
1591      data.readIntArray(array);
1592  } catch(error) {
1593      console.info("rpc read intArray fail, errorCode " + error.code);
1594      console.info("rpc read intArray fail, errorMessage" + error.message);
1595  }
1596  ```
1597
1598### readIntArray
1599
1600readIntArray(): number[]
1601
1602Reads the integer array from this **MessageSequence** object.
1603
1604**System capability**: SystemCapability.Communication.IPC.Core
1605
1606**Return value**
1607
1608  | Type    | Description          |
1609  | -------- | -------------- |
1610  | number[] | Integer array read.|
1611
1612**Error codes**
1613
1614For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1615
1616  | ID| Error Message|
1617  | ----- | ------- |
1618  | 1900010 | read data from message sequence failed |
1619
1620**Example**
1621
1622  ```ts
1623  let data = rpc.MessageSequence.create();
1624  try {
1625      data.writeIntArray([100, 111, 112]);
1626  } catch(error) {
1627      console.info("rpc write intArray fail, errorCode " + error.code);
1628      console.info("rpc write intArray fail, errorMessage" + error.message);
1629  }
1630  try {
1631    let array = data.readIntArray();
1632    console.log("RpcClient: readIntArray is " + array);
1633  } catch(error) {
1634      console.info("rpc read intArray fail, errorCode " + error.code);
1635      console.info("rpc read intArray fail, errorMessage" + error.message);
1636  }
1637  ```
1638
1639### writeLongArray
1640
1641writeLongArray(longArray: number[]): void
1642
1643Writes a long array to this **MessageSequence** object.
1644
1645**System capability**: SystemCapability.Communication.IPC.Core
1646
1647**Parameters**
1648
1649  | Name   | Type    | Mandatory| Description                |
1650  | --------- | -------- | ---- | -------------------- |
1651  | longArray | number[] | Yes  | Long array to write.|
1652
1653**Error codes**
1654
1655For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1656
1657  | ID| Error Message|
1658  | -------  | ----- |
1659  | 1900009 | write data to message sequence failed |
1660
1661**Example**
1662
1663  ```ts
1664  let data = rpc.MessageSequence.create();
1665  try {
1666      data.writeLongArray([1111, 1112, 1113]);
1667  }catch(error){
1668      console.info("rpc write longArray fail, errorCode " + error.code);
1669      console.info("rpc write longArray fail, errorMessage" + error.message);
1670  }
1671  ```
1672
1673### readLongArray
1674
1675readLongArray(dataIn: number[]): void
1676
1677Reads a long array from this **MessageSequence** object.
1678
1679**System capability**: SystemCapability.Communication.IPC.Core
1680
1681**Parameters**
1682
1683  | Name| Type    | Mandatory| Description                |
1684  | ------ | -------- | ---- | -------------------- |
1685  | dataIn | number[] | Yes  | Long array to read.|
1686
1687**Error codes**
1688
1689For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1690
1691  | ID| Error Message|
1692  | ------- | ------ |
1693  | 1900010 | read data from message sequence failed |
1694
1695**Example**
1696
1697  ```ts
1698  let data = rpc.MessageSequence.create();
1699  try {
1700      data.writeLongArray([1111, 1112, 1113]);
1701  } catch(error) {
1702      console.info("rpc write longArray fail, errorCode " + error.code);
1703      console.info("rpc write longArray fail, errorMessage" + error.message);
1704  }
1705  let array = new Array(3);
1706  try {
1707      data.readLongArray(array);
1708  } catch(error) {
1709      console.info("rpc read longArray fail, errorCode " + error.code);
1710      console.info("rpc read longArray fail, errorMessage" + error.message);
1711  }
1712  ```
1713
1714### readLongArray
1715
1716readLongArray(): number[]
1717
1718Reads the long array from this **MessageSequence** object.
1719
1720**System capability**: SystemCapability.Communication.IPC.Core
1721
1722**Return value**
1723
1724  | Type    | Description            |
1725  | -------- | ---------------- |
1726  | number[] | Long array read.|
1727
1728**Error codes**
1729
1730For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1731
1732  | ID| Error Message|
1733  | ------- | -------- |
1734  | 1900010 | read data from message sequence failed |
1735
1736**Example**
1737
1738  ```ts
1739  let data = rpc.MessageSequence.create();
1740  try {
1741      data.writeLongArray([1111, 1112, 1113]);
1742  } catch(error) {
1743      console.info("rpc write longArray fail, errorCode " + error.code);
1744      console.info("rpc write longArray fail, errorMessage" + error.message);
1745  }
1746  try {
1747      let array = data.readLongArray();
1748      console.log("RpcClient: readLongArray is " + array);
1749  } catch(error) {
1750      console.info("rpc read longArray fail, errorCode " + error.code);
1751      console.info("rpc read longArray fail, errorMessage" + error.message);
1752  }
1753  ```
1754
1755### writeFloatArray
1756
1757writeFloatArray(floatArray: number[]): void
1758
1759Writes a floating-point array to this **MessageSequence** object.
1760
1761**System capability**: SystemCapability.Communication.IPC.Core
1762
1763**Parameters**
1764
1765  | Name    | Type    | Mandatory| Description                                                                                                                   |
1766  | ---------- | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
1767  | 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.|
1768
1769**Error codes**
1770
1771For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1772
1773  | ID| Error Message|
1774  | ------- | -------- |
1775  | 1900009 | write data to message sequence failed |
1776
1777**Example**
1778
1779  ```ts
1780  let data = rpc.MessageSequence.create();
1781  try {
1782      data.writeFloatArray([1.2, 1.3, 1.4]);
1783  } catch(error) {
1784      console.info("rpc write floatArray fail, errorCode " + error.code);
1785      console.info("rpc write floatArray fail, errorMessage" + error.message);
1786  }
1787  ```
1788
1789### readFloatArray
1790
1791readFloatArray(dataIn: number[]): void
1792
1793Reads a floating-point array from this **MessageSequence** object.
1794
1795**System capability**: SystemCapability.Communication.IPC.Core
1796
1797**Parameters**
1798
1799  | Name| Type    | Mandatory| Description                                                                                                                   |
1800  | ------ | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
1801  | 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.|
1802
1803**Error codes**
1804
1805For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1806
1807  | ID| Error Message|
1808  | ------- | -------- |
1809  | 1900010 | read data from message sequence failed |
1810
1811**Example**
1812
1813  ```ts
1814  let data = rpc.MessageSequence.create();
1815  try {
1816      data.writeFloatArray([1.2, 1.3, 1.4]);
1817  }catch(error){
1818      console.info("rpc write floatArray fail, errorCode " + error.code);
1819      console.info("rpc write floatArray fail, errorMessage" + error.message);
1820  }
1821  let array = new Array(3);
1822  try {
1823      data.readFloatArray(array);
1824  } catch(error) {
1825      console.info("rpc read floatArray fail, errorCode " + error.code);
1826      console.info("rpc read floatArray fail, errorMessage" + error.message);
1827  }
1828  ```
1829
1830### readFloatArray
1831
1832readFloatArray(): number[]
1833
1834Reads the floating-point array from this **MessageSequence** object.
1835
1836**System capability**: SystemCapability.Communication.IPC.Core
1837
1838**Return value**
1839
1840  | Type    | Description          |
1841  | -------- | -------------- |
1842  | number[] | Floating-point array read.|
1843
1844**Error codes**
1845
1846For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1847
1848  | ID| Error Message|
1849  | ------- | -------- |
1850  | 1900010 | read data from message sequence failed |
1851
1852**Example**
1853
1854  ```ts
1855  let data = rpc.MessageSequence.create();
1856  try {
1857      data.writeFloatArray([1.2, 1.3, 1.4]);
1858  } catch(error) {
1859      console.info("rpc write floatArray fail, errorCode " + error.code);
1860      console.info("rpc write floatArray fail, errorMessage" + error.message);
1861  }
1862  try {
1863      let array = data.readFloatArray();
1864      console.log("RpcClient: readFloatArray is " + array);
1865  } catch(error) {
1866      console.info("rpc read floatArray fail, errorCode " + error.code);
1867      console.info("rpc read floatArray fail, errorMessage" + error.message);
1868  }
1869  ```
1870
1871### writeDoubleArray
1872
1873writeDoubleArray(doubleArray: number[]): void
1874
1875Writes a double-precision floating-point array to this **MessageSequence** object.
1876
1877**System capability**: SystemCapability.Communication.IPC.Core
1878
1879**Parameters**
1880
1881  | Name     | Type    | Mandatory| Description                    |
1882  | ----------- | -------- | ---- | ------------------------ |
1883  | doubleArray | number[] | Yes  | Double-precision floating-point array to write.|
1884
1885**Error codes**
1886
1887For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1888
1889  | ID| Error Message|
1890  | ------- | -------- |
1891  | 1900009 | write data to message sequence failed |
1892
1893**Example**
1894
1895  ```ts
1896  let data = rpc.MessageSequence.create();
1897  try {
1898      data.writeDoubleArray([11.1, 12.2, 13.3]);
1899  } catch(error) {
1900      console.info("rpc write doubleArray fail, errorCode " + error.code);
1901      console.info("rpc write doubleArray fail, errorMessage" + error.message);
1902  }
1903  ```
1904
1905### readDoubleArray
1906
1907readDoubleArray(dataIn: number[]): void
1908
1909Reads a double-precision floating-point array from this **MessageSequence** object.
1910
1911**System capability**: SystemCapability.Communication.IPC.Core
1912
1913**Parameters**
1914
1915  | Name| Type    | Mandatory| Description                    |
1916  | ------ | -------- | ---- | ------------------------ |
1917  | dataIn | number[] | Yes  | Double-precision floating-point array to read.|
1918
1919**Error codes**
1920
1921For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1922
1923  | ID| Error Message|
1924  | ------- | -------- |
1925  | 1900010 | read data from message sequence failed |
1926
1927**Example**
1928
1929  ```ts
1930  let data = rpc.MessageSequence.create();
1931  try {
1932      data.writeDoubleArray([11.1, 12.2, 13.3]);
1933  } catch(error) {
1934      console.info("rpc write doubleArray fail, errorCode " + error.code);
1935      console.info("rpc write doubleArray fail, errorMessage" + error.message);
1936  }
1937  let array = new Array(3);
1938  try {
1939      data.readDoubleArray(array);
1940  } catch(error) {
1941      console.info("rpc read doubleArray fail, errorCode " + error.code);
1942      console.info("rpc read doubleArray fail, errorMessage" + error.message);
1943  }
1944  ```
1945
1946### readDoubleArray
1947
1948readDoubleArray(): number[]
1949
1950Reads the double-precision floating-point array from this **MessageSequence** object.
1951
1952**System capability**: SystemCapability.Communication.IPC.Core
1953
1954**Return value**
1955
1956  | Type    | Description                |
1957  | -------- | -------------------- |
1958  | number[] | Double-precision floating-point array read.|
1959
1960**Error codes**
1961
1962For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
1963
1964  | ID| Error Message|
1965  | ------- | -------- |
1966  | 1900010 | read data from message sequence failed |
1967
1968**Example**
1969
1970  ```ts
1971  let data = rpc.MessageSequence.create();
1972  try {
1973      data.writeDoubleArray([11.1, 12.2, 13.3]);
1974  } catch(error) {
1975      console.info("rpc write doubleArray fail, errorCode " + error.code);
1976      console.info("rpc write doubleArray fail, errorMessage" + error.message);
1977  }
1978  try {
1979      let array = data.readDoubleArray();
1980      console.log("RpcClient: readDoubleArray is " + array);
1981  } catch(error) {
1982      console.info("rpc read doubleArray fail, errorCode " + error.code);
1983      console.info("rpc read doubleArray fail, errorMessage" + error.message);
1984  }
1985  ```
1986
1987### writeBooleanArray
1988
1989writeBooleanArray(booleanArray: boolean[]): void
1990
1991Writes a Boolean array to this **MessageSequence** object.
1992
1993**System capability**: SystemCapability.Communication.IPC.Core
1994
1995**Parameters**
1996
1997  | Name      | Type     | Mandatory| Description              |
1998  | ------------ | --------- | ---- | ------------------ |
1999  | booleanArray | boolean[] | Yes  | Boolean array to write.|
2000
2001**Error codes**
2002
2003For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2004
2005  | ID| Error Message|
2006  | ------- | -------- |
2007  | 1900009 | write data to message sequence failed |
2008
2009**Example**
2010
2011  ```ts
2012  let data = rpc.MessageSequence.create();
2013  try {
2014      data.writeBooleanArray([false, true, false]);
2015  } catch(error) {
2016      console.info("rpc write booleanArray fail, errorCode " + error.code);
2017      console.info("rpc write booleanArray fail, errorMessage" + error.message);
2018  }
2019  ```
2020
2021### readBooleanArray
2022
2023readBooleanArray(dataIn: boolean[]): void
2024
2025Reads a Boolean array from this **MessageSequence** object.
2026
2027**System capability**: SystemCapability.Communication.IPC.Core
2028
2029**Parameters**
2030
2031  | Name| Type     | Mandatory| Description              |
2032  | ------ | --------- | ---- | ------------------ |
2033  | dataIn | boolean[] | Yes  | Boolean array to read.|
2034
2035**Error codes**
2036
2037For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2038
2039  | ID| Error Message|
2040  | ------- | -------- |
2041  | 1900010 | read data from message sequence failed |
2042
2043**Example**
2044
2045  ```ts
2046  let data = rpc.MessageSequence.create();
2047  try {
2048      data.writeBooleanArray([false, true, false]);
2049  } catch(error) {
2050      console.info("rpc write booleanArray fail, errorCode " + error.code);
2051      console.info("rpc write booleanArray fail, errorMessage" + error.message);
2052  }
2053  let array = new Array(3);
2054  try {
2055      data.readBooleanArray(array);
2056  } catch(error) {
2057      console.info("rpc read booleanArray fail, errorCode " + error.code);
2058      console.info("rpc read booleanArray fail, errorMessage" + error.message);
2059  }
2060  ```
2061
2062### readBooleanArray
2063
2064readBooleanArray(): boolean[]
2065
2066Reads the Boolean array from this **MessageSequence** object.
2067
2068**System capability**: SystemCapability.Communication.IPC.Core
2069
2070**Return value**
2071
2072  | Type     | Description          |
2073  | --------- | -------------- |
2074  | boolean[] | Boolean array read.|
2075
2076**Error codes**
2077
2078For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2079
2080  | ID| Error Message|
2081  | ------- | -------- |
2082  | 1900010 | read data from message sequence failed |
2083
2084**Example**
2085
2086  ```ts
2087  let data = rpc.MessageSequence.create();
2088  try {
2089      data.writeBooleanArray([false, true, false]);
2090  } catch(error) {
2091      console.info("rpc write booleanArray fail, errorCode " + error.code);
2092      console.info("rpc write booleanArray fail, errorMessage" + error.message);
2093  }
2094  try {
2095      let array = data.readBooleanArray();
2096      console.log("RpcClient: readBooleanArray is " + array);
2097  } catch(error) {
2098      console.info("rpc read booleanArray fail, errorCode " + error.code);
2099      console.info("rpc read booleanArray fail, errorMessage" + error.message);
2100  }
2101  ```
2102
2103### writeCharArray
2104
2105writeCharArray(charArray: number[]): void
2106
2107Writes a character array to this **MessageSequence** object.
2108
2109**System capability**: SystemCapability.Communication.IPC.Core
2110
2111**Parameters**
2112
2113  | Name   | Type    | Mandatory| Description                  |
2114  | --------- | -------- | ---- | ---------------------- |
2115  | charArray | number[] | Yes  | Character array to write.|
2116
2117**Error codes**
2118
2119For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2120
2121  | ID| Error Message|
2122  | -------- | ------ |
2123  | 1900009 | write data to message sequence failed |
2124
2125**Example**
2126
2127  ```ts
2128  let data = rpc.MessageSequence.create();
2129  try {
2130      data.writeCharArray([97, 98, 88]);
2131  } catch(error) {
2132      console.info("rpc write charArray fail, errorCode " + error.code);
2133      console.info("rpc write charArray fail, errorMessage" + error.message);
2134  }
2135  ```
2136
2137### readCharArray
2138
2139readCharArray(dataIn: number[]): void
2140
2141Reads a character array from this **MessageSequence** object.
2142
2143**System capability**: SystemCapability.Communication.IPC.Core
2144
2145**Parameters**
2146
2147  | Name| Type    | Mandatory| Description                  |
2148  | ------ | -------- | ---- | ---------------------- |
2149  | dataIn | number[] | Yes  | Character array to read.|
2150
2151**Error codes**
2152
2153For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2154
2155  | ID| Error Message|
2156  | ------- | -------- |
2157  | 1900010 | read data from message sequence failed |
2158
2159**Example**
2160
2161  ```ts
2162  let data = rpc.MessageSequence.create();
2163  try {
2164      data.writeCharArray([97, 98, 88]);
2165  } catch(error) {
2166      console.info("rpc write charArray fail, errorCode " + error.code);
2167      console.info("rpc write charArray fail, errorMessage" + error.message);
2168  }
2169  let array = new Array(3);
2170  try {
2171      data.readCharArray(array);
2172  } catch(error) {
2173      console.info("rpc read charArray fail, errorCode " + error.code);
2174      console.info("rpc read charArray fail, errorMessage" + error.message);
2175  }
2176  ```
2177
2178### readCharArray
2179
2180readCharArray(): number[]
2181
2182Reads the character array from this **MessageSequence** object.
2183
2184**System capability**: SystemCapability.Communication.IPC.Core
2185
2186**Return value**
2187
2188  | Type    | Description              |
2189  | -------- | ------------------ |
2190  | number[] | Character array read.|
2191
2192**Error codes**
2193
2194For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2195
2196  | ID| Error Message|
2197  | ------- | -------- |
2198  | 1900010 | read data from message sequence failed |
2199
2200**Example**
2201
2202  ```ts
2203  let data = rpc.MessageSequence.create();
2204  try {
2205      data.writeCharArray([97, 98, 88]);
2206  } catch(error) {
2207      console.info("rpc write charArray fail, errorCode " + error.code);
2208      console.info("rpc write charArray fail, errorMessage" + error.message);
2209  }
2210  let array = new Array(3);
2211  try {
2212      let array = data.readCharArray();
2213      console.log("RpcClient: readCharArray is " + array);
2214  } catch(error) {
2215      console.info("rpc read charArray fail, errorCode " + error.code);
2216      console.info("rpc read charArray fail, errorMessage" + error.message);
2217  }
2218  ```
2219
2220### writeStringArray
2221
2222writeStringArray(stringArray: string[]): void
2223
2224Writes a string array to this **MessageSequence** object.
2225
2226**System capability**: SystemCapability.Communication.IPC.Core
2227
2228**Parameters**
2229
2230  | Name     | Type    | Mandatory| Description                                                   |
2231  | ----------- | -------- | ---- | ------------------------------------------------------- |
2232  | stringArray | string[] | Yes  | String array to write. The length of a single element in the array must be less than 40960 bytes.|
2233
2234**Error codes**
2235
2236For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2237
2238  | ID| Error Message|
2239  | ------- | -------- |
2240  | 1900009 | write data to message sequence failed |
2241
2242**Example**
2243
2244  ```ts
2245  let data = rpc.MessageSequence.create();
2246  try {
2247      data.writeStringArray(["abc", "def"]);
2248  } catch(error) {
2249      console.info("rpc write stringArray fail, errorCode " + error.code);
2250      console.info("rpc write stringArray fail, errorMessage" + error.message);
2251  }
2252  ```
2253
2254### readStringArray
2255
2256readStringArray(dataIn: string[]): void
2257
2258Reads a string array from this **MessageSequence** object.
2259
2260**System capability**: SystemCapability.Communication.IPC.Core
2261
2262**Parameters**
2263
2264  | Name| Type    | Mandatory| Description                |
2265  | ------ | -------- | ---- | -------------------- |
2266  | dataIn | string[] | Yes  | String array to read.|
2267
2268**Error codes**
2269
2270For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2271
2272  | ID| Error Message|
2273  | ------- | -------- |
2274  | 1900010 | read data from message sequence failed |
2275
2276**Example**
2277
2278  ```ts
2279  let data = rpc.MessageSequence.create();
2280  try {
2281      data.writeStringArray(["abc", "def"]);
2282  } catch(error) {
2283      console.info("rpc write stringArray fail, errorCode " + error.code);
2284      console.info("rpc write stringArray fail, errorMessage" + error.message);
2285  }
2286  let array = new Array(2);
2287  try {
2288      data.readStringArray(array);
2289  } catch(error) {
2290      console.info("rpc read stringArray fail, errorCode " + error.code);
2291      console.info("rpc read stringArray fail, errorMessage" + error.message);
2292  }
2293  ```
2294
2295### readStringArray
2296
2297readStringArray(): string[]
2298
2299Reads the string array from this **MessageSequence** object.
2300
2301**System capability**: SystemCapability.Communication.IPC.Core
2302
2303**Return value**
2304
2305  | Type    | Description            |
2306  | -------- | ---------------- |
2307  | string[] | String array read.|
2308
2309**Error codes**
2310
2311For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2312
2313  | ID| Error Message|
2314  | ------- | -------- |
2315  | 1900010 | read data from message sequence failed |
2316
2317**Example**
2318
2319  ```ts
2320  let data = rpc.MessageSequence.create();
2321  try {
2322      data.writeStringArray(["abc", "def"]);
2323  } catch(error) {
2324      console.info("rpc write stringArray fail, errorCode " + error.code);
2325      console.info("rpc write stringArray fail, errorMessage" + error.message);
2326  }
2327  try {
2328      let array = data.readStringArray();
2329      console.log("RpcClient: readStringArray is " + array);
2330  } catch(error) {
2331      console.info("rpc read stringArray fail, errorCode " + error.code);
2332      console.info("rpc read stringArray fail, errorMessage" + error.message);
2333  }
2334  ```
2335
2336### writeNoException
2337
2338writeNoException(): void
2339
2340Writes information to this **MessageSequence** object indicating that no exception occurred.
2341
2342**System capability**: SystemCapability.Communication.IPC.Core
2343
2344**Error codes**
2345
2346For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2347
2348  | ID| Error Message|
2349  | ------- | -------- |
2350  | 1900009 | write data to message sequence failed |
2351
2352**Example**
2353
2354  ```ts
2355  class TestRemoteObject extends rpc.RemoteObject {
2356      constructor(descriptor) {
2357          super(descriptor);
2358      }
2359
2360      onRemoteRequest(code, data, reply, option) {
2361          if (code === 1) {
2362              console.log("RpcServer: onRemoteRequest called");
2363              try {
2364                  reply.writeNoException();
2365              } catch(error) {
2366                  console.info("rpc write no exception fail, errorCode " + error.code);
2367                  console.info("rpc write no exception fail, errorMessage" + error.message);
2368              }
2369              return true;
2370          } else {
2371              console.log("RpcServer: unknown code: " + code);
2372              return false;
2373          }
2374      }
2375  }
2376  ```
2377
2378### readException
2379
2380readException(): void
2381
2382Reads the exception information from this **MessageSequence** object.
2383
2384**System capability**: SystemCapability.Communication.IPC.Core
2385
2386**Error codes**
2387
2388For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2389
2390  | ID| Error Message|
2391  | ------- | -------- |
2392  | 1900010 | read data from message sequence failed |
2393
2394**Example**
2395
2396  Obtain the service.
2397
2398  ```ts
2399  import FA from "@ohos.ability.featureAbility";
2400  let proxy;
2401  let connect = {
2402      onConnect: function(elementName, remoteProxy) {
2403          console.log("RpcClient: js onConnect called.");
2404          proxy = remoteProxy;
2405      },
2406      onDisconnect: function(elementName) {
2407          console.log("RpcClient: onDisconnect");
2408      },
2409      onFailed: function() {
2410          console.log("RpcClient: onFailed");
2411      }
2412  };
2413  let want = {
2414      "bundleName": "com.ohos.server",
2415      "abilityName": "com.ohos.server.MainAbility",
2416  };
2417  FA.connectAbility(want, connect);
2418  ```
2419
2420  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.
2421
2422  ```ts
2423  let option = new rpc.MessageOption();
2424  let data = rpc.MessageSequence.create();
2425  let reply = rpc.MessageSequence.create();
2426  data.writeInt(1);
2427  data.writeString("hello");
2428  proxy.sendMessageRequest(1, data, reply, option)
2429      .then(function(errCode) {
2430          if (errCode === 0) {
2431              console.log("sendMessageRequest got result");
2432              try {
2433                  reply.readException();
2434              } catch(error) {
2435                  console.info("rpc read exception fail, errorCode " + error.code);
2436                  console.info("rpc read no exception fail, errorMessage" + error.message);
2437              }
2438              let msg = reply.readString();
2439              console.log("RPCTest: reply msg: " + msg);
2440          } else {
2441              console.log("RPCTest: sendMessageRequest failed, errCode: " + errCode);
2442          }
2443      }).catch(function(e) {
2444          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
2445      }).finally (() => {
2446          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
2447          data.reclaim();
2448          reply.reclaim();
2449      });
2450  ```
2451
2452### writeParcelableArray
2453
2454writeParcelableArray(parcelableArray: Parcelable[]): void
2455
2456Writes a **Parcelable** array to this **MessageSequence** object.
2457
2458**System capability**: SystemCapability.Communication.IPC.Core
2459
2460**Parameters**
2461
2462  | Name         | Type        | Mandatory| Description                      |
2463  | --------------- | ------------ | ---- | -------------------------- |
2464  | parcelableArray | Parcelable[] | Yes  | **Parcelable** array to write.|
2465
2466**Error codes**
2467
2468For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2469
2470  | ID| Error Message|
2471  | ------- | -------- |
2472  | 1900009 | write data to message sequence failed |
2473
2474**Example**
2475
2476  ```ts
2477  class MyParcelable {
2478      num: number;
2479      str: string;
2480      constructor(num, str) {
2481          this.num = num;
2482          this.str = str;
2483      }
2484      marshalling(messageSequence) {
2485          messageSequence.writeInt(this.num);
2486          messageSequence.writeString(this.str);
2487          return true;
2488      }
2489      unmarshalling(messageSequence) {
2490          this.num = messageSequence.readInt();
2491          this.str = messageSequence.readString();
2492          return true;
2493      }
2494  }
2495  let parcelable = new MyParcelable(1, "aaa");
2496  let parcelable2 = new MyParcelable(2, "bbb");
2497  let parcelable3 = new MyParcelable(3, "ccc");
2498  let a = [parcelable, parcelable2, parcelable3];
2499  let data = rpc.MessageSequence.create();
2500  try {
2501      data.writeParcelableArray(a);
2502  } catch(error) {
2503      console.info("rpc write parcelable array fail, errorCode " + error.code);
2504      console.info("rpc write parcelable array fail, errorMessage" + error.message);
2505  }
2506  ```
2507
2508### readParcelableArray
2509
2510readParcelableArray(parcelableArray: Parcelable[]): void
2511
2512Reads a **Parcelable** array from this **MessageSequence** object.
2513
2514**System capability**: SystemCapability.Communication.IPC.Core
2515
2516**Parameters**
2517
2518  | Name         | Type        | Mandatory| Description                      |
2519  | --------------- | ------------ | ---- | -------------------------- |
2520  | parcelableArray | Parcelable[] | Yes  | **Parcelable** array to read.|
2521
2522**Error codes**
2523
2524For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2525
2526  | ID| Error Message|
2527  | ------- | -------- |
2528  | 1900010 | read data from message sequence failed |
2529  | 1900012 | call js callback function failed |
2530
2531**Example**
2532
2533  ```ts
2534  class MyParcelable {
2535      num: number;
2536      str: string;
2537      constructor(num, str) {
2538          this.num = num;
2539          this.str = str;
2540      }
2541      marshalling(messageSequence) {
2542          messageSequence.writeInt(this.num);
2543          messageSequence.writeString(this.str);
2544          return true;
2545      }
2546      unmarshalling(messageSequence) {
2547          this.num = messageSequence.readInt();
2548          this.str = messageSequence.readString();
2549          return true;
2550      }
2551  }
2552  let parcelable = new MyParcelable(1, "aaa");
2553  let parcelable2 = new MyParcelable(2, "bbb");
2554  let parcelable3 = new MyParcelable(3, "ccc");
2555  let a = [parcelable, parcelable2, parcelable3];
2556  let data = rpc.MessageSequence.create();
2557  let result = data.writeParcelableArray(a);
2558  console.log("RpcClient: writeParcelableArray is " + result);
2559  let b = [new MyParcelable(0, ""), new MyParcelable(0, ""), new MyParcelable(0, "")];
2560  try {
2561      data.readParcelableArray(b);
2562  } catch(error) {
2563      console.info("rpc read parcelable array fail, errorCode " + error.code);
2564      console.info("rpc read parcelable array fail, errorMessage" + error.message);
2565  }
2566  data.readParcelableArray(b);
2567  ```
2568
2569### writeRemoteObjectArray
2570
2571writeRemoteObjectArray(objectArray: IRemoteObject[]): void
2572
2573Writes an array of **IRemoteObject** objects to this **MessageSequence** object.
2574
2575**System capability**: SystemCapability.Communication.IPC.Core
2576
2577**Parameters**
2578
2579  | Name     | Type           | Mandatory| Description                                          |
2580  | ----------- | --------------- | ---- | ---------------------------------------------- |
2581  | objectArray | IRemoteObject[] | Yes  | Array of **IRemoteObject** objects to write.|
2582
2583**Error codes**
2584
2585For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2586
2587  | ID| Error Message|
2588  | ------- | ------- |
2589  | 1900009 | write data to message sequence failed |
2590
2591**Example**
2592
2593  ```ts
2594  class TestRemoteObject extends rpc.RemoteObject {
2595      constructor(descriptor) {
2596          super(descriptor);
2597          this.modifyLocalInterface(this, descriptor);
2598      }
2599
2600      asObject(): rpc.IRemoteObject {
2601          return this;
2602      }
2603  }
2604  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
2605  let data = rpc.MessageSequence.create();
2606  let result = data.writeRemoteObjectArray(a);
2607  try {
2608      data.writeRemoteObjectArray(a);
2609  } catch(error) {
2610      console.info("rpc write remote object array fail, errorCode " + error.code);
2611      console.info("rpc write remote object array fail, errorMessage" + error.message);
2612  }
2613  console.log("RpcClient: writeRemoteObjectArray is " + result);
2614  ```
2615
2616### readRemoteObjectArray
2617
2618readRemoteObjectArray(objects: IRemoteObject[]): void
2619
2620Reads an array of **IRemoteObject** objects from this **MessageSequence** object.
2621
2622**System capability**: SystemCapability.Communication.IPC.Core
2623
2624**Parameters**
2625
2626  | Name | Type           | Mandatory| Description                                          |
2627  | ------- | --------------- | ---- | ---------------------------------------------- |
2628  | objects | IRemoteObject[] | Yes  | **IRemoteObject** array to read.|
2629
2630**Error codes**
2631
2632For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2633
2634  | ID| Error Message|
2635  | ------- | -------- |
2636  | 1900010 | read data from message sequence failed |
2637
2638**Example**
2639
2640  ```ts
2641  class MyDeathRecipient {
2642      onRemoteDied() {
2643          console.log("server died");
2644      }
2645  }
2646  class TestRemoteObject extends rpc.RemoteObject {
2647      constructor(descriptor) {
2648          super(descriptor);
2649          this.modifyLocalInterface(this, descriptor);
2650      }
2651
2652      asObject(): rpc.IRemoteObject {
2653          return this;
2654      }
2655  }
2656  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
2657  let data = rpc.MessageSequence.create();
2658  data.writeRemoteObjectArray(a);
2659  let b = new Array(3);
2660  try {
2661      data.readRemoteObjectArray(b);
2662  } catch(error) {
2663      console.info("rpc read remote object array fail, errorCode " + error.code);
2664      console.info("rpc read remote object array fail, errorMessage" + error.message);
2665  }
2666  data.readRemoteObjectArray(b);
2667  ```
2668
2669### readRemoteObjectArray
2670
2671readRemoteObjectArray(): IRemoteObject[]
2672
2673Reads the **IRemoteObject** object array from this **MessageSequence** object.
2674
2675**System capability**: SystemCapability.Communication.IPC.Core
2676
2677**Return value**
2678
2679  | Type           | Description                       |
2680  | --------------- | --------------------------- |
2681  | IRemoteObject[] | **IRemoteObject** object array read.|
2682
2683**Error codes**
2684
2685For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2686
2687  | ID| Error Message|
2688  | ------- | -------- |
2689  | 1900010 | read data from message sequence failed |
2690
2691**Example**
2692
2693  ```ts
2694  class TestRemoteObject extends rpc.RemoteObject {
2695      constructor(descriptor) {
2696          super(descriptor);
2697          this.modifyLocalInterface(this, descriptor);
2698      }
2699
2700      asObject(): rpc.IRemoteObject {
2701          return this;
2702      }
2703  }
2704  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
2705  let data = rpc.MessageSequence.create();
2706  data.writeRemoteObjectArray(a);
2707  try {
2708      let b = data.readRemoteObjectArray();
2709      console.log("RpcClient: readRemoteObjectArray is " + b);
2710  } catch(error) {
2711      console.info("rpc read remote object array fail, errorCode " + error.code);
2712      console.info("rpc read remote object array fail, errorMessage" + error.message);
2713  }
2714  ```
2715
2716
2717### closeFileDescriptor<sup>9+</sup>
2718
2719static closeFileDescriptor(fd: number): void
2720
2721Closes a file descriptor. This API is a static method.
2722
2723**System capability**: SystemCapability.Communication.IPC.Core
2724
2725**Parameters**
2726
2727  | Name| Type  | Mandatory| Description                |
2728  | ------ | ------ | ---- | -------------------- |
2729  | fd     | number | Yes  | File descriptor to close.|
2730
2731**Example**
2732
2733  ```ts
2734  import fileio from '@ohos.fileio';
2735  let filePath = "path/to/file";
2736  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
2737  try {
2738      rpc.MessageSequence.closeFileDescriptor(fd);
2739  } catch(error) {
2740      console.info("rpc close file descriptor fail, errorCode " + error.code);
2741      console.info("rpc close file descriptor fail, errorMessage" + error.message);
2742  }
2743  ```
2744
2745### dupFileDescriptor
2746
2747static dupFileDescriptor(fd: number) :number
2748
2749Duplicates a file descriptor. This API is a static method.
2750
2751**System capability**: SystemCapability.Communication.IPC.Core
2752
2753**Parameters**
2754
2755  | Name| Type  | Mandatory| Description                    |
2756  | ------ | ------ | ---- | ------------------------ |
2757  | fd     | number | Yes  | File descriptor to duplicate.|
2758
2759**Return value**
2760
2761  | Type  | Description                |
2762  | ------ | -------------------- |
2763  | number | New file descriptor.|
2764
2765**Error codes**
2766
2767For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2768
2769  | ID| Error Message|
2770  | ------- | ------- |
2771  | 1900013 | call os dup function failed |
2772
2773**Example**
2774
2775  ```ts
2776  import fileio from '@ohos.fileio';
2777  let filePath = "path/to/file";
2778  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
2779  try {
2780      let newFd = rpc.MessageSequence.dupFileDescriptor(fd);
2781  } catch(error) {
2782      console.info("rpc dup file descriptor fail, errorCode " + error.code);
2783      console.info("rpc dup file descriptor fail, errorMessage" + error.message);
2784  }
2785  ```
2786
2787### containFileDescriptors
2788
2789containFileDescriptors(): boolean
2790
2791Checks whether this **MessageSequence** object contains file descriptors.
2792
2793**System capability**: SystemCapability.Communication.IPC.Core
2794
2795**Return value**
2796
2797  | Type   | Description                                                                |
2798  | ------- | -------------------------------------------------------------------- |
2799  | boolean | Returns **true** if the **MessageSequence** object contains file descriptors; returns **false** otherwise.|
2800
2801**Example**
2802
2803
2804  ```ts
2805  import fileio from '@ohos.fileio';
2806  let sequence = new rpc.MessageSequence();
2807  let filePath = "path/to/file";
2808  let r1 = sequence.containFileDescriptors();
2809  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
2810  try {
2811      sequence.writeFileDescriptor(fd);
2812  } catch(error) {
2813      console.info("rpc write file descriptor fail, errorCode " + error.code);
2814      console.info("rpc write file descriptor fail, errorMessage" + error.message);
2815  }
2816  try {
2817      let containFD = sequence.containFileDescriptors();
2818      console.log("RpcTest: sequence after write fd containFd result is : " + containFD);
2819  } catch(error) {
2820      console.info("rpc contain file descriptor fail, errorCode " + error.code);
2821      console.info("rpc contain file descriptor fail, errorMessage" + error.message);
2822  }
2823  ```
2824
2825### writeFileDescriptor
2826
2827writeFileDescriptor(fd: number): void
2828
2829Writes a file descriptor to this **MessageSequence** object.
2830
2831**System capability**: SystemCapability.Communication.IPC.Core
2832
2833**Parameters**
2834
2835  | Name| Type  | Mandatory| Description        |
2836  | ------ | ------ | ---- | ------------ |
2837  | fd     | number | Yes  | File descriptor to write.|
2838
2839**Error codes**
2840
2841For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2842
2843  | ID| Error Message|
2844  | -------- | ------ |
2845  | 1900009 | write data to message sequence failed |
2846
2847**Example**
2848
2849  ```ts
2850  import fileio from '@ohos.fileio';
2851  let sequence = new rpc.MessageSequence();
2852  let filePath = "path/to/file";
2853  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
2854  try {
2855      sequence.writeFileDescriptor(fd);
2856  } catch(error) {
2857      console.info("rpc write file descriptor fail, errorCode " + error.code);
2858      console.info("rpc write file descriptor fail, errorMessage" + error.message);
2859  }
2860  ```
2861
2862### readFileDescriptor
2863
2864readFileDescriptor(): number
2865
2866Reads the file descriptor from this **MessageSequence** object.
2867
2868**System capability**: SystemCapability.Communication.IPC.Core
2869
2870**Return value**
2871
2872  | Type  | Description            |
2873  | ------ | ---------------- |
2874  | number | File descriptor read.|
2875
2876**Error codes**
2877
2878For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2879
2880  | ID| Error Message|
2881  | ------- | -------- |
2882  | 1900010 | read data from message sequence failed |
2883
2884**Example**
2885
2886  ```ts
2887  import fileio from '@ohos.fileio';
2888  let sequence = new rpc.MessageSequence();
2889  let filePath = "path/to/file";
2890  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
2891  try {
2892      sequence.writeFileDescriptor(fd);
2893  } catch(error) {
2894      console.info("rpc write file descriptor fail, errorCode " + error.code);
2895      console.info("rpc write file descriptor fail, errorMessage" + error.message);
2896  }
2897  try {
2898      let readFD = sequence.readFileDescriptor();
2899  } catch(error) {
2900      console.info("rpc read file descriptor fail, errorCode " + error.code);
2901      console.info("rpc read file descriptor fail, errorMessage" + error.message);
2902  }
2903  ```
2904
2905### writeAshmem
2906
2907writeAshmem(ashmem: Ashmem): void
2908
2909Writes an anonymous shared object to this **MessageSequence** object.
2910
2911**System capability**: SystemCapability.Communication.IPC.Core
2912
2913**Parameters**
2914
2915  | Name| Type  | Mandatory| Description                                 |
2916  | ------ | ------ | ---- | ------------------------------------- |
2917  | ashmem | Ashmem | Yes  | Anonymous shared object to write.|
2918
2919**Error codes**
2920
2921For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2922
2923  | ID| Error Message|
2924  | ------- | ------- |
2925  | 1900003 | write to ashmem failed |
2926
2927**Example**
2928
2929  ```ts
2930  let sequence = new rpc.MessageSequence();
2931  let ashmem;
2932  try {
2933      ashmem = rpc.Ashmem.create("ashmem", 1024);
2934  } catch(error) {
2935      console.info("rpc create ashmem fail, errorCode " + error.code);
2936      console.info("rpc creat ashmem fail, errorMessage" + error.message);
2937  }
2938  try {
2939      sequence.writeAshmem(ashmem);
2940  } catch(error) {
2941      console.info("rpc write ashmem fail, errorCode " + error.code);
2942      console.info("rpc write ashmem fail, errorMessage" + error.message);
2943  }
2944  ```
2945
2946
2947### readAshmem
2948
2949readAshmem(): Ashmem
2950
2951Reads the anonymous shared object from this **MessageSequence** object.
2952
2953**System capability**: SystemCapability.Communication.IPC.Core
2954
2955**Return value**
2956
2957  | Type  | Description              |
2958  | ------ | ------------------ |
2959  | Ashmem | Anonymous share object read.|
2960
2961**Error codes**
2962
2963For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
2964
2965  | ID| Error Message|
2966  | ------- | -------- |
2967  | 1900004 | read from ashmem failed |
2968
2969**Example**
2970
2971  ```ts
2972  let sequence = new rpc.MessageSequence();
2973  let ashmem;
2974  try {
2975      ashmem = rpc.Ashmem.create("ashmem", 1024);
2976  } catch(error) {
2977      console.info("rpc create ashmem fail, errorCode " + error.code);
2978      console.info("rpc creat ashmem fail, errorMessage" + error.message);
2979  }
2980  try {
2981      sequence.writeAshmem(ashmem);
2982  } catch(error) {
2983      console.info("rpc write ashmem fail, errorCode " + error.code);
2984      console.info("rpc write ashmem fail, errorMessage" + error.message);
2985  }
2986  try {
2987      let readAshmem = sequence.readAshmem();
2988      console.log("RpcTest: read ashmem to result is : " + readAshmem);
2989  } catch(error) {
2990      console.info("rpc read ashmem fail, errorCode " + error.code);
2991      console.info("rpc read ashmem fail, errorMessage" + error.message);
2992  }
2993  ```
2994
2995### getRawDataCapacity
2996
2997getRawDataCapacity(): number
2998
2999Obtains the maximum amount of raw data that can be held by this **MessageSequence** object.
3000
3001**System capability**: SystemCapability.Communication.IPC.Core
3002
3003**Return value**
3004
3005  | Type  | Description                                                        |
3006  | ------ | ------------------------------------------------------------ |
3007  | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageSequence** object.|
3008
3009**Example**
3010
3011  ```ts
3012  let sequence = new rpc.MessageSequence();
3013  let result = sequence.getRawDataCapacity();
3014  console.log("RpcTest: sequence get RawDataCapacity result is : " + result);
3015  ```
3016
3017### writeRawData
3018
3019writeRawData(rawData: number[], size: number): void
3020
3021Writes raw data to this **MessageSequence** object.
3022
3023**System capability**: SystemCapability.Communication.IPC.Core
3024
3025**Parameters**
3026
3027  | Name | Type    | Mandatory| Description                              |
3028  | ------- | -------- | ---- | ---------------------------------- |
3029  | rawData | number[] | Yes  | Raw data to write.                |
3030  | size    | number   | Yes  | Size of the raw data, in bytes.|
3031
3032**Error codes**
3033
3034For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
3035
3036  | ID| Error Message|
3037  | ------- | ------ |
3038  | 1900009 | write data to message sequence failed |
3039
3040**Example**
3041
3042  ```ts
3043  let sequence = new rpc.MessageSequence();
3044  let arr = [1, 2, 3, 4, 5];
3045  try {
3046      sequence.writeRawData(arr, arr.length);
3047  } catch(error) {
3048      console.info("rpc write rawdata fail, errorCode " + error.code);
3049      console.info("rpc write rawdata fail, errorMessage" + error.message);
3050  }
3051  ```
3052
3053### readRawData
3054
3055readRawData(size: number): number[]
3056
3057Reads raw data from this **MessageSequence** object.
3058
3059**System capability**: SystemCapability.Communication.IPC.Core
3060
3061**Parameters**
3062
3063  | Name| Type  | Mandatory| Description                    |
3064  | ------ | ------ | ---- | ------------------------ |
3065  | size   | number | Yes  | Size of the raw data to read.|
3066
3067**Return value**
3068
3069  | Type    | Description                          |
3070  | -------- | ------------------------------ |
3071  | number[] | Raw data read, in bytes.|
3072
3073**Error codes**
3074
3075For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
3076
3077  | ID| Error Message|
3078  | ------- | -------- |
3079  | 1900010 | read data from message sequence failed |
3080
3081**Example**
3082
3083  ```ts
3084  let sequence = new rpc.MessageSequence();
3085  let arr = [1, 2, 3, 4, 5];
3086  try {
3087      sequence.writeRawData(arr, arr.length);
3088  } catch(error) {
3089      console.info("rpc write rawdata fail, errorCode " + error.code);
3090      console.info("rpc write rawdata fail, errorMessage" + error.message);
3091  }
3092  try {
3093      let result = sequence.readRawData(5);
3094      console.log("RpcTest: sequence read raw data result is : " + result);
3095  } catch(error) {
3096      console.info("rpc read rawdata fail, errorCode " + error.code);
3097      console.info("rpc read rawdata fail, errorMessage" + error.message);
3098  }
3099  ```
3100
3101## MessageParcel<sup>(deprecated)</sup>
3102
3103>This class is no longer maintained since API version 9. You are advised to use [MessageSequence](#messagesequence9).
3104
3105Provides APIs for reading and writing data in specific format.
3106
3107During 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.
3108
3109### create
3110
3111static create(): MessageParcel
3112
3113Creates a **MessageParcel** object. This method is a static method.
3114
3115**System capability**: SystemCapability.Communication.IPC.Core
3116
3117**Return value**
3118
3119  | Type         | Description                         |
3120  | ------------- | ----------------------------- |
3121  | MessageParcel | **MessageParcel** object created.|
3122
3123**Example**
3124
3125  ```ts
3126  let data = rpc.MessageParcel.create();
3127  console.log("RpcClient: data is " + data);
3128  ```
3129
3130### reclaim
3131
3132reclaim(): void
3133
3134Reclaims the **MessageParcel** object that is no longer used.
3135
3136**System capability**: SystemCapability.Communication.IPC.Core
3137
3138**Example**
3139
3140  ```ts
3141  let reply = rpc.MessageParcel.create();
3142  reply.reclaim();
3143  ```
3144
3145### writeRemoteObject
3146
3147writeRemoteObject(object: [IRemoteObject](#iremoteobject)): boolean
3148
3149Serializes a remote object and writes it to this **MessageParcel** object.
3150
3151**System capability**: SystemCapability.Communication.IPC.Core
3152
3153**Parameters**
3154
3155  | Name| Type                           | Mandatory| Description                                   |
3156  | ------ | ------------------------------- | ---- | --------------------------------------- |
3157  | object | [IRemoteObject](#iremoteobject) | Yes  | Remote object to serialize and write to the **MessageParcel** object.|
3158
3159**Return value**
3160
3161  | Type   | Description                                     |
3162  | ------- | ----------------------------------------- |
3163  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3164
3165**Example**
3166
3167  ```ts
3168  class MyDeathRecipient {
3169      onRemoteDied() {
3170          console.log("server died");
3171      }
3172  }
3173  class TestRemoteObject extends rpc.RemoteObject {
3174      constructor(descriptor) {
3175          super(descriptor);
3176      }
3177      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
3178          return true;
3179      }
3180      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
3181          return true;
3182      }
3183      isObjectDead(): boolean {
3184          return false;
3185      }
3186  }
3187  let data = rpc.MessageParcel.create();
3188  let testRemoteObject = new TestRemoteObject("testObject");
3189  data.writeRemoteObject(testRemoteObject);
3190  ```
3191
3192### readRemoteObject
3193
3194readRemoteObject(): IRemoteObject
3195
3196Reads 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.
3197
3198**System capability**: SystemCapability.Communication.IPC.Core
3199
3200**Return value**
3201
3202  | Type                           | Description              |
3203  | ------------------------------- | ------------------ |
3204  | [IRemoteObject](#iremoteobject) | Remote object obtained.|
3205
3206**Example**
3207
3208  ```ts
3209  class MyDeathRecipient {
3210      onRemoteDied() {
3211          console.log("server died");
3212      }
3213  }
3214  class TestRemoteObject extends rpc.RemoteObject {
3215      constructor(descriptor) {
3216          super(descriptor);
3217      }
3218      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
3219          return true;
3220      }
3221      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
3222          return true;
3223      }
3224      isObjectDead(): boolean {
3225          return false;
3226      }
3227  }
3228  let data = rpc.MessageParcel.create();
3229  let testRemoteObject = new TestRemoteObject("testObject");
3230  data.writeRemoteObject(testRemoteObject);
3231  let proxy = data.readRemoteObject();
3232  ```
3233
3234### writeInterfaceToken
3235
3236writeInterfaceToken(token: string): boolean
3237
3238Writes an interface token to this **MessageParcel** object. The remote object can use this interface token to verify the communication.
3239
3240**System capability**: SystemCapability.Communication.IPC.Core
3241
3242**Parameters**
3243
3244  | Name| Type  | Mandatory| Description              |
3245  | ------ | ------ | ---- | ------------------ |
3246  | token  | string | Yes  | Interface token to write.|
3247
3248**Return value**
3249
3250  | Type   | Description                                     |
3251  | ------- | ----------------------------------------- |
3252  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3253
3254**Example**
3255
3256  ```ts
3257  let data = rpc.MessageParcel.create();
3258  let result = data.writeInterfaceToken("aaa");
3259  console.log("RpcServer: writeInterfaceToken is " + result);
3260  ```
3261
3262
3263### readInterfaceToken
3264
3265readInterfaceToken(): string
3266
3267Reads 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.
3268
3269**System capability**: SystemCapability.Communication.IPC.Core
3270
3271**Return value**
3272
3273  | Type  | Description                    |
3274  | ------ | ------------------------ |
3275  | string | Interface token obtained.|
3276
3277**Example**
3278
3279  ```ts
3280  class Stub extends rpc.RemoteObject {
3281      onRemoteMessageRequest(code, data, reply, option) {
3282          let interfaceToken = data.readInterfaceToken();
3283          console.log("RpcServer: interfaceToken is " + interfaceToken);
3284          return true;
3285      }
3286  }
3287  ```
3288
3289### getSize
3290
3291getSize(): number
3292
3293Obtains the data size of this **MessageParcel** object.
3294
3295**System capability**: SystemCapability.Communication.IPC.Core
3296
3297**Return value**
3298
3299  | Type  | Description                                         |
3300  | ------ | --------------------------------------------- |
3301  | number | Size of the **MessageParcel** object obtained, in bytes.|
3302
3303**Example**
3304
3305  ```ts
3306  let data = rpc.MessageParcel.create();
3307  let size = data.getSize();
3308  console.log("RpcClient: size is " + size);
3309  ```
3310
3311### getCapacity
3312
3313getCapacity(): number
3314
3315Obtains the capacity of this **MessageParcel** object.
3316
3317**System capability**: SystemCapability.Communication.IPC.Core
3318
3319**Return value**
3320
3321  | Type  | Description                                         |
3322  | ------ | --------------------------------------------- |
3323  | number | **MessageParcel** capacity obtained, in bytes.|
3324
3325**Example**
3326
3327  ```ts
3328  let data = rpc.MessageParcel.create();
3329  let result = data.getCapacity();
3330  console.log("RpcClient: capacity is " + result);
3331  ```
3332
3333### setSize
3334
3335setSize(size: number): boolean
3336
3337Sets the size of data contained in this **MessageParcel** object.
3338
3339**System capability**: SystemCapability.Communication.IPC.Core
3340
3341**Parameters**
3342
3343  | Name| Type  | Mandatory| Description                                       |
3344  | ------ | ------ | ---- | ------------------------------------------- |
3345  | size   | number | Yes  | Data size to set, in bytes.|
3346
3347**Return value**
3348
3349  | Type   | Description                             |
3350  | ------- | --------------------------------- |
3351  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3352
3353**Example**
3354
3355  ```ts
3356  let data = rpc.MessageParcel.create();
3357  let setSize = data.setSize(16);
3358  console.log("RpcClient: setSize is " + setSize);
3359  ```
3360
3361### setCapacity
3362
3363setCapacity(size: number): boolean
3364
3365Sets the storage capacity of this **MessageParcel** object.
3366
3367**System capability**: SystemCapability.Communication.IPC.Core
3368
3369**Parameters**
3370
3371  | Name| Type  | Mandatory| Description                                       |
3372  | ------ | ------ | ---- | ------------------------------------------- |
3373  | size   | number | Yes  | Storage capacity to set, in bytes.|
3374
3375**Return value**
3376
3377  | Type   | Description                             |
3378  | ------- | --------------------------------- |
3379  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3380
3381**Example**
3382
3383  ```ts
3384  let data = rpc.MessageParcel.create();
3385  let result = data.setCapacity(100);
3386  console.log("RpcClient: setCapacity is " + result);
3387  ```
3388
3389### getWritableBytes
3390
3391getWritableBytes(): number
3392
3393Obtains the writable capacity of this **MessageParcel** object.
3394
3395**System capability**: SystemCapability.Communication.IPC.Core
3396
3397**Return value**
3398
3399  | Type  | Description                                               |
3400  | ------ | --------------------------------------------------- |
3401  | number | **MessageParcel** writable capacity obtained, in bytes.|
3402
3403**Example**
3404
3405  ```ts
3406  class Stub extends rpc.RemoteObject {
3407      onRemoteMessageRequest(code, data, reply, option) {
3408          let getWritableBytes = data.getWritableBytes();
3409          console.log("RpcServer: getWritableBytes is " + getWritableBytes);
3410          return true;
3411      }
3412  }
3413  ```
3414
3415### getReadableBytes
3416
3417getReadableBytes(): number
3418
3419Obtains the readable capacity of this **MessageParcel** object.
3420
3421**System capability**: SystemCapability.Communication.IPC.Core
3422
3423**Return value**
3424
3425  | Type  | Description                                               |
3426  | ------ | --------------------------------------------------- |
3427  | number | **MessageParcel** object readable capacity, in bytes.|
3428
3429**Example**
3430
3431  ```ts
3432  class Stub extends rpc.RemoteObject {
3433      onRemoteRequest(code, data, reply, option) {
3434          let result = data.getReadableBytes();
3435          console.log("RpcServer: getReadableBytes is " + result);
3436          return true;
3437      }
3438  }
3439  ```
3440
3441### getReadPosition
3442
3443getReadPosition(): number
3444
3445Obtains the read position of this **MessageParcel** object.
3446
3447**System capability**: SystemCapability.Communication.IPC.Core
3448
3449**Return value**
3450
3451  | Type  | Description                                   |
3452  | ------ | --------------------------------------- |
3453  | number | Current read position of the **MessageParcel** object.|
3454
3455**Example**
3456
3457  ```ts
3458  let data = rpc.MessageParcel.create();
3459  let readPos = data.getReadPosition();
3460  console.log("RpcClient: readPos is " + readPos);
3461  ```
3462
3463### getWritePosition
3464
3465getWritePosition(): number
3466
3467Obtains the write position of this **MessageParcel** object.
3468
3469**System capability**: SystemCapability.Communication.IPC.Core
3470
3471**Return value**
3472
3473  | Type  | Description                                   |
3474  | ------ | --------------------------------------- |
3475  | number | Current write position of the **MessageParcel** object.|
3476
3477**Example**
3478
3479  ```ts
3480  let data = rpc.MessageParcel.create();
3481  data.writeInt(10);
3482  let bwPos = data.getWritePosition();
3483  console.log("RpcClient: bwPos is " + bwPos);
3484  ```
3485
3486### rewindRead
3487
3488rewindRead(pos: number): boolean
3489
3490Moves the read pointer to the specified position.
3491
3492**System capability**: SystemCapability.Communication.IPC.Core
3493
3494**Parameters**
3495
3496  | Name| Type  | Mandatory| Description                    |
3497  | ------ | ------ | ---- | ------------------------ |
3498  | pos    | number | Yes  | Position from which data is to read.|
3499
3500**Return value**
3501
3502  | Type   | Description                                             |
3503  | ------- | ------------------------------------------------- |
3504  | boolean | Returns **true** if the read position changes; returns **false** otherwise.|
3505
3506**Example**
3507
3508  ```ts
3509  let data = rpc.MessageParcel.create();
3510  data.writeInt(12);
3511  data.writeString("parcel");
3512  let number = data.readInt();
3513  console.log("RpcClient: number is " + number);
3514  data.rewindRead(0);
3515  let number2 = data.readInt();
3516  console.log("RpcClient: rewindRead is " + number2);
3517  ```
3518
3519### rewindWrite
3520
3521rewindWrite(pos: number): boolean
3522
3523Moves the write pointer to the specified position.
3524
3525**System capability**: SystemCapability.Communication.IPC.Core
3526
3527**Parameters**
3528
3529  | Name| Type  | Mandatory| Description                    |
3530  | ------ | ------ | ---- | ------------------------ |
3531  | pos    | number | Yes  | Position from which data is to write.|
3532
3533**Return value**
3534
3535  | Type   | Description                                         |
3536  | ------- | --------------------------------------------- |
3537  | boolean | Returns **true** if the write position changes; returns **false** otherwise.|
3538
3539**Example**
3540
3541  ```ts
3542  let data = rpc.MessageParcel.create();
3543  data.writeInt(4);
3544  data.rewindWrite(0);
3545  data.writeInt(5);
3546  let number = data.readInt();
3547  console.log("RpcClient: rewindWrite is: " + number);
3548  ```
3549
3550### writeByte
3551
3552writeByte(val: number): boolean
3553
3554Writes a Byte value to this **MessageParcel** object.
3555
3556**System capability**: SystemCapability.Communication.IPC.Core
3557
3558**Parameters**
3559
3560  | Name| Type  | Mandatory| Description            |
3561  | ------ | ------ | ---- | ---------------- |
3562  | val    | number | Yes  | Byte value to write.|
3563
3564**Return value**
3565
3566  | Type   | Description                         |
3567  | ------- | ----------------------------- |
3568  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3569
3570**Example**
3571
3572  ```ts
3573  let data = rpc.MessageParcel.create();
3574  let result = data.writeByte(2);
3575  console.log("RpcClient: writeByte is: " + result);
3576  ```
3577
3578### readByte
3579
3580readByte(): number
3581
3582Reads the Byte value from this **MessageParcel** object.
3583
3584**System capability**: SystemCapability.Communication.IPC.Core
3585
3586**Return value**
3587
3588  | Type  | Description        |
3589  | ------ | ------------ |
3590  | number | Byte value read.|
3591
3592**Example**
3593
3594  ```ts
3595  let data = rpc.MessageParcel.create();
3596  let result = data.writeByte(2);
3597  console.log("RpcClient: writeByte is: " + result);
3598  let ret = data.readByte();
3599  console.log("RpcClient: readByte is: " + ret);
3600  ```
3601
3602### writeShort
3603
3604writeShort(val: number): boolean
3605
3606Writes a Short int value to this **MessageParcel** object.
3607
3608**System capability**: SystemCapability.Communication.IPC.Core
3609
3610**Parameters**
3611
3612  | Name| Type  | Mandatory| Description              |
3613  | ------ | ------ | ---- | ------------------ |
3614  | val    | number | Yes  | Short int value to write.|
3615
3616**Return value**
3617
3618  | Type   | Description                         |
3619  | ------- | ----------------------------- |
3620  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
3621
3622**Example**
3623
3624  ```ts
3625  let data = rpc.MessageParcel.create();
3626  let result = data.writeShort(8);
3627  console.log("RpcClient: writeShort is: " + result);
3628  ```
3629
3630### readShort
3631
3632readShort(): number
3633
3634Reads the Short int value from this **MessageParcel** object.
3635
3636**System capability**: SystemCapability.Communication.IPC.Core
3637
3638**Return value**
3639
3640  | Type  | Description          |
3641  | ------ | -------------- |
3642  | number | Short int value read.|
3643
3644**Example**
3645
3646  ```ts
3647  let data = rpc.MessageParcel.create();
3648  let result = data.writeShort(8);
3649  console.log("RpcClient: writeShort is: " + result);
3650  let ret = data.readShort();
3651  console.log("RpcClient: readShort is: " + ret);
3652  ```
3653
3654### writeInt
3655
3656writeInt(val: number): boolean
3657
3658Writes an Int value to this **MessageParcel** object.
3659
3660**System capability**: SystemCapability.Communication.IPC.Core
3661
3662**Parameters**
3663
3664  | Name| Type  | Mandatory| Description            |
3665  | ------ | ------ | ---- | ---------------- |
3666  | val    | number | Yes  | Int value to write.|
3667
3668**Return value**
3669
3670  | Type   | Description                         |
3671  | ------- | ----------------------------- |
3672  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3673
3674**Example**
3675
3676  ```ts
3677  let data = rpc.MessageParcel.create();
3678  let result = data.writeInt(10);
3679  console.log("RpcClient: writeInt is " + result);
3680  ```
3681
3682### readInt
3683
3684readInt(): number
3685
3686Reads the Int value from this **MessageParcel** object.
3687
3688**System capability**: SystemCapability.Communication.IPC.Core
3689
3690**Return value**
3691
3692  | Type  | Description        |
3693  | ------ | ------------ |
3694  | number | Int value read.|
3695
3696**Example**
3697
3698  ```ts
3699  let data = rpc.MessageParcel.create();
3700  let result = data.writeInt(10);
3701  console.log("RpcClient: writeInt is " + result);
3702  let ret = data.readInt();
3703  console.log("RpcClient: readInt is " + ret);
3704  ```
3705
3706### writeLong
3707
3708writeLong(val: number): boolean
3709
3710Writes a Long int value to this **MessageParcel** object.
3711
3712**System capability**: SystemCapability.Communication.IPC.Core
3713
3714**Parameters**
3715
3716  | Name| Type  | Mandatory| Description            |
3717  | ------ | ------ | ---- | ---------------- |
3718  | val    | number | Yes  | Long int value to write.|
3719
3720**Return value**
3721
3722  | Type   | Description                             |
3723  | ------- | --------------------------------- |
3724  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
3725
3726**Example**
3727
3728  ```ts
3729  let data = rpc.MessageParcel.create();
3730  let result = data.writeLong(10000);
3731  console.log("RpcClient: writeLong is " + result);
3732  ```
3733
3734### readLong
3735
3736readLong(): number
3737
3738Reads the Long int value from this **MessageParcel** object.
3739
3740**System capability**: SystemCapability.Communication.IPC.Core
3741
3742**Return value**
3743
3744  | Type  | Description          |
3745  | ------ | -------------- |
3746  | number | Long int value read.|
3747
3748**Example**
3749
3750  ```ts
3751  let data = rpc.MessageParcel.create();
3752  let result = data.writeLong(10000);
3753  console.log("RpcClient: writeLong is " + result);
3754  let ret = data.readLong();
3755  console.log("RpcClient: readLong is " + ret);
3756  ```
3757
3758### writeFloat
3759
3760writeFloat(val: number): boolean
3761
3762Writes a Float value to this **MessageParcel** object.
3763
3764**System capability**: SystemCapability.Communication.IPC.Core
3765
3766**Parameters**
3767
3768  | Name| Type  | Mandatory| Description            |
3769  | ------ | ------ | ---- | ---------------- |
3770  | val    | number | Yes  | Float value to write.|
3771
3772**Return value**
3773
3774  | Type   | Description                             |
3775  | ------- | --------------------------------- |
3776  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
3777
3778**Example**
3779
3780  ```ts
3781  let data = rpc.MessageParcel.create();
3782  let result = data.writeFloat(1.2);
3783  console.log("RpcClient: writeFloat is " + result);
3784  ```
3785
3786### readFloat
3787
3788readFloat(): number
3789
3790Reads the Float value from this **MessageParcel** object.
3791
3792**System capability**: SystemCapability.Communication.IPC.Core
3793
3794**Return value**
3795
3796  | Type  | Description        |
3797  | ------ | ------------ |
3798  | number | Float value read.|
3799
3800**Example**
3801
3802  ```ts
3803  let data = rpc.MessageParcel.create();
3804  let result = data.writeFloat(1.2);
3805  console.log("RpcClient: writeFloat is " + result);
3806  let ret = data.readFloat();
3807  console.log("RpcClient: readFloat is " + ret);
3808  ```
3809
3810### writeDouble
3811
3812writeDouble(val: number): boolean
3813
3814Writes a Double value to this **MessageParcel** object.
3815
3816**System capability**: SystemCapability.Communication.IPC.Core
3817
3818**Parameters**
3819
3820  | Name| Type  | Mandatory| Description                  |
3821  | ------ | ------ | ---- | ---------------------- |
3822  | val    | number | Yes  | Double value to write.|
3823
3824**Return value**
3825
3826  | Type   | Description                             |
3827  | ------- | --------------------------------- |
3828  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
3829
3830**Example**
3831
3832  ```ts
3833  let data = rpc.MessageParcel.create();
3834  let result = data.writeDouble(10.2);
3835  console.log("RpcClient: writeDouble is " + result);
3836  ```
3837
3838### readDouble
3839
3840readDouble(): number
3841
3842Reads the Double value from this **MessageParcel** object.
3843
3844**System capability**: SystemCapability.Communication.IPC.Core
3845
3846**Return value**
3847
3848  | Type  | Description              |
3849  | ------ | ------------------ |
3850  | number | Double value read.|
3851
3852**Example**
3853
3854  ```ts
3855  let data = rpc.MessageParcel.create();
3856  let result = data.writeDouble(10.2);
3857  console.log("RpcClient: writeDouble is " + result);
3858  let ret = data.readDouble();
3859  console.log("RpcClient: readDouble is " + ret);
3860  ```
3861
3862### writeBoolean
3863
3864writeBoolean(val: boolean): boolean
3865
3866Writes a Boolean value to this **MessageParcel** object.
3867
3868**System capability**: SystemCapability.Communication.IPC.Core
3869
3870**Parameters**
3871
3872  | Name| Type   | Mandatory| Description            |
3873  | ------ | ------- | ---- | ---------------- |
3874  | val    | boolean | Yes  | Boolean value to write.|
3875
3876**Return value**
3877
3878  | Type   | Description                             |
3879  | ------- | --------------------------------- |
3880  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
3881
3882**Example**
3883
3884  ```ts
3885  let data = rpc.MessageParcel.create();
3886  let result = data.writeBoolean(false);
3887  console.log("RpcClient: writeBoolean is " + result);
3888  ```
3889
3890### readBoolean
3891
3892readBoolean(): boolean
3893
3894Reads the Boolean value from this **MessageParcel** object.
3895
3896**System capability**: SystemCapability.Communication.IPC.Core
3897
3898**Return value**
3899
3900  | Type   | Description                |
3901  | ------- | -------------------- |
3902  | boolean | Boolean value read.|
3903
3904**Example**
3905
3906  ```ts
3907  let data = rpc.MessageParcel.create();
3908  let result = data.writeBoolean(false);
3909  console.log("RpcClient: writeBoolean is " + result);
3910  let ret = data.readBoolean();
3911  console.log("RpcClient: readBoolean is " + ret);
3912  ```
3913
3914### writeChar
3915
3916writeChar(val: number): boolean
3917
3918Writes a Char value to this **MessageParcel** object.
3919
3920**System capability**: SystemCapability.Communication.IPC.Core
3921
3922**Parameters**
3923
3924  | Name| Type  | Mandatory| Description                |
3925  | ------ | ------ | ---- | -------------------- |
3926  | val    | number | Yes  | Char value to write.|
3927
3928**Return value**
3929
3930  | Type   | Description                         |
3931  | ------- | ----------------------------- |
3932  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
3933
3934**Example**
3935
3936  ```ts
3937  let data = rpc.MessageParcel.create();
3938  let result = data.writeChar(97);
3939  console.log("RpcClient: writeChar is " + result);
3940  ```
3941
3942### readChar
3943
3944readChar(): number
3945
3946Reads the Char value from this **MessageParcel** object.
3947
3948**System capability**: SystemCapability.Communication.IPC.Core
3949
3950**Return value**
3951
3952  | Type  | Description            |
3953  | ------ | ---------------- |
3954  | number | Char value read.|
3955
3956**Example**
3957
3958  ```ts
3959  let data = rpc.MessageParcel.create();
3960  let result = data.writeChar(97);
3961  console.log("RpcClient: writeChar is " + result);
3962  let ret = data.readChar();
3963  console.log("RpcClient: readChar is " + ret);
3964  ```
3965
3966### writeString
3967
3968writeString(val: string): boolean
3969
3970Writes a string to this **MessageParcel** object.
3971
3972**System capability**: SystemCapability.Communication.IPC.Core
3973
3974**Parameters**
3975
3976  | Name| Type  | Mandatory| Description                                     |
3977  | ------ | ------ | ---- | ----------------------------------------- |
3978  | val    | string | Yes  | String to write. The length of the string must be less than 40960 bytes.|
3979
3980**Return value**
3981
3982  | Type   | Description                             |
3983  | ------- | --------------------------------- |
3984  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
3985
3986**Example**
3987
3988  ```ts
3989  let data = rpc.MessageParcel.create();
3990  let result = data.writeString('abc');
3991  console.log("RpcClient: writeString  is " + result);
3992  ```
3993
3994### readString
3995
3996readString(): string
3997
3998Reads the string from this **MessageParcel** object.
3999
4000**System capability**: SystemCapability.Communication.IPC.Core
4001
4002**Return value**
4003
4004  | Type  | Description          |
4005  | ------ | -------------- |
4006  | string | String read.|
4007
4008**Example**
4009
4010  ```ts
4011  let data = rpc.MessageParcel.create();
4012  let result = data.writeString('abc');
4013  console.log("RpcClient: writeString  is " + result);
4014  let ret = data.readString();
4015  console.log("RpcClient: readString is " + ret);
4016  ```
4017
4018### writeSequenceable
4019
4020writeSequenceable(val: Sequenceable): boolean
4021
4022Writes a sequenceable object to this **MessageParcel** object.
4023
4024**System capability**: SystemCapability.Communication.IPC.Core
4025
4026**Parameters**
4027
4028  | Name| Type                         | Mandatory| Description                |
4029  | ------ | ----------------------------- | ---- | -------------------- |
4030  | val    | [Sequenceable](#sequenceable) | Yes  | Sequenceable object to write.|
4031
4032**Return value**
4033
4034  | Type   | Description                             |
4035  | ------- | --------------------------------- |
4036  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4037
4038**Example**
4039
4040  ```ts
4041  class MySequenceable {
4042      num: number;
4043      str: string;
4044      constructor(num, str) {
4045          this.num = num;
4046          this.str = str;
4047      }
4048      marshalling(messageParcel) {
4049          messageParcel.writeInt(this.num);
4050          messageParcel.writeString(this.str);
4051          return true;
4052      }
4053      unmarshalling(messageParcel) {
4054          this.num = messageParcel.readInt();
4055          this.str = messageParcel.readString();
4056          return true;
4057      }
4058  }
4059  let sequenceable = new MySequenceable(1, "aaa");
4060  let data = rpc.MessageParcel.create();
4061  let result = data.writeSequenceable(sequenceable);
4062  console.log("RpcClient: writeSequenceable is " + result);
4063  ```
4064
4065### readSequenceable
4066
4067readSequenceable(dataIn: Sequenceable): boolean
4068
4069Reads member variables from this **MessageParcel** object.
4070
4071**System capability**: SystemCapability.Communication.IPC.Core
4072
4073**Parameters**
4074
4075  | Name| Type                         | Mandatory| Description                                   |
4076  | ------ | ----------------------------- | ---- | --------------------------------------- |
4077  | dataIn | [Sequenceable](#sequenceabledeprecated) | Yes  | Object that reads member variables from the **MessageParcel** object.|
4078
4079**Return value**
4080
4081  | Type   | Description                                       |
4082  | ------- | ------------------------------------------- |
4083  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
4084
4085**Example**
4086
4087  ```ts
4088  class MySequenceable {
4089      num: number;
4090      str: string;
4091      constructor(num, str) {
4092          this.num = num;
4093          this.str = str;
4094      }
4095      marshalling(messageParcel) {
4096          messageParcel.writeInt(this.num);
4097          messageParcel.writeString(this.str);
4098          return true;
4099      }
4100      unmarshalling(messageParcel) {
4101          this.num = messageParcel.readInt();
4102          this.str = messageParcel.readString();
4103          return true;
4104      }
4105  }
4106  let sequenceable = new MySequenceable(1, "aaa");
4107  let data = rpc.MessageParcel.create();
4108  let result = data.writeSequenceable(sequenceable);
4109  console.log("RpcClient: writeSequenceable is " + result);
4110  let ret = new MySequenceable(0, "");
4111  let result2 = data.readSequenceable(ret);
4112  console.log("RpcClient: writeSequenceable is " + result2);
4113  ```
4114
4115### writeByteArray
4116
4117writeByteArray(byteArray: number[]): boolean
4118
4119Writes a byte array to this **MessageParcel** object.
4120
4121**System capability**: SystemCapability.Communication.IPC.Core
4122
4123**Parameters**
4124
4125  | Name   | Type    | Mandatory| Description              |
4126  | --------- | -------- | ---- | ------------------ |
4127  | byteArray | number[] | Yes  | Byte array to write.|
4128
4129**Return value**
4130
4131  | Type   | Description                             |
4132  | ------- | --------------------------------- |
4133  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4134
4135**Example**
4136
4137  ```ts
4138  let data = rpc.MessageParcel.create();
4139  let ByteArrayVar = [1, 2, 3, 4, 5];
4140  let result = data.writeByteArray(ByteArrayVar);
4141  console.log("RpcClient: writeByteArray is " + result);
4142  ```
4143
4144### readByteArray
4145
4146readByteArray(dataIn: number[]): void
4147
4148Reads a byte array from this **MessageParcel** object.
4149
4150**System capability**: SystemCapability.Communication.IPC.Core
4151
4152**Parameters**
4153
4154  | Name| Type    | Mandatory| Description              |
4155  | ------ | -------- | ---- | ------------------ |
4156  | dataIn | number[] | Yes  | Byte array to read.|
4157
4158**Example**
4159
4160  ```ts
4161  let data = rpc.MessageParcel.create();
4162  let ByteArrayVar = [1, 2, 3, 4, 5];
4163  let result = data.writeByteArray(ByteArrayVar);
4164  console.log("RpcClient: writeByteArray is " + result);
4165  let array = new Array(5);
4166  data.readByteArray(array);
4167  ```
4168
4169### readByteArray
4170
4171readByteArray(): number[]
4172
4173Reads the byte array from this **MessageParcel** object.
4174
4175**System capability**: SystemCapability.Communication.IPC.Core
4176
4177**Return value**
4178
4179  | Type    | Description          |
4180  | -------- | -------------- |
4181  | number[] | Byte array read.|
4182
4183**Example**
4184
4185  ```ts
4186  let data = rpc.MessageParcel.create();
4187  let ByteArrayVar = [1, 2, 3, 4, 5];
4188  let result = data.writeByteArray(ByteArrayVar);
4189  console.log("RpcClient: writeByteArray is " + result);
4190  let array = data.readByteArray();
4191  console.log("RpcClient: readByteArray is " + array);
4192  ```
4193
4194### writeShortArray
4195
4196writeShortArray(shortArray: number[]): boolean
4197
4198Writes a short array to this **MessageParcel** object.
4199
4200**System capability**: SystemCapability.Communication.IPC.Core
4201
4202**Parameters**
4203
4204  | Name    | Type    | Mandatory| Description                |
4205  | ---------- | -------- | ---- | -------------------- |
4206  | shortArray | number[] | Yes  | Short array to write.|
4207
4208**Return value**
4209
4210  | Type   | Description                         |
4211  | ------- | ----------------------------- |
4212  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4213
4214**Example**
4215
4216  ```ts
4217  let data = rpc.MessageParcel.create();
4218  let result = data.writeShortArray([11, 12, 13]);
4219  console.log("RpcClient: writeShortArray is " + result);
4220  ```
4221
4222### readShortArray
4223
4224readShortArray(dataIn: number[]): void
4225
4226Reads a short array from this **MessageParcel** object.
4227
4228**System capability**: SystemCapability.Communication.IPC.Core
4229
4230**Parameters**
4231
4232  | Name| Type    | Mandatory| Description                |
4233  | ------ | -------- | ---- | -------------------- |
4234  | dataIn | number[] | Yes  | Short array to read.|
4235
4236**Example**
4237
4238  ```ts
4239  let data = rpc.MessageParcel.create();
4240  let result = data.writeShortArray([11, 12, 13]);
4241  console.log("RpcClient: writeShortArray is " + result);
4242  let array = new Array(3);
4243  data.readShortArray(array);
4244  ```
4245
4246### readShortArray
4247
4248readShortArray(): number[]
4249
4250Reads the short array from this **MessageParcel** object.
4251
4252**System capability**: SystemCapability.Communication.IPC.Core
4253
4254**Return value**
4255
4256  | Type    | Description            |
4257  | -------- | ---------------- |
4258  | number[] | Short array read.|
4259
4260**Example**
4261
4262  ```ts
4263  let data = rpc.MessageParcel.create();
4264  let result = data.writeShortArray([11, 12, 13]);
4265  console.log("RpcClient: writeShortArray is " + result);
4266  let array = data.readShortArray();
4267 console.log("RpcClient: readShortArray is " + array);
4268  ```
4269
4270### writeIntArray
4271
4272writeIntArray(intArray: number[]): boolean
4273
4274Writes an integer array to this **MessageParcel** object.
4275
4276**System capability**: SystemCapability.Communication.IPC.Core
4277
4278**Parameters**
4279
4280  | Name  | Type    | Mandatory| Description              |
4281  | -------- | -------- | ---- | ------------------ |
4282  | intArray | number[] | Yes  | Integer array to write.|
4283
4284**Return value**
4285
4286  | Type   | Description                         |
4287  | ------- | ----------------------------- |
4288  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4289
4290**Example**
4291
4292  ```ts
4293  let data = rpc.MessageParcel.create();
4294  let result = data.writeIntArray([100, 111, 112]);
4295  console.log("RpcClient: writeIntArray is " + result);
4296  ```
4297
4298### readIntArray
4299
4300readIntArray(dataIn: number[]): void
4301
4302Reads an integer array from this **MessageParcel** object.
4303
4304**System capability**: SystemCapability.Communication.IPC.Core
4305
4306**Parameters**
4307
4308  | Name| Type    | Mandatory| Description              |
4309  | ------ | -------- | ---- | ------------------ |
4310  | dataIn | number[] | Yes  | Integer array to read.|
4311
4312**Example**
4313
4314  ```ts
4315  let data = rpc.MessageParcel.create();
4316  let result = data.writeIntArray([100, 111, 112]);
4317  console.log("RpcClient: writeIntArray is " + result);
4318  let array = new Array(3);
4319  data.readIntArray(array);
4320  ```
4321
4322### readIntArray
4323
4324readIntArray(): number[]
4325
4326Reads the integer array from this **MessageParcel** object.
4327
4328**System capability**: SystemCapability.Communication.IPC.Core
4329
4330**Return value**
4331
4332  | Type    | Description          |
4333  | -------- | -------------- |
4334  | number[] | Integer array read.|
4335
4336**Example**
4337
4338  ```ts
4339  let data = rpc.MessageParcel.create();
4340  let result = data.writeIntArray([100, 111, 112]);
4341  console.log("RpcClient: writeIntArray is " + result);
4342  let array = data.readIntArray();
4343  console.log("RpcClient: readIntArray is " + array);
4344  ```
4345
4346### writeLongArray
4347
4348writeLongArray(longArray: number[]): boolean
4349
4350Writes a long array to this **MessageParcel** object.
4351
4352**System capability**: SystemCapability.Communication.IPC.Core
4353
4354**Parameters**
4355
4356  | Name   | Type    | Mandatory| Description                |
4357  | --------- | -------- | ---- | -------------------- |
4358  | longArray | number[] | Yes  | Long array to write.|
4359
4360**Return value**
4361
4362  | Type   | Description                         |
4363  | ------- | ----------------------------- |
4364  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4365
4366**Example**
4367
4368  ```ts
4369  let data = rpc.MessageParcel.create();
4370  let result = data.writeLongArray([1111, 1112, 1113]);
4371  console.log("RpcClient: writeLongArray is " + result);
4372  ```
4373
4374### readLongArray
4375
4376readLongArray(dataIn: number[]): void
4377
4378Reads a long array from this **MessageParcel** object.
4379
4380**System capability**: SystemCapability.Communication.IPC.Core
4381
4382**Parameters**
4383
4384  | Name| Type    | Mandatory| Description                |
4385  | ------ | -------- | ---- | -------------------- |
4386  | dataIn | number[] | Yes  | Long array to read.|
4387
4388**Example**
4389
4390  ```ts
4391  let data = rpc.MessageParcel.create();
4392  let result = data.writeLongArray([1111, 1112, 1113]);
4393  console.log("RpcClient: writeLongArray is " + result);
4394  let array = new Array(3);
4395  data.readLongArray(array);
4396  ```
4397
4398### readLongArray
4399
4400readLongArray(): number[]
4401
4402Reads the long array from this **MessageParcel** object.
4403
4404**System capability**: SystemCapability.Communication.IPC.Core
4405
4406**Return value**
4407
4408 | Type    | Description            |
4409 | -------- | ---------------- |
4410 | number[] | Long array read.|
4411
4412**Example**
4413
4414  ```ts
4415  let data = rpc.MessageParcel.create();
4416  let result = data.writeLongArray([1111, 1112, 1113]);
4417  console.log("RpcClient: writeLongArray is " + result);
4418  let array = data.readLongArray();
4419  console.log("RpcClient: readLongArray is " + array);
4420  ```
4421
4422### writeFloatArray
4423
4424writeFloatArray(floatArray: number[]): boolean
4425
4426Writes a FloatArray to this **MessageParcel** object.
4427
4428**System capability**: SystemCapability.Communication.IPC.Core
4429
4430**Parameters**
4431
4432  | Name| Type| Mandatory| Description|
4433  | ---------- | -------- | ---- | --- |
4434  | 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.|
4435
4436**Return value**
4437
4438  | Type   | Description                         |
4439  | ------- | ----------------------------- |
4440  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4441
4442**Example**
4443
4444  ```ts
4445  let data = rpc.MessageParcel.create();
4446  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
4447  console.log("RpcClient: writeFloatArray is " + result);
4448  ```
4449
4450### readFloatArray
4451
4452readFloatArray(dataIn: number[]): void
4453
4454Reads a FloatArray from this **MessageParcel** object.
4455
4456**System capability**: SystemCapability.Communication.IPC.Core
4457
4458**Parameters**
4459
4460  | Name| Type| Mandatory| Description|
4461  | ------ | -------- | ---- | ------ |
4462  | 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.|
4463
4464**Example**
4465
4466  ```ts
4467  let data = rpc.MessageParcel.create();
4468  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
4469  console.log("RpcClient: writeFloatArray is " + result);
4470  let array = new Array(3);
4471  data.readFloatArray(array);
4472  ```
4473
4474### readFloatArray
4475
4476readFloatArray(): number[]
4477
4478Reads the FloatArray from this **MessageParcel** object.
4479
4480**System capability**: SystemCapability.Communication.IPC.Core
4481
4482**Return value**
4483
4484  | Type    | Description          |
4485  | -------- | -------------- |
4486  | number[] | FloatArray read.|
4487
4488**Example**
4489
4490  ```ts
4491  let data = rpc.MessageParcel.create();
4492  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
4493  console.log("RpcClient: writeFloatArray is " + result);
4494  let array = data.readFloatArray();
4495  console.log("RpcClient: readFloatArray is " + array);
4496  ```
4497
4498### writeDoubleArray
4499
4500writeDoubleArray(doubleArray: number[]): boolean
4501
4502Writes a DoubleArray to this **MessageParcel** object.
4503
4504**System capability**: SystemCapability.Communication.IPC.Core
4505
4506**Parameters**
4507
4508  | Name     | Type    | Mandatory| Description                    |
4509  | ----------- | -------- | ---- | ------------------------ |
4510  | doubleArray | number[] | Yes  | DoubleArray to write.|
4511
4512**Return value**
4513
4514  | Type   | Description                         |
4515  | ------- | ----------------------------- |
4516  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4517
4518**Example**
4519
4520  ```ts
4521  let data = rpc.MessageParcel.create();
4522  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
4523  console.log("RpcClient: writeDoubleArray is " + result);
4524  ```
4525
4526### readDoubleArray
4527
4528readDoubleArray(dataIn: number[]): void
4529
4530Reads a DoubleArray from this **MessageParcel** object.
4531
4532**System capability**: SystemCapability.Communication.IPC.Core
4533
4534**Parameters**
4535
4536  | Name| Type    | Mandatory| Description                    |
4537  | ------ | -------- | ---- | ------------------------ |
4538  | dataIn | number[] | Yes  | DoubleArray to read.|
4539
4540**Example**
4541
4542  ```ts
4543  let data = rpc.MessageParcel.create();
4544  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
4545  console.log("RpcClient: writeDoubleArray is " + result);
4546  let array = new Array(3);
4547  data.readDoubleArray(array);
4548  ```
4549
4550### readDoubleArray
4551
4552readDoubleArray(): number[]
4553
4554Reads the DoubleArray from this **MessageParcel** object.
4555
4556**System capability**: SystemCapability.Communication.IPC.Core
4557
4558**Return value**
4559
4560  | Type    | Description                |
4561  | -------- | -------------------- |
4562  | number[] | DoubleArray read.|
4563
4564**Example**
4565
4566  ```ts
4567  let data = rpc.MessageParcel.create();
4568  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
4569  console.log("RpcClient: writeDoubleArray is " + result);
4570  let array = data.readDoubleArray();
4571  console.log("RpcClient: readDoubleArray is " + array);
4572  ```
4573
4574### writeBooleanArray
4575
4576writeBooleanArray(booleanArray: boolean[]): boolean
4577
4578Writes a Boolean array to this **MessageParcel** object.
4579
4580**System capability**: SystemCapability.Communication.IPC.Core
4581
4582**Parameters**
4583
4584  | Name      | Type     | Mandatory| Description              |
4585  | ------------ | --------- | ---- | ------------------ |
4586  | booleanArray | boolean[] | Yes  | Boolean array to write.|
4587
4588**Return value**
4589
4590  | Type   | Description                             |
4591  | ------- | --------------------------------- |
4592  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4593
4594**Example**
4595
4596  ```ts
4597  let data = rpc.MessageParcel.create();
4598  let result = data.writeBooleanArray([false, true, false]);
4599  console.log("RpcClient: writeBooleanArray is " + result);
4600  ```
4601
4602### readBooleanArray
4603
4604readBooleanArray(dataIn: boolean[]): void
4605
4606Reads a Boolean array from this **MessageParcel** object.
4607
4608**System capability**: SystemCapability.Communication.IPC.Core
4609
4610**Parameters**
4611
4612  | Name| Type     | Mandatory| Description              |
4613  | ------ | --------- | ---- | ------------------ |
4614  | dataIn | boolean[] | Yes  | Boolean array to read.|
4615
4616**Example**
4617
4618  ```ts
4619  let data = rpc.MessageParcel.create();
4620  let result = data.writeBooleanArray([false, true, false]);
4621  console.log("RpcClient: writeBooleanArray is " + result);
4622  let array = new Array(3);
4623  data.readBooleanArray(array);
4624  ```
4625
4626### readBooleanArray
4627
4628readBooleanArray(): boolean[]
4629
4630Reads the Boolean array from this **MessageParcel** object.
4631
4632**System capability**: SystemCapability.Communication.IPC.Core
4633
4634**Return value**
4635
4636  | Type     | Description          |
4637  | --------- | -------------- |
4638  | boolean[] | Boolean array read.|
4639
4640**Example**
4641
4642  ```ts
4643  let data = rpc.MessageParcel.create();
4644  let result = data.writeBooleanArray([false, true, false]);
4645  console.log("RpcClient: writeBooleanArray is " + result);
4646  let array = data.readBooleanArray();
4647  console.log("RpcClient: readBooleanArray is " + array);
4648  ```
4649
4650### writeCharArray
4651
4652writeCharArray(charArray: number[]): boolean
4653
4654Writes a character array to this **MessageParcel** object.
4655
4656**System capability**: SystemCapability.Communication.IPC.Core
4657
4658**Parameters**
4659
4660  | Name   | Type    | Mandatory| Description                  |
4661  | --------- | -------- | ---- | ---------------------- |
4662  | charArray | number[] | Yes  | Character array to write.|
4663
4664**Return value**
4665
4666  | Type   | Description                             |
4667  | ------- | --------------------------------- |
4668  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4669
4670**Example**
4671
4672  ```ts
4673  let data = rpc.MessageParcel.create();
4674  let result = data.writeCharArray([97, 98, 88]);
4675  console.log("RpcClient: writeCharArray is " + result);
4676  ```
4677
4678### readCharArray
4679
4680readCharArray(dataIn: number[]): void
4681
4682Reads a character array from this **MessageParcel** object.
4683
4684**System capability**: SystemCapability.Communication.IPC.Core
4685
4686**Parameters**
4687
4688  | Name| Type    | Mandatory| Description                  |
4689  | ------ | -------- | ---- | ---------------------- |
4690  | dataIn | number[] | Yes  | Character array to read.|
4691
4692**Example**
4693
4694  ```ts
4695  let data = rpc.MessageParcel.create();
4696  let result = data.writeCharArray([97, 98, 99]);
4697  console.log("RpcClient: writeCharArray is " + result);
4698  let array = new Array(3);
4699  data.readCharArray(array);
4700  ```
4701
4702### readCharArray
4703
4704readCharArray(): number[]
4705
4706Reads the character array from this **MessageParcel** object.
4707
4708**System capability**: SystemCapability.Communication.IPC.Core
4709
4710**Return value**
4711
4712  | Type    | Description              |
4713  | -------- | ------------------ |
4714  | number[] | Character array read.|
4715
4716**Example**
4717
4718  ```ts
4719  let data = rpc.MessageParcel.create();
4720  let result = data.writeCharArray([97, 98, 99]);
4721  console.log("RpcClient: writeCharArray is " + result);
4722  let array = data.readCharArray();
4723  console.log("RpcClient: readCharArray is " + array);
4724  ```
4725
4726### writeStringArray
4727
4728writeStringArray(stringArray: string[]): boolean
4729
4730Writes a string array to this **MessageParcel** object.
4731
4732**System capability**: SystemCapability.Communication.IPC.Core
4733
4734**Parameters**
4735
4736  | Name     | Type    | Mandatory| Description|
4737  | ----------- | -------- | ---- | ---------------- |
4738  | stringArray | string[] | Yes  | String array to write. The length of a single element in the array must be less than 40960 bytes.|
4739
4740**Return value**
4741
4742  | Type   | Description|
4743  | ------- | --------------------------------- |
4744  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4745
4746**Example**
4747
4748  ```ts
4749  let data = rpc.MessageParcel.create();
4750  let result = data.writeStringArray(["abc", "def"]);
4751  console.log("RpcClient: writeStringArray is " + result);
4752  ```
4753
4754### readStringArray
4755
4756readStringArray(dataIn: string[]): void
4757
4758Reads a string array from this **MessageParcel** object.
4759
4760**System capability**: SystemCapability.Communication.IPC.Core
4761
4762**Parameters**
4763
4764  | Name| Type    | Mandatory| Description                |
4765  | ------ | -------- | ---- | -------------------- |
4766  | dataIn | string[] | Yes  | String array to read.|
4767
4768**Example**
4769
4770  ```ts
4771  let data = rpc.MessageParcel.create();
4772  let result = data.writeStringArray(["abc", "def"]);
4773  console.log("RpcClient: writeStringArray is " + result);
4774  let array = new Array(2);
4775  data.readStringArray(array);
4776  ```
4777
4778### readStringArray
4779
4780readStringArray(): string[]
4781
4782Reads the string array from this **MessageParcel** object.
4783
4784**System capability**: SystemCapability.Communication.IPC.Core
4785
4786**Return value**
4787
4788  | Type    | Description            |
4789  | -------- | ---------------- |
4790  | string[] | String array read.|
4791
4792**Example**
4793
4794  ```ts
4795  let data = rpc.MessageParcel.create();
4796  let result = data.writeStringArray(["abc", "def"]);
4797  console.log("RpcClient: writeStringArray is " + result);
4798  let array = data.readStringArray();
4799  console.log("RpcClient: readStringArray is " + array);
4800  ```
4801
4802### writeNoException<sup>8+</sup>
4803
4804writeNoException(): void
4805
4806Writes information to this **MessageParcel** object indicating that no exception occurred.
4807
4808**System capability**: SystemCapability.Communication.IPC.Core
4809
4810**Example**
4811
4812  ```ts
4813  class MyDeathRecipient {
4814      onRemoteDied() {
4815          console.log("server died");
4816      }
4817  }
4818  class TestRemoteObject extends rpc.RemoteObject {
4819      constructor(descriptor) {
4820          super(descriptor);
4821      }
4822      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
4823          return true;
4824      }
4825      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
4826          return true;
4827      }
4828      isObjectDead(): boolean {
4829          return false;
4830      }
4831      onRemoteRequest(code, data, reply, option) {
4832          if (code === 1) {
4833              console.log("RpcServer: onRemoteRequest called");
4834              reply.writeNoException();
4835              return true;
4836          } else {
4837              console.log("RpcServer: unknown code: " + code);
4838              return false;
4839          }
4840      }
4841  }
4842  ```
4843
4844### readException<sup>8+</sup>
4845
4846readException(): void
4847
4848Reads the exception information from this **MessageParcel** object.
4849
4850**System capability**: SystemCapability.Communication.IPC.Core
4851
4852**Example**
4853
4854  Obtain the service.
4855
4856  ```ts
4857  import FA from "@ohos.ability.featureAbility";
4858  let proxy;
4859  let connect = {
4860      onConnect: function(elementName, remoteProxy) {
4861          console.log("RpcClient: js onConnect called.");
4862          proxy = remoteProxy;
4863      },
4864      onDisconnect: function(elementName) {
4865          console.log("RpcClient: onDisconnect");
4866      },
4867      onFailed: function() {
4868          console.log("RpcClient: onFailed");
4869      }
4870  };
4871  let want = {
4872      "bundleName": "com.ohos.server",
4873      "abilityName": "com.ohos.server.MainAbility",
4874  };
4875  FA.connectAbility(want, connect);
4876  ```
4877
4878  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.
4879
4880  ```ts
4881  let option = new rpc.MessageOption();
4882  let data = rpc.MessageParcel.create();
4883  let reply = rpc.MessageParcel.create();
4884  data.writeInt(1);
4885  data.writeString("hello");
4886  proxy.sendMessageRequest(1, data, reply, option)
4887      .then(function(errCode) {
4888          if (errCode === 0) {
4889              console.log("sendMessageRequest got result");
4890              reply.readException();
4891              let msg = reply.readString();
4892              console.log("RPCTest: reply msg: " + msg);
4893          } else {
4894              console.log("RPCTest: sendMessageRequest failed, errCode: " + errCode);
4895          }
4896      }).catch(function(e) {
4897          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
4898      }).finally (() => {
4899          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
4900          data.reclaim();
4901          reply.reclaim();
4902      });
4903  ```
4904
4905### writeSequenceableArray
4906
4907writeSequenceableArray(sequenceableArray: Sequenceable[]): boolean
4908
4909Writes a sequenceable array to this **MessageParcel** object.
4910
4911**System capability**: SystemCapability.Communication.IPC.Core
4912
4913**Parameters**
4914
4915  | Name           | Type          | Mandatory| Description                      |
4916  | ----------------- | -------------- | ---- | -------------------------- |
4917  | sequenceableArray | Sequenceable[] | Yes  | Sequenceable array to write.|
4918
4919**Return value**
4920
4921  | Type   | Description                             |
4922  | ------- | --------------------------------- |
4923  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
4924
4925**Example**
4926
4927  ```ts
4928  class MySequenceable {
4929      num: number;
4930      str: string;
4931      constructor(num, str) {
4932          this.num = num;
4933          this.str = str;
4934      }
4935      marshalling(messageParcel) {
4936          messageParcel.writeInt(this.num);
4937          messageParcel.writeString(this.str);
4938          return true;
4939      }
4940      unmarshalling(messageParcel) {
4941          this.num = messageParcel.readInt();
4942          this.str = messageParcel.readString();
4943          return true;
4944      }
4945  }
4946  let sequenceable = new MySequenceable(1, "aaa");
4947  let sequenceable2 = new MySequenceable(2, "bbb");
4948  let sequenceable3 = new MySequenceable(3, "ccc");
4949  let a = [sequenceable, sequenceable2, sequenceable3];
4950  let data = rpc.MessageParcel.create();
4951  let result = data.writeSequenceableArray(a);
4952  console.log("RpcClient: writeSequenceableArray is " + result);
4953  ```
4954
4955### readSequenceableArray<sup>8+</sup>
4956
4957readSequenceableArray(sequenceableArray: Sequenceable[]): void
4958
4959Reads a sequenceable array from this **MessageParcel** object.
4960
4961**System capability**: SystemCapability.Communication.IPC.Core
4962
4963**Parameters**
4964
4965  | Name           | Type          | Mandatory| Description                      |
4966  | ----------------- | -------------- | ---- | -------------------------- |
4967  | sequenceableArray | Sequenceable[] | Yes  | Sequenceable array to read.|
4968
4969**Example**
4970
4971  ```ts
4972  class MySequenceable {
4973      num: number;
4974      str: string;
4975      constructor(num, str) {
4976          this.num = num;
4977          this.str = str;
4978      }
4979      marshalling(messageParcel) {
4980          messageParcel.writeInt(this.num);
4981          messageParcel.writeString(this.str);
4982          return true;
4983      }
4984      unmarshalling(messageParcel) {
4985          this.num = messageParcel.readInt();
4986          this.str = messageParcel.readString();
4987          return true;
4988      }
4989  }
4990  let sequenceable = new MySequenceable(1, "aaa");
4991  let sequenceable2 = new MySequenceable(2, "bbb");
4992  let sequenceable3 = new MySequenceable(3, "ccc");
4993  let a = [sequenceable, sequenceable2, sequenceable3];
4994  let data = rpc.MessageParcel.create();
4995  let result = data.writeSequenceableArray(a);
4996  console.log("RpcClient: writeSequenceableArray is " + result);
4997  let b = [new MySequenceable(0, ""), new MySequenceable(0, ""), new MySequenceable(0, "")];
4998  data.readSequenceableArray(b);
4999  ```
5000
5001### writeRemoteObjectArray<sup>8+</sup>
5002
5003writeRemoteObjectArray(objectArray: IRemoteObject[]): boolean
5004
5005Writes an array of **IRemoteObject** objects to this **MessageParcel** object.
5006
5007**System capability**: SystemCapability.Communication.IPC.Core
5008
5009**Parameters**
5010
5011  | Name     | Type           | Mandatory| Description|
5012  | ----------- | --------------- | ---- | ----- |
5013  | objectArray | IRemoteObject[] | Yes  | Array of **IRemoteObject** objects to write.|
5014
5015**Return value**
5016
5017  | Type   | Description                                                                                                                |
5018  | ------- | -------------------------------------------------------------------------------------------------------------------- |
5019  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5020
5021**Example**
5022
5023  ```ts
5024  class MyDeathRecipient {
5025      onRemoteDied() {
5026          console.log("server died");
5027      }
5028  }
5029  class TestRemoteObject extends rpc.RemoteObject {
5030      constructor(descriptor) {
5031          super(descriptor);
5032          this.attachLocalInterface(this, descriptor);
5033      }
5034      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5035          return true;
5036      }
5037      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5038          return true;
5039      }
5040      isObjectDead(): boolean {
5041          return false;
5042      }
5043      asObject(): rpc.IRemoteObject {
5044          return this;
5045      }
5046  }
5047  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
5048  let data = rpc.MessageParcel.create();
5049  let result = data.writeRemoteObjectArray(a);
5050  console.log("RpcClient: writeRemoteObjectArray is " + result);
5051  ```
5052
5053### readRemoteObjectArray<sup>8+</sup>
5054
5055readRemoteObjectArray(objects: IRemoteObject[]): void
5056
5057Reads an **IRemoteObject** array from this **MessageParcel** object.
5058
5059**System capability**: SystemCapability.Communication.IPC.Core
5060
5061**Parameters**
5062
5063  | Name | Type           | Mandatory| Description|
5064  | ------- | --------------- | ---- | --------- |
5065  | objects | IRemoteObject[] | Yes  | **IRemoteObject** array to read.|
5066
5067**Example**
5068
5069  ```ts
5070  class MyDeathRecipient {
5071      onRemoteDied() {
5072          console.log("server died");
5073      }
5074  }
5075  class TestRemoteObject extends rpc.RemoteObject {
5076      constructor(descriptor) {
5077          super(descriptor);
5078          this.attachLocalInterface(this, descriptor);
5079      }
5080      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5081          return true;
5082      }
5083      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5084          return true;
5085      }
5086      isObjectDead(): boolean {
5087         return false;
5088      }
5089      asObject(): rpc.IRemoteObject {
5090          return this;
5091      }
5092  }
5093  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
5094  let data = rpc.MessageParcel.create();
5095  let result = data.writeRemoteObjectArray(a);
5096  let b = new Array(3);
5097  data.readRemoteObjectArray(b);
5098  ```
5099
5100### readRemoteObjectArray<sup>8+</sup>
5101
5102readRemoteObjectArray(): IRemoteObject[]
5103
5104Reads the **IRemoteObject** array from this **MessageParcel** object.
5105
5106**System capability**: SystemCapability.Communication.IPC.Core
5107
5108**Return value**
5109
5110  | Type| Description|
5111  | --------------- | -------- |
5112  | IRemoteObject[] | **IRemoteObject** object array obtained.|
5113
5114**Example**
5115
5116  ```ts
5117  class MyDeathRecipient {
5118      onRemoteDied() {
5119          console.log("server died");
5120      }
5121  }
5122  class TestRemoteObject extends rpc.RemoteObject {
5123      constructor(descriptor) {
5124          super(descriptor);
5125          this.attachLocalInterface(this, descriptor);
5126      }
5127      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5128          return true;
5129      }
5130      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
5131          return true;
5132      }
5133      isObjectDead(): boolean {
5134          return false;
5135      }
5136      asObject(): rpc.IRemoteObject {
5137          return this;
5138      }
5139  }
5140  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
5141  let data = rpc.MessageParcel.create();
5142  let result = data.writeRemoteObjectArray(a);
5143  console.log("RpcClient: readRemoteObjectArray is " + result);
5144  let b = data.readRemoteObjectArray();
5145  console.log("RpcClient: readRemoteObjectArray is " + b);
5146  ```
5147
5148### closeFileDescriptor<sup>8+</sup>
5149
5150static closeFileDescriptor(fd: number): void
5151
5152Closes a file descriptor. This API is a static method.
5153
5154**System capability**: SystemCapability.Communication.IPC.Core
5155
5156**Parameters**
5157
5158  | Name| Type  | Mandatory| Description                |
5159  | ------ | ------ | ---- | -------------------- |
5160  | fd     | number | Yes  | File descriptor to close.|
5161
5162**Example**
5163
5164  ```ts
5165  import fileio from '@ohos.fileio';
5166  let filePath = "path/to/file";
5167  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
5168  rpc.MessageParcel.closeFileDescriptor(fd);
5169  ```
5170
5171### dupFileDescriptor<sup>8+</sup>
5172
5173static dupFileDescriptor(fd: number) :number
5174
5175Duplicates a file descriptor. This API is a static method.
5176
5177**System capability**: SystemCapability.Communication.IPC.Core
5178
5179**Parameters**
5180
5181  | Name| Type  | Mandatory| Description                    |
5182  | ------ | ------ | ---- | ------------------------ |
5183  | fd     | number | Yes  | File descriptor to duplicate.|
5184
5185**Return value**
5186
5187  | Type  | Description                |
5188  | ------ | -------------------- |
5189  | number | New file descriptor.|
5190
5191**Example**
5192
5193  ```ts
5194  import fileio from '@ohos.fileio';
5195  let filePath = "path/to/file";
5196  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
5197  let newFd = rpc.MessageParcel.dupFileDescriptor(fd);
5198  ```
5199
5200### containFileDescriptors<sup>8+</sup>
5201
5202containFileDescriptors(): boolean
5203
5204Checks whether this **MessageParcel** object contains file descriptors.
5205
5206**System capability**: SystemCapability.Communication.IPC.Core
5207
5208**Return value**
5209
5210  | Type   | Description                                                              |
5211  | ------- | ------------------------------------------------------------------ |
5212  | boolean |Returns **true** if the **MessageParcel** object contains file descriptors; returns **false** otherwise.|
5213
5214**Example**
5215
5216  ```ts
5217  import fileio from '@ohos.fileio';
5218  let parcel = new rpc.MessageParcel();
5219  let filePath = "path/to/file";
5220  let r1 = parcel.containFileDescriptors();
5221  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
5222  let writeResult = parcel.writeFileDescriptor(fd);
5223  console.log("RpcTest: parcel writeFd result is : " + writeResult);
5224  let containFD = parcel.containFileDescriptors();
5225  console.log("RpcTest: parcel after write fd containFd result is : " + containFD);
5226  ```
5227
5228### writeFileDescriptor<sup>8+</sup>
5229
5230writeFileDescriptor(fd: number): boolean
5231
5232Writes a file descriptor to this **MessageParcel** object.
5233
5234**System capability**: SystemCapability.Communication.IPC.Core
5235
5236**Parameters**
5237
5238  | Name| Type  | Mandatory| Description        |
5239  | ------ | ------ | ---- | ------------ |
5240  | fd     | number | Yes  | File descriptor to write.|
5241
5242**Return value**
5243
5244  | Type   | Description                                     |
5245  | ------- | ----------------------------------------- |
5246  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
5247
5248**Example**
5249
5250  ```ts
5251  import fileio from '@ohos.fileio';
5252  let parcel = new rpc.MessageParcel();
5253  let filePath = "path/to/file";
5254  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
5255  let writeResult = parcel.writeFileDescriptor(fd);
5256  console.log("RpcTest: parcel writeFd result is : " + writeResult);
5257  ```
5258
5259### readFileDescriptor<sup>8+</sup>
5260
5261readFileDescriptor(): number
5262
5263Reads the file descriptor from this **MessageParcel** object.
5264
5265**System capability**: SystemCapability.Communication.IPC.Core
5266
5267**Return value**
5268
5269  | Type  | Description            |
5270  | ------ | ---------------- |
5271  | number | File descriptor read.|
5272
5273**Example**
5274
5275  ```ts
5276  import fileio from '@ohos.fileio';
5277  let parcel = new rpc.MessageParcel();
5278  let filePath = "path/to/file";
5279  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
5280  let writeResult = parcel.writeFileDescriptor(fd);
5281  let readFD = parcel.readFileDescriptor();
5282  console.log("RpcTest: parcel read fd is : " + readFD);
5283  ```
5284
5285### writeAshmem<sup>8+</sup>
5286
5287writeAshmem(ashmem: Ashmem): boolean
5288
5289Writes an anonymous shared object to this **MessageParcel** object.
5290
5291**System capability**: SystemCapability.Communication.IPC.Core
5292
5293**Parameters**
5294
5295  | Name| Type  | Mandatory| Description                               |
5296  | ------ | ------ | ---- | ----------------------------------- |
5297  | ashmem | Ashmem | Yes  | Anonymous shared object to write.|
5298
5299**Return value**
5300
5301  | Type   | Description                                                                |
5302  | ------- | -------------------------------------------------------------------- |
5303  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5304
5305**Example**
5306
5307  ```ts
5308  let parcel = new rpc.MessageParcel();
5309  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024);
5310  let isWriteSuccess = parcel.writeAshmem(ashmem);
5311  console.log("RpcTest: write ashmem to result is : " + isWriteSuccess);
5312  ```
5313
5314### readAshmem<sup>8+</sup>
5315
5316readAshmem(): Ashmem
5317
5318Reads the anonymous shared object from this **MessageParcel** object.
5319
5320**System capability**: SystemCapability.Communication.IPC.Core
5321
5322**Return value**
5323
5324  | Type  | Description              |
5325  | ------ | ------------------ |
5326  | Ashmem | Anonymous share object obtained.|
5327
5328**Example**
5329
5330  ```ts
5331  let parcel = new rpc.MessageParcel();
5332  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024);
5333  let isWriteSuccess = parcel.writeAshmem(ashmem);
5334  console.log("RpcTest: write ashmem to result is : " + isWriteSuccess);
5335  let readAshmem = parcel.readAshmem();
5336  console.log("RpcTest: read ashmem to result is : " + readAshmem);
5337  ```
5338
5339### getRawDataCapacity<sup>8+</sup>
5340
5341getRawDataCapacity(): number
5342
5343Obtains the maximum amount of raw data that can be held by this **MessageParcel** object.
5344
5345**System capability**: SystemCapability.Communication.IPC.Core
5346
5347**Return value**
5348
5349  | Type  | Description                                                      |
5350  | ------ | ---------------------------------------------------------- |
5351  | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.|
5352
5353**Example**
5354
5355  ```ts
5356  let parcel = new rpc.MessageParcel();
5357  let result = parcel.getRawDataCapacity();
5358  console.log("RpcTest: parcel get RawDataCapacity result is : " + result);
5359  ```
5360
5361### writeRawData<sup>8+</sup>
5362
5363writeRawData(rawData: number[], size: number): boolean
5364
5365Writes raw data to this **MessageParcel** object.
5366
5367**System capability**: SystemCapability.Communication.IPC.Core
5368
5369**Parameters**
5370
5371  | Name | Type    | Mandatory| Description                              |
5372  | ------- | -------- | ---- | ---------------------------------- |
5373  | rawData | number[] | Yes  | Raw data to write.                |
5374  | size    | number   | Yes  | Size of the raw data, in bytes.|
5375
5376**Return value**
5377
5378  | Type   | Description                                     |
5379  | ------- | ----------------------------------------- |
5380  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
5381
5382**Example**
5383
5384  ```ts
5385  let parcel = new rpc.MessageParcel();
5386  let arr = [1, 2, 3, 4, 5];
5387  let isWriteSuccess = parcel.writeRawData(arr, arr.length);
5388  console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
5389  ```
5390
5391### readRawData<sup>8+</sup>
5392
5393readRawData(size: number): number[]
5394
5395Reads raw data from this **MessageParcel** object.
5396
5397**System capability**: SystemCapability.Communication.IPC.Core
5398
5399**Parameters**
5400
5401  | Name| Type  | Mandatory| Description                    |
5402  | ------ | ------ | ---- | ------------------------ |
5403  | size   | number | Yes  | Size of the raw data to read.|
5404
5405**Return value**
5406
5407  | Type    | Description                          |
5408  | -------- | ------------------------------ |
5409  | number[] | Raw data obtained, in bytes.|
5410
5411**Example**
5412
5413  ```ts
5414  let parcel = new rpc.MessageParcel();
5415  let arr = [1, 2, 3, 4, 5];
5416  let isWriteSuccess = parcel.writeRawData(arr, arr.length);
5417  console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
5418  let result = parcel.readRawData(5);
5419  console.log("RpcTest: parcel read raw data result is : " + result);
5420  ```
5421
5422## Parcelable<sup>9+</sup>
5423
5424Writes an object to a **MessageSequence** and reads it from the **MessageSequence** during IPC.
5425
5426### marshalling
5427
5428marshalling(dataOut: MessageSequence): boolean
5429
5430Marshals this **Parcelable** object into a **MessageSequence** object.
5431
5432**System capability**: SystemCapability.Communication.IPC.Core
5433
5434**Parameters**
5435
5436  | Name | Type           | Mandatory| Description                                       |
5437  | ------- | --------------- | ---- | ------------------------------------------- |
5438  | dataOut | MessageSequence | Yes  | **MessageSequence** object to which the **Parcelable** object is to be marshaled.|
5439
5440**Return value**
5441
5442  | Type   | Description                                     |
5443  | ------- | ----------------------------------------- |
5444  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
5445**Example**
5446
5447  ```ts
5448  class MyParcelable {
5449      num: number;
5450      str: string;
5451      constructor(num, str) {
5452          this.num = num;
5453          this.str = str;
5454      }
5455      marshalling(messageSequence) {
5456          messageSequence.writeInt(this.num);
5457          messageSequence.writeString(this.str);
5458          return true;
5459      }
5460      unmarshalling(messageSequence) {
5461          this.num = messageSequence.readInt();
5462          this.str = messageSequence.readString();
5463          return true;
5464      }
5465  }
5466  let parcelable = new MyParcelable(1, "aaa");
5467  let data = rpc.MessageSequence.create();
5468  let result = data.writeParcelable(parcelable);
5469  console.log("RpcClient: writeParcelable is " + result);
5470  let ret = new MyParcelable(0, "");
5471  let result2 = data.readParcelable(ret);
5472  console.log("RpcClient: readParcelable is " + result2);
5473  ```
5474
5475### unmarshalling
5476
5477unmarshalling(dataIn: MessageSequence): boolean
5478
5479Unmarshals this **Parcelable** object from a **MessageSequence** object.
5480
5481**System capability**: SystemCapability.Communication.IPC.Core
5482
5483**Parameters**
5484
5485  | Name| Type           | Mandatory| Description                                           |
5486  | ------ | --------------- | ---- | ----------------------------------------------- |
5487  | dataIn | MessageSequence | Yes  | **MessageSequence** object from which the **Parcelable** object is to be unmarshaled.|
5488
5489**Return value**
5490
5491  | Type   | Description                                         |
5492  | ------- | --------------------------------------------- |
5493  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
5494
5495**Example**
5496
5497  ```ts
5498  class MyParcelable {
5499      num: number;
5500      str: string;
5501      constructor(num, str) {
5502          this.num = num;
5503          this.str = str;
5504      }
5505      marshalling(messageSequence) {
5506          messageSequence.writeInt(this.num);
5507          messageSequence.writeString(this.str);
5508          return true;
5509      }
5510      unmarshalling(messageSequence) {
5511          this.num = messageSequence.readInt();
5512          this.str = messageSequence.readString();
5513          return true;
5514      }
5515  }
5516  let parcelable = new MyParcelable(1, "aaa");
5517  let data = rpc.MessageSequence.create();
5518  let result = data.writeParcelable(parcelable);
5519  console.log("RpcClient: writeParcelable is " + result);
5520  let ret = new MyParcelable(0, "");
5521  let result2 = data.readParcelable(ret);
5522  console.log("RpcClient: readParcelable is " + result2);
5523  ```
5524
5525## Sequenceable<sup>(deprecated)</sup>
5526
5527>This class is no longer maintained since API version 9. You are advised to use the [Parcelable](#parcelable9).
5528
5529Writes objects of classes to a **MessageParcel** and reads them from the **MessageParcel** during IPC.
5530
5531### marshalling
5532
5533marshalling(dataOut: MessageParcel): boolean
5534
5535Marshals the sequenceable object into a **MessageParcel** object.
5536
5537**System capability**: SystemCapability.Communication.IPC.Core
5538
5539**Parameters**
5540
5541  | Name | Type                           | Mandatory| Description                                     |
5542  | ------- | ------------------------------- | ---- | ----------------------------------------- |
5543  | dataOut | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object to which the sequenceable object is to be marshaled.|
5544
5545**Return value**
5546
5547  | Type   | Description                                     |
5548  | ------- | ----------------------------------------- |
5549  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
5550**Example**
5551
5552  ```ts
5553  class MySequenceable {
5554      num: number;
5555      str: string;
5556      constructor(num, str) {
5557          this.num = num;
5558          this.str = str;
5559      }
5560      marshalling(messageParcel) {
5561          messageParcel.writeInt(this.num);
5562          messageParcel.writeString(this.str);
5563          return true;
5564      }
5565      unmarshalling(messageParcel) {
5566          this.num = messageParcel.readInt();
5567          this.str = messageParcel.readString();
5568          return true;
5569      }
5570  }
5571  let sequenceable = new MySequenceable(1, "aaa");
5572  let data = rpc.MessageParcel.create();
5573  let result = data.writeSequenceable(sequenceable);
5574  console.log("RpcClient: writeSequenceable is " + result);
5575  let ret = new MySequenceable(0, "");
5576  let result2 = data.readSequenceable(ret);
5577  console.log("RpcClient: readSequenceable is " + result2);
5578  ```
5579
5580### unmarshalling
5581
5582unmarshalling(dataIn: MessageParcel): boolean
5583
5584Unmarshals this sequenceable object from a **MessageParcel** object.
5585
5586**System capability**: SystemCapability.Communication.IPC.Core
5587
5588**Parameters**
5589
5590  | Name| Type                           | Mandatory| Description                                         |
5591  | ------ | ------------------------------- | ---- | --------------------------------------------- |
5592  | dataIn | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
5593
5594**Return value**
5595
5596  | Type   | Description                                         |
5597  | ------- | --------------------------------------------- |
5598  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
5599
5600**Example**
5601
5602  ```ts
5603  class MySequenceable {
5604      num: number;
5605      str: string;
5606      constructor(num, str) {
5607          this.num = num;
5608          this.str = str;
5609      }
5610      marshalling(messageParcel) {
5611          messageParcel.writeInt(this.num);
5612          messageParcel.writeString(this.str);
5613          return true;
5614      }
5615      unmarshalling(messageParcel) {
5616          this.num = messageParcel.readInt();
5617          this.str = messageParcel.readString();
5618          return true;
5619      }
5620  }
5621  let sequenceable = new MySequenceable(1, "aaa");
5622  let data = rpc.MessageParcel.create();
5623  let result = data.writeSequenceable(sequenceable);
5624  console.log("RpcClient: writeSequenceable is " + result);
5625  let ret = new MySequenceable(0, "");
5626  let result2 = data.readSequenceable(ret);
5627  console.log("RpcClient: readSequenceable is " + result2);
5628  ```
5629
5630## IRemoteBroker
5631
5632Provides the holder of a remote proxy object.
5633
5634### asObject
5635
5636asObject(): IRemoteObject
5637
5638Obtains a proxy or remote object. This API must be implemented by its derived classes.
5639
5640**System capability**: SystemCapability.Communication.IPC.Core
5641
5642**Return value**
5643
5644  | Type | Description|
5645  | ---- | ----- |
5646  | [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.|
5647
5648**Example**
5649
5650  ```ts
5651  class TestAbility extends rpc.RemoteObject {
5652      asObject() {
5653          return this;
5654      }
5655  }
5656  let remoteObject = new TestAbility("testObject").asObject();
5657  ```
5658
5659**Example**
5660
5661  Obtain the service.
5662
5663  ```ts
5664  import FA from "@ohos.ability.featureAbility";
5665  let proxy;
5666  let connect = {
5667      onConnect: function (elementName, remoteProxy) {
5668          console.log("RpcClient: js onConnect called.");
5669          proxy = remoteProxy;
5670      },
5671      onDisconnect: function (elementName) {
5672          console.log("RpcClient: onDisconnect");
5673      },
5674      onFailed: function () {
5675          console.log("RpcClient: onFailed");
5676      }
5677  };
5678  let want = {
5679      "bundleName": "com.ohos.server",
5680      "abilityName": "com.ohos.server.MainAbility",
5681  };
5682  FA.connectAbility(want, connect);
5683  ```
5684
5685  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.
5686
5687  ```ts
5688  class TestProxy {
5689      remote: rpc.RemoteObject;
5690      constructor(remote) {
5691          this.remote = remote;
5692      }
5693      asObject() {
5694          return this.remote;
5695      }
5696  }
5697  let iRemoteObject = new TestProxy(proxy).asObject();
5698
5699  ```
5700
5701## DeathRecipient
5702
5703Subscribes 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.
5704
5705### onRemoteDied
5706
5707onRemoteDied(): void
5708
5709Called to perform subsequent operations when a death notification of the remote object is received.
5710
5711**System capability**: SystemCapability.Communication.IPC.Core
5712
5713**Example**
5714
5715  ```ts
5716  class MyDeathRecipient {
5717      onRemoteDied() {
5718          console.log("server died");
5719      }
5720  }
5721  ```
5722
5723## RequestResult<sup>9+</sup>
5724
5725Defines the response to the request.
5726
5727**System capability**: SystemCapability.Communication.IPC.Core
5728
5729  | Name   | Type           | Readable| Writable| Description                                 |
5730  | ------- | --------------- | ---- | ---- |-------------------------------------- |
5731  | errCode | number          | Yes  | No  | Error Code                             |
5732  | code    | number          | Yes  | No  | Message code.                           |
5733  | data    | MessageSequence | Yes  | No  | **MessageSequence** object sent to the remote process.|
5734  | reply   | MessageSequence | Yes  | No  | **MessageSequence** object returned by the remote process.  |
5735
5736## SendRequestResult<sup>8+(deprecated)</sup>
5737
5738>This API is no longer maintained since API version 9. You are advised to use [RequestResult](#requestresult9).
5739
5740Defines the response to the request.
5741
5742**System capability**: SystemCapability.Communication.IPC.Core
5743
5744  | Name   | Type         | Readable| Writable| Description                               |
5745  | ------- | ------------- | ---- | ---- | ----------------------------------- |
5746  | errCode | number        | Yes  | No  | Error Code                           |
5747  | code    | number        | Yes  | No  | Message code.                         |
5748  | data    | MessageParcel | Yes  | No  | **MessageParcel** object sent to the remote process.|
5749  | reply   | MessageParcel | Yes  | No  | **MessageParcel** object returned by the remote process.  |
5750
5751## IRemoteObject
5752
5753Provides methods to query of obtain interface descriptors, add or delete death notifications, dump object status to specific files, and send messages.
5754
5755### getLocalInterface<sup>9+</sup>
5756
5757getLocalInterface(descriptor: string): IRemoteBroker
5758
5759Obtains the interface descriptor.
5760
5761**System capability**: SystemCapability.Communication.IPC.Core
5762
5763**Parameters**
5764
5765  | Name    | Type  | Mandatory| Description                |
5766  | ---------- | ------ | ---- | -------------------- |
5767  | descriptor | string | Yes  | Interface descriptor.|
5768
5769**Return value**
5770
5771  | Type         | Description                                         |
5772  | ------------- | --------------------------------------------- |
5773  | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
5774
5775### queryLocalInterface<sup>(deprecated)</sup>
5776
5777>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).
5778
5779queryLocalInterface(descriptor: string): IRemoteBroker
5780
5781Queries the interface descriptor.
5782
5783**System capability**: SystemCapability.Communication.IPC.Core
5784
5785**Parameters**
5786
5787  | Name    | Type  | Mandatory| Description                |
5788  | ---------- | ------ | ---- | -------------------- |
5789  | descriptor | string | Yes  | Interface descriptor.|
5790
5791**Return value**
5792
5793  | Type         | Description                                         |
5794  | ------------- | --------------------------------------------- |
5795  | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
5796
5797### sendRequest<sup>(deprecated)</sup>
5798
5799>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
5800
5801sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
5802
5803Sends 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.
5804
5805**System capability**: SystemCapability.Communication.IPC.Core
5806
5807**Parameters**
5808
5809  | Name | Type| Mandatory| Description |
5810  | ------- | ------------------------------- | ---- | ---- |
5811  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
5812  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
5813  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
5814  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
5815
5816**Return value**
5817
5818  | Type   | Description                                         |
5819  | ------- | --------------------------------------------- |
5820  | boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
5821
5822
5823### sendRequest<sup>8+(deprecated)</sup>
5824
5825>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
5826
5827sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
5828
5829Sends 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.
5830
5831**System capability**: SystemCapability.Communication.IPC.Core
5832
5833**Parameters**
5834
5835  | Name | Type                           | Mandatory| Description                                                                                  |
5836  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
5837  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
5838  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
5839  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
5840  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
5841
5842**Return value**
5843
5844  | Type                            | Description                                         |
5845  | -------------------------------- | --------------------------------------------- |
5846  | Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
5847
5848
5849### sendMessageRequest<sup>9+</sup>
5850
5851sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
5852
5853Sends 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.
5854
5855**System capability**: SystemCapability.Communication.IPC.Core
5856
5857**Parameters**
5858
5859  | Name | Type                           | Mandatory| Description                                                                                  |
5860  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
5861  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
5862  | data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
5863  | reply   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
5864  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
5865
5866**Return value**
5867
5868  | Type                        | Description                                     |
5869  | ---------------------------- | ----------------------------------------- |
5870  | Promise&lt;RequestResult&gt; | Promise used to return the **requestResult** object.|
5871
5872
5873### sendMessageRequest<sup>9+</sup>
5874
5875sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void
5876
5877Sends 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.
5878
5879**System capability**: SystemCapability.Communication.IPC.Core
5880
5881**Parameters**
5882
5883  | Name  | Type                              | Mandatory| Description                                                                                  |
5884  | -------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
5885  | code     | number                             | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
5886  | data     | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
5887  | reply    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
5888  | options  | [MessageOption](#messageoption)    | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
5889  | callback | AsyncCallback&lt;RequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |
5890
5891### sendRequest<sup>8+(deprecated)</sup>
5892
5893>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
5894
5895sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void
5896
5897Sends 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.
5898
5899**System capability**: SystemCapability.Communication.IPC.Core
5900
5901**Parameters**
5902
5903  | Name  | Type                                  | Mandatory| Description                                                                                  |
5904  | -------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
5905  | code     | number                                 | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
5906  | data     | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object holding the data to send.                                             |
5907  | reply    | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object that receives the response.                                                     |
5908  | options  | [MessageOption](#messageoption)        | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
5909  | callback | AsyncCallback&lt;SendRequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |
5910
5911### registerDeathRecipient<sup>9+</sup>
5912
5913registerDeathRecipient(recipient: DeathRecipient, flags: number): void
5914
5915Registers 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.
5916
5917**System capability**: SystemCapability.Communication.IPC.Core
5918
5919**Parameters**
5920
5921  | Name   | Type                             | Mandatory| Description          |
5922  | --------- | --------------------------------- | ---- | -------------- |
5923  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to register.|
5924  | flags     | number                            | Yes  | Flag of the death notification.|
5925
5926**Error codes**
5927
5928For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
5929
5930  | ID| Error Message|
5931  | ------- | -------- |
5932  | 1900008 | proxy or remote object is invalid |
5933
5934### addDeathrecipient<sup>(deprecated)</sup>
5935
5936>This API is no longer maintained since API version 9. You are advised to use [registerDeathRecipient](#registerdeathrecipient9).
5937
5938addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
5939
5940Adds 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.
5941
5942**System capability**: SystemCapability.Communication.IPC.Core
5943
5944**Parameters**
5945
5946  | Name   | Type                             | Mandatory| Description          |
5947  | --------- | --------------------------------- | ---- | -------------- |
5948  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.|
5949  | flags     | number                            | Yes  | Flag of the death notification.|
5950
5951**Return value**
5952
5953  | Type   | Description                                         |
5954  | ------- | --------------------------------------------- |
5955  | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
5956
5957
5958### unregisterDeathRecipient<sup>9+</sup>
5959
5960unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void
5961
5962Unregisters the callback used to receive death notifications of the remote object.
5963
5964**System capability**: SystemCapability.Communication.IPC.Core
5965
5966**Parameters**
5967
5968  | Name   | Type                             | Mandatory| Description          |
5969  | --------- | --------------------------------- | ---- | -------------- |
5970  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to unregister.|
5971  | flags     | number                            | Yes  | Flag of the death notification.|
5972
5973**Error codes**
5974
5975For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
5976
5977  | ID| Error Message|
5978  | ------- | -------- |
5979  | 1900008 | proxy or remote object is invalid |
5980
5981### removeDeathRecipient<sup>(deprecated)</sup>
5982
5983>This API is no longer maintained since API version 9. You are advised to use [unregisterDeathRecipient](#unregisterdeathrecipient9).
5984
5985removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
5986
5987Removes the callback used to receive death notifications of the remote object.
5988
5989**System capability**: SystemCapability.Communication.IPC.Core
5990
5991**Parameters**
5992
5993  | Name   | Type                             | Mandatory| Description          |
5994  | --------- | --------------------------------- | ---- | -------------- |
5995  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.|
5996  | flags     | number                            | Yes  | Flag of the death notification.|
5997
5998**Return value**
5999
6000  | Type   | Description                                         |
6001  | ------- | --------------------------------------------- |
6002  | boolean | Returns **true** if the callback is removed; returns **false** otherwise.|
6003
6004### getDescriptor<sup>9+</sup>
6005
6006getDescriptor(): string
6007
6008Obtains the interface descriptor (which is a string) of this object.
6009
6010**System capability**: SystemCapability.Communication.IPC.Core
6011
6012**Return value**
6013
6014  | Type  | Description            |
6015  | ------ | ---------------- |
6016  | string | Interface descriptor obtained.|
6017
6018**Error codes**
6019
6020For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
6021
6022  | ID| Error Message|
6023  | ------- | -------- |
6024  | 1900008 | proxy or remote object is invalid |
6025
6026
6027### getInterfaceDescriptor<sup>(deprecated)</sup>
6028
6029>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
6030
6031getInterfaceDescriptor(): string
6032
6033Obtains the interface descriptor (which is a string) of this object.
6034
6035**System capability**: SystemCapability.Communication.IPC.Core
6036
6037**Return value**
6038
6039  | Type  | Description            |
6040  | ------ | ---------------- |
6041  | string | Interface descriptor obtained.|
6042
6043
6044### isObjectDead
6045
6046isObjectDead(): boolean
6047
6048Checks whether this object is dead.
6049
6050**System capability**: SystemCapability.Communication.IPC.Core
6051
6052**Return value**
6053
6054  | Type   | Description                                       |
6055  | ------- | ------------------------------------------- |
6056  | boolean | Returns **true** if the object is dead; returns **false** otherwise.|
6057
6058
6059## RemoteProxy
6060
6061Provides APIs to implement **IRemoteObject**.
6062
6063**System capability**: SystemCapability.Communication.IPC.Core
6064
6065| Name                 | Value                     | Description                             |
6066| --------------------- | ----------------------- | --------------------------------- |
6067| PING_TRANSACTION      | 1599098439 (0x5f504e47) | Internal instruction code used to test whether the IPC service is normal.|
6068| DUMP_TRANSACTION      | 1598311760 (0x5f444d50) | Internal instruction code used to obtain the internal status of the binder. |
6069| INTERFACE_TRANSACTION | 1598968902 (0x5f4e5446) | Internal instruction code used to obtain the remote interface token. |
6070| MIN_TRANSACTION_ID    | 1 (0x00000001)          | Minimum valid instruction code.                 |
6071| MAX_TRANSACTION_ID    | 16777215 (0x00FFFFFF)   | Maximum valid instruction code.                 |
6072
6073### sendRequest<sup>(deprecated)</sup>
6074
6075>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
6076
6077sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
6078
6079Sends 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.
6080
6081**System capability**: SystemCapability.Communication.IPC.Core
6082
6083**Parameters**
6084
6085  | Name | Type                           | Mandatory| Description                                                                                  |
6086  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
6087  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6088  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
6089  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
6090  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6091
6092**Return value**
6093
6094  | Type   | Description                                         |
6095  | ------- | --------------------------------------------- |
6096  | boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
6097
6098**Example**
6099
6100  Obtain the service.
6101
6102  ```ts
6103  import FA from "@ohos.ability.featureAbility";
6104  let proxy;
6105  let connect = {
6106      onConnect: function(elementName, remoteProxy) {
6107          console.log("RpcClient: js onConnect called.");
6108          proxy = remoteProxy;
6109      },
6110      onDisconnect: function(elementName) {
6111          console.log("RpcClient: onDisconnect");
6112      },
6113      onFailed: function() {
6114          console.log("RpcClient: onFailed");
6115      }
6116  };
6117  let want = {
6118      "bundleName": "com.ohos.server",
6119      "abilityName": "com.ohos.server.MainAbility",
6120  };
6121  FA.connectAbility(want, connect);
6122  ```
6123
6124  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.
6125
6126  ```ts
6127  let option = new rpc.MessageOption();
6128  let data = rpc.MessageParcel.create();
6129  let reply = rpc.MessageParcel.create();
6130  data.writeInt(1);
6131  data.writeString("hello");
6132  let ret: boolean = proxy.sendRequest(1, data, reply, option);
6133  if (ret) {
6134      console.log("sendRequest got result");
6135      let msg = reply.readString();
6136      console.log("RPCTest: reply msg: " + msg);
6137  } else {
6138      console.log("RPCTest: sendRequest failed");
6139  }
6140  console.log("RPCTest: sendRequest ends, reclaim parcel");
6141  data.reclaim();
6142  reply.reclaim();
6143  ```
6144
6145### sendMessageRequest<sup>9+</sup>
6146
6147sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
6148
6149Sends 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.
6150
6151**System capability**: SystemCapability.Communication.IPC.Core
6152
6153**Parameters**
6154
6155  | Name | Type                           | Mandatory| Description                                                                                  |
6156  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
6157  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6158  | data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
6159  | reply   | [MessageSequence](#messagesequence9)  | Yes  | **MessageSequence** object that receives the response.                                                   |
6160  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6161
6162**Return value**
6163
6164  | Type                        | Description                                     |
6165  | ---------------------------- | ----------------------------------------- |
6166  | Promise&lt;RequestResult&gt; | Promise used to return the **requestResult** object.|
6167
6168**Example**
6169
6170  Obtain the service.
6171
6172  ```ts
6173  import FA from "@ohos.ability.featureAbility";
6174  let proxy;
6175  let connect = {
6176      onConnect: function(elementName, remoteProxy) {
6177          console.log("RpcClient: js onConnect called.");
6178          proxy = remoteProxy;
6179      },
6180      onDisconnect: function(elementName) {
6181          console.log("RpcClient: onDisconnect");
6182      },
6183      onFailed: function() {
6184          console.log("RpcClient: onFailed");
6185      }
6186  };
6187  let want = {
6188      "bundleName": "com.ohos.server",
6189      "abilityName": "com.ohos.server.MainAbility",
6190  };
6191  FA.connectAbility(want, connect);
6192  ```
6193
6194  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.
6195
6196  ```ts
6197  let option = new rpc.MessageOption();
6198  let data = rpc.MessageSequence.create();
6199  let reply = rpc.MessageSequence.create();
6200  data.writeInt(1);
6201  data.writeString("hello");
6202  proxy.sendMessageRequest(1, data, reply, option)
6203      .then(function(result) {
6204          if (result.errCode === 0) {
6205              console.log("sendMessageRequest got result");
6206              result.reply.readException();
6207              let msg = result.reply.readString();
6208              console.log("RPCTest: reply msg: " + msg);
6209          } else {
6210              console.log("RPCTest: sendMessageRequest failed, errCode: " + result.errCode);
6211          }
6212      }).catch(function(e) {
6213          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
6214      }).finally (() => {
6215          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
6216          data.reclaim();
6217          reply.reclaim();
6218      });
6219  ```
6220
6221### sendRequest<sup>8+(deprecated)</sup>
6222
6223>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
6224
6225sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
6226
6227Sends 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.
6228
6229**System capability**: SystemCapability.Communication.IPC.Core
6230
6231**Parameters**
6232
6233  | Name | Type                           | Mandatory| Description                                                                                  |
6234  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
6235  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6236  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
6237  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
6238  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6239
6240**Return value**
6241
6242  | Type                            | Description                                         |
6243  | -------------------------------- | --------------------------------------------- |
6244  | Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
6245
6246**Example**
6247
6248  Obtain the service.
6249
6250  ```ts
6251  import FA from "@ohos.ability.featureAbility";
6252  let proxy;
6253  let connect = {
6254      onConnect: function(elementName, remoteProxy) {
6255          console.log("RpcClient: js onConnect called.");
6256          proxy = remoteProxy;
6257      },
6258      onDisconnect: function(elementName) {
6259          console.log("RpcClient: onDisconnect");
6260      },
6261      onFailed: function() {
6262          console.log("RpcClient: onFailed");
6263      }
6264  };
6265  let want = {
6266      "bundleName": "com.ohos.server",
6267      "abilityName": "com.ohos.server.MainAbility",
6268  };
6269  FA.connectAbility(want, connect);
6270  ```
6271
6272  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.
6273
6274  ```ts
6275  let option = new rpc.MessageOption();
6276  let data = rpc.MessageParcel.create();
6277  let reply = rpc.MessageParcel.create();
6278  data.writeInt(1);
6279  data.writeString("hello");
6280  proxy.sendRequest(1, data, reply, option)
6281      .then(function(result) {
6282          if (result.errCode === 0) {
6283              console.log("sendRequest got result");
6284              result.reply.readException();
6285              let msg = result.reply.readString();
6286              console.log("RPCTest: reply msg: " + msg);
6287          } else {
6288              console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
6289          }
6290      }).catch(function(e) {
6291          console.log("RPCTest: sendRequest got exception: " + e.message);
6292      }).finally (() => {
6293          console.log("RPCTest: sendRequest ends, reclaim parcel");
6294          data.reclaim();
6295          reply.reclaim();
6296      });
6297  ```
6298
6299### sendMessageRequest<sup>9+</sup>
6300
6301sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void
6302
6303Sends 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.
6304
6305**System capability**: SystemCapability.Communication.IPC.Core
6306
6307**Parameters**
6308
6309  | Name  | Type                              | Mandatory| Description                                                                                  |
6310  | -------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
6311  | code     | number                             | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6312  | data     | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
6313  | reply    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
6314  | options  | [MessageOption](#messageoption)    | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6315  | callback | AsyncCallback&lt;RequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |
6316
6317**Example**
6318
6319  Obtain the service.
6320
6321  ```ts
6322  import FA from "@ohos.ability.featureAbility";
6323  let proxy;
6324  let connect = {
6325      onConnect: function(elementName, remoteProxy) {
6326          console.log("RpcClient: js onConnect called.");
6327          proxy = remoteProxy;
6328      },
6329      onDisconnect: function(elementName) {
6330          console.log("RpcClient: onDisconnect");
6331      },
6332      onFailed: function() {
6333          console.log("RpcClient: onFailed");
6334      }
6335  };
6336  let want = {
6337      "bundleName": "com.ohos.server",
6338      "abilityName": "com.ohos.server.MainAbility",
6339  };
6340  function sendRequestCallback(result) {
6341      if (result.errCode === 0) {
6342          console.log("sendRequest got result");
6343          result.reply.readException();
6344          let msg = result.reply.readString();
6345          console.log("RPCTest: reply msg: " + msg);
6346      } else {
6347          console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
6348      }
6349      console.log("RPCTest: sendRequest ends, reclaim parcel");
6350      result.data.reclaim();
6351      result.reply.reclaim();
6352  }
6353  FA.connectAbility(want, connect);
6354  ```
6355
6356  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.
6357
6358  ```ts
6359  let option = new rpc.MessageOption();
6360  let data = rpc.MessageSequence.create();
6361  let reply = rpc.MessageSequence.create();
6362  data.writeInt(1);
6363  data.writeString("hello");
6364  try {
6365      proxy.sendRequest(1, data, reply, option, sendRequestCallback);
6366  } catch(error) {
6367      console.info("rpc send sequence request fail, errorCode " + error.code);
6368      console.info("rpc send sequence request fail, errorMessage " + error.message);
6369  }
6370  ```
6371
6372### sendRequest<sup>8+(deprecated)</sup>
6373
6374>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
6375
6376sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void
6377
6378Sends 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.
6379
6380**System capability**: SystemCapability.Communication.IPC.Core
6381
6382**Parameters**
6383
6384  | Name  | Type                                  | Mandatory| Description                                                                                  |
6385  | -------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
6386  | code     | number                                 | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
6387  | data     | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object holding the data to send.                                             |
6388  | reply    | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object that receives the response.                                                     |
6389  | options  | [MessageOption](#messageoption)        | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
6390  | callback | AsyncCallback&lt;SendRequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |
6391
6392**Example**
6393
6394  Obtain the service.
6395
6396  ```ts
6397  import FA from "@ohos.ability.featureAbility";
6398  let proxy;
6399  let connect = {
6400      onConnect: function(elementName, remoteProxy) {
6401          console.log("RpcClient: js onConnect called.");
6402          proxy = remoteProxy;
6403      },
6404      onDisconnect: function(elementName) {
6405          console.log("RpcClient: onDisconnect");
6406      },
6407      onFailed: function() {
6408          console.log("RpcClient: onFailed");
6409      }
6410  };
6411  let want = {
6412      "bundleName": "com.ohos.server",
6413      "abilityName": "com.ohos.server.MainAbility",
6414  };
6415  function sendRequestCallback(result) {
6416      if (result.errCode === 0) {
6417          console.log("sendRequest got result");
6418          result.reply.readException();
6419          let msg = result.reply.readString();
6420          console.log("RPCTest: reply msg: " + msg);
6421      } else {
6422          console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
6423      }
6424      console.log("RPCTest: sendRequest ends, reclaim parcel");
6425      result.data.reclaim();
6426      result.reply.reclaim();
6427  }
6428  FA.connectAbility(want, connect);
6429  ```
6430
6431  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.
6432
6433  ```ts
6434  let option = new rpc.MessageOption();
6435  let data = rpc.MessageParcel.create();
6436  let reply = rpc.MessageParcel.create();
6437  data.writeInt(1);
6438  data.writeString("hello");
6439  proxy.sendRequest(1, data, reply, option, sendRequestCallback);
6440  ```
6441
6442### getLocalInterface<sup>9+</sup>
6443
6444getLocalInterface(interface: string): IRemoteBroker
6445
6446Obtains the **LocalInterface** object of an interface token.
6447
6448**System capability**: SystemCapability.Communication.IPC.Core
6449
6450**Parameters**
6451
6452  | Name   | Type  | Mandatory| Description                  |
6453  | --------- | ------ | ---- | ---------------------- |
6454  | interface | string | Yes  | Interface descriptor.|
6455
6456**Return value**
6457
6458  | Type         | Description                                      |
6459  | ------------- | ------------------------------------------ |
6460  | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
6461
6462**Error codes**
6463
6464For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
6465
6466  | ID| Error Message|
6467  | ------- | --------  |
6468  | 1900006 | only remote object permitted |
6469
6470**Example**
6471
6472  Obtain the service.
6473
6474  ```ts
6475  import FA from "@ohos.ability.featureAbility";
6476  let proxy;
6477  let connect = {
6478      onConnect: function(elementName, remoteProxy) {
6479          console.log("RpcClient: js onConnect called.");
6480          proxy = remoteProxy;
6481      },
6482      onDisconnect: function (elementName) {
6483          console.log("RpcClient: onDisconnect");
6484      },
6485      onFailed: function() {
6486          console.log("RpcClient: onFailed");
6487      }
6488  };
6489  let want = {
6490      "bundleName":"com.ohos.server",
6491      "abilityName":"com.ohos.server.MainAbility",
6492  };
6493  FA.connectAbility(want, connect);
6494  ```
6495
6496  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.
6497
6498  ```ts
6499  try {
6500      let broker = proxy.getLocalInterface("testObject");
6501      console.log("RpcClient: getLocalInterface is " + broker);
6502  } catch(error) {
6503      console.info("rpc get local interface fail, errorCode " + error.code);
6504      console.info("rpc get local interface fail, errorMessage " + error.message);
6505  }
6506  ```
6507
6508### queryLocalInterface<sup>(deprecated)</sup>
6509
6510>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).
6511
6512queryLocalInterface(interface: string): IRemoteBroker
6513
6514Obtains the **LocalInterface** object of an interface token.
6515
6516**System capability**: SystemCapability.Communication.IPC.Core
6517
6518**Parameters**
6519
6520  | Name   | Type  | Mandatory| Description                  |
6521  | --------- | ------ | ---- | ---------------------- |
6522  | interface | string | Yes  | Interface descriptor.|
6523
6524**Return value**
6525
6526  | Type         | Description                                      |
6527  | ------------- | ------------------------------------------ |
6528  | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
6529
6530**Example**
6531
6532  Obtain the service.
6533
6534  ```ts
6535  import FA from "@ohos.ability.featureAbility";
6536  let proxy;
6537  let connect = {
6538      onConnect: function(elementName, remoteProxy) {
6539          console.log("RpcClient: js onConnect called.");
6540          proxy = remoteProxy;
6541      },
6542      onDisconnect: function (elementName) {
6543          console.log("RpcClient: onDisconnect");
6544      },
6545      onFailed: function() {
6546          console.log("RpcClient: onFailed");
6547      }
6548  };
6549  let want = {
6550      "bundleName":"com.ohos.server",
6551      "abilityName":"com.ohos.server.MainAbility",
6552  };
6553  FA.connectAbility(want, connect);
6554  ```
6555
6556  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.
6557
6558  ```ts
6559  let broker = proxy.queryLocalInterface("testObject");
6560  console.log("RpcClient: queryLocalInterface is " + broker);
6561  ```
6562
6563### registerDeathRecipient<sup>9+</sup>
6564
6565registerDeathRecipient(recipient: DeathRecipient, flags: number): void
6566
6567Registers 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.
6568
6569**System capability**: SystemCapability.Communication.IPC.Core
6570
6571**Parameters**
6572
6573  | Name   | Type                             | Mandatory| Description          |
6574  | --------- | --------------------------------- | ---- | -------------- |
6575  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to register.|
6576  | flags     | number                            | Yes  | Flag of the death notification.|
6577
6578**Error codes**
6579
6580For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
6581
6582  | ID| Error Message|
6583  | ------- | -------- |
6584  | 1900008 | proxy or remote object is invalid |
6585
6586**Example**
6587
6588  Obtain the service.
6589
6590  ```ts
6591  import FA from "@ohos.ability.featureAbility";
6592  let proxy;
6593  let connect = {
6594      onConnect: function(elementName, remoteProxy) {
6595          console.log("RpcClient: js onConnect called.");
6596          proxy = remoteProxy;
6597      },
6598      onDisconnect: function(elementName) {
6599          console.log("RpcClient: onDisconnect");
6600      },
6601      onFailed: function() {
6602          console.log("RpcClient: onFailed");
6603      }
6604  };
6605  let want = {
6606      "bundleName": "com.ohos.server",
6607      "abilityName": "com.ohos.server.MainAbility",
6608  };
6609  FA.connectAbility(want, connect);
6610  ```
6611
6612  The 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.
6613
6614  ```ts
6615  class MyDeathRecipient {
6616      onRemoteDied() {
6617          console.log("server died");
6618      }
6619  }
6620  let deathRecipient = new MyDeathRecipient();
6621  try {
6622      proxy.registerDeathRecipient(deathRecipient, 0);
6623  } catch(error) {
6624      console.info("proxy register deathRecipient fail, errorCode " + error.code);
6625      console.info("proxy register deathRecipient fail, errorMessage " + error.message);
6626  }
6627  ```
6628
6629### addDeathRecippient<sup>(deprecated)</sup>
6630
6631>This API is no longer maintained since API version 9. You are advised to use [registerDeathRecipient](#registerdeathrecipient9).
6632
6633addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
6634
6635Adds a callback for receiving the death notifications of the remote object, including the death notifications of the remote proxy.
6636
6637**System capability**: SystemCapability.Communication.IPC.Core
6638
6639**Parameters**
6640
6641  | Name   | Type                             | Mandatory| Description                             |
6642  | --------- | --------------------------------- | ---- | --------------------------------- |
6643  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.         |
6644  | flags     | number                            | Yes  | Flag of the death notification. This parameter is reserved. It is set to **0**.|
6645
6646**Return value**
6647
6648  | Type   | Description                                         |
6649  | ------- | --------------------------------------------- |
6650  | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
6651
6652**Example**
6653
6654  Obtain the service.
6655
6656  ```ts
6657  import FA from "@ohos.ability.featureAbility";
6658  let proxy;
6659  let connect = {
6660      onConnect: function(elementName, remoteProxy) {
6661          console.log("RpcClient: js onConnect called.");
6662          proxy = remoteProxy;
6663      },
6664      onDisconnect: function(elementName) {
6665          console.log("RpcClient: onDisconnect");
6666      },
6667      onFailed: function() {
6668          console.log("RpcClient: onFailed");
6669      }
6670  };
6671  let want = {
6672      "bundleName": "com.ohos.server",
6673      "abilityName": "com.ohos.server.MainAbility",
6674  };
6675  FA.connectAbility(want, connect);
6676  ```
6677
6678  The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **addDeathRecippient()** of the proxy object is called to add a callback for receiving the death notification of the remove object.
6679
6680  ```ts
6681  class MyDeathRecipient {
6682      onRemoteDied() {
6683          console.log("server died");
6684      }
6685  }
6686  let deathRecipient = new MyDeathRecipient();
6687  proxy.addDeathRecipient(deathRecipient, 0);
6688  ```
6689
6690### unregisterDeathRecipient<sup>9+</sup>
6691
6692unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void
6693
6694Unregisters the callback used to receive death notifications of the remote object.
6695
6696**System capability**: SystemCapability.Communication.IPC.Core
6697
6698**Parameters**
6699
6700  | Name   | Type                             | Mandatory| Description          |
6701  | --------- | --------------------------------- | ---- | -------------- |
6702  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to unregister.|
6703  | flags     | number                            | Yes  | Flag of the death notification.|
6704
6705**Error codes**
6706
6707For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
6708
6709  | ID| Error Message|
6710  | ------- | -------- |
6711  | 1900008 | proxy or remote object is invalid |
6712
6713**Example**
6714
6715  Obtain the service.
6716
6717  ```ts
6718  import FA from "@ohos.ability.featureAbility";
6719  let proxy;
6720  let connect = {
6721      onConnect: function(elementName, remoteProxy) {
6722          console.log("RpcClient: js onConnect called.");
6723          proxy = remoteProxy;
6724      },
6725      onDisconnect: function(elementName) {
6726          console.log("RpcClient: onDisconnect");
6727      },
6728      onFailed: function() {
6729          console.log("RpcClient: onFailed");
6730      }
6731  };
6732  let want = {
6733      "bundleName": "com.ohos.server",
6734      "abilityName": "com.ohos.server.MainAbility",
6735  };
6736  FA.connectAbility(want, connect);
6737  ```
6738
6739  The 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.
6740
6741  ```ts
6742  class MyDeathRecipient {
6743      onRemoteDied() {
6744          console.log("server died");
6745      }
6746  }
6747  let deathRecipient = new MyDeathRecipient();
6748  try {
6749      proxy.registerDeathRecippient(deathRecipient, 0);
6750      proxy.unregisterDeathRecippient(deathRecipient, 0);
6751  } catch(error) {
6752      console.info("proxy register deathRecipient fail, errorCode " + error.code);
6753      console.info("proxy register deathRecipient fail, errorMessage " + error.message);
6754  }
6755  ```
6756
6757### removeDeathRecipient<sup>(deprecated)</sup>
6758
6759>This API is no longer maintained since API version 9. You are advised to use [unregisterDeathRecipient](#unregisterdeathrecipient9).
6760
6761removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
6762
6763Removes the callback used to receive death notifications of the remote object.
6764
6765**System capability**: SystemCapability.Communication.IPC.Core
6766
6767**Parameters**
6768
6769  | Name   | Type                             | Mandatory| Description                             |
6770  | --------- | --------------------------------- | ---- | --------------------------------- |
6771  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.               |
6772  | flags     | number                            | Yes  | Flag of the death notification. This parameter is reserved. It is set to **0**.|
6773
6774**Return value**
6775
6776  | Type   | Description                                         |
6777  | ------- | --------------------------------------------- |
6778  | boolean | Returns **true** if the callback is removed; returns **false** otherwise.|
6779
6780**Example**
6781
6782  Obtain the service.
6783
6784  ```ts
6785  import FA from "@ohos.ability.featureAbility";
6786  let proxy;
6787  let connect = {
6788      onConnect: function(elementName, remoteProxy) {
6789          console.log("RpcClient: js onConnect called.");
6790          proxy = remoteProxy;
6791      },
6792      onDisconnect: function(elementName) {
6793          console.log("RpcClient: onDisconnect");
6794      },
6795      onFailed: function() {
6796          console.log("RpcClient: onFailed");
6797      }
6798  };
6799  let want = {
6800      "bundleName": "com.ohos.server",
6801      "abilityName": "com.ohos.server.MainAbility",
6802  };
6803  FA.connectAbility(want, connect);
6804  ```
6805
6806  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.
6807
6808  ```ts
6809  class MyDeathRecipient {
6810      onRemoteDied() {
6811          console.log("server died");
6812      }
6813  }
6814  let deathRecipient = new MyDeathRecipient();
6815  proxy.addDeathRecippient(deathRecipient, 0);
6816  proxy.removeDeathRecipient(deathRecipient, 0);
6817  ```
6818
6819### getDescriptor<sup>9+</sup>
6820
6821getDescriptor(): string
6822
6823Obtains the interface descriptor (which is a string) of this proxy object.
6824
6825**System capability**: SystemCapability.Communication.IPC.Core
6826
6827**Return value**
6828
6829  | Type  | Description            |
6830  | ------ | ---------------- |
6831  | string | Interface descriptor obtained.|
6832
6833**Error codes**
6834
6835For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
6836
6837  | ID| Error Message|
6838  | -------- | ------- |
6839  | 1900008 | proxy or remote object is invalid |
6840  | 1900007 | communication failed              |
6841
6842**Example**
6843
6844  Obtain the service.
6845
6846  ```ts
6847  import FA from "@ohos.ability.featureAbility";
6848  let proxy;
6849  let connect = {
6850      onConnect: function(elementName, remoteProxy) {
6851          console.log("RpcClient: js onConnect called.");
6852          proxy = remoteProxy;
6853      },
6854      onDisconnect: function(elementName) {
6855          console.log("RpcClient: onDisconnect");
6856      },
6857      onFailed: function() {
6858          console.log("RpcClient: onFailed");
6859      }
6860  };
6861  let want = {
6862      "bundleName": "com.ohos.server",
6863      "abilityName": "com.ohos.server.MainAbility",
6864  };
6865  FA.connectAbility(want, connect);
6866  ```
6867  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.
6868
6869  ```ts
6870  try {
6871      let descriptor = proxy.getDescriptor();
6872      console.log("RpcClient: descriptor is " + descriptor);
6873  } catch(error) {
6874      console.info("rpc get interface descriptor fail, errorCode " + error.code);
6875      console.info("rpc get interface descriptor fail, errorMessage " + error.message);
6876  }
6877  ```
6878
6879### getInterfaceDescriptor<sup>(deprecated)</sup>
6880
6881>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
6882
6883getInterfaceDescriptor(): string
6884
6885Obtains the interface descriptor of this proxy object.
6886
6887**System capability**: SystemCapability.Communication.IPC.Core
6888
6889**Return value**
6890
6891  | Type  | Description              |
6892  | ------ | ------------------ |
6893  | string | Interface descriptor obtained.|
6894
6895**Example**
6896
6897  Obtain the service.
6898
6899  ```ts
6900  import FA from "@ohos.ability.featureAbility";
6901  let proxy;
6902  let connect = {
6903      onConnect: function(elementName, remoteProxy) {
6904          console.log("RpcClient: js onConnect called.");
6905          proxy = remoteProxy;
6906      },
6907      onDisconnect: function(elementName) {
6908          console.log("RpcClient: onDisconnect");
6909      },
6910      onFailed: function() {
6911          console.log("RpcClient: onFailed");
6912      }
6913  };
6914  let want = {
6915      "bundleName": "com.ohos.server",
6916      "abilityName": "com.ohos.server.MainAbility",
6917  };
6918  FA.connectAbility(want, connect);
6919    ```
6920
6921The 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.
6922
6923  ```ts
6924  let descriptor = proxy.getInterfaceDescriptor();
6925  console.log("RpcClient: descriptor is " + descriptor);
6926  ```
6927
6928### isObjectDead
6929
6930isObjectDead(): boolean
6931
6932Checks whether the **RemoteObject** is dead.
6933
6934**System capability**: SystemCapability.Communication.IPC.Core
6935
6936**Return value**
6937
6938  | Type   | Description                                                     |
6939  | ------- | --------------------------------------------------------- |
6940  | boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.|
6941
6942**Example**
6943
6944  Obtain the service.
6945
6946  ```ts
6947  import FA from "@ohos.ability.featureAbility";
6948  let proxy;
6949  let connect = {
6950      onConnect: function(elementName, remoteProxy) {
6951          console.log("RpcClient: js onConnect called.");
6952          proxy = remoteProxy;
6953      },
6954      onDisconnect: function(elementName) {
6955          console.log("RpcClient: onDisconnect");
6956      },
6957      onFailed: function() {
6958          console.log("RpcClient: onFailed");
6959      }
6960  };
6961  let want = {
6962      "bundleName": "com.ohos.server",
6963      "abilityName": "com.ohos.server.MainAbility",
6964  };
6965  FA.connectAbility(want, connect);
6966  ```
6967
6968  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.
6969
6970  ```ts
6971  let isDead = proxy.isObjectDead();
6972  console.log("RpcClient: isObjectDead is " + isDead);
6973  ```
6974
6975## MessageOption
6976
6977Provides common message options (flag and wait time). Use the specified flag to construct the **MessageOption** object.
6978
6979**System capability**: SystemCapability.Communication.IPC.Core
6980
6981  | Name         | Value  | Description                                                       |
6982  | ------------- | ---- | ----------------------------------------------------------- |
6983  | TF_SYNC       | 0    | Synchronous call.                                                 |
6984  | TF_ASYNC      | 1    | Asynchronous call.                                                 |
6985  | TF_ACCEPT_FDS | 0x10 | Indication to **sendMessageRequest<sup>9+</sup>** for returning the file descriptor.|
6986  | TF_WAIT_TIME  | 8    | Default waiting time, in seconds.                                         |
6987
6988
6989### constructor<sup>9+</sup>
6990
6991constructor(async?: boolean);
6992
6993A constructor used to create a **MessageOption** object.
6994
6995**System capability**: SystemCapability.Communication.IPC.Core
6996
6997**Parameters**
6998
6999  | Name   | Type  | Mandatory| Description                                  |
7000  | --------- | ------ | ---- | -------------------------------------- |
7001  | syncFlags | number | No  | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.|
7002
7003
7004**Example**
7005
7006  ```ts
7007  class TestRemoteObject extends rpc.MessageOption {
7008    constructor(async) {
7009        super(async);
7010    }
7011  }
7012  ```
7013
7014### constructor
7015
7016constructor(syncFlags?: number, waitTime?: number)
7017
7018A constructor used to create a **MessageOption** object.
7019
7020**System capability**: SystemCapability.Communication.IPC.Core
7021
7022**Parameters**
7023
7024  | Name   | Type  | Mandatory| Description                                         |
7025  | --------- | ------ | ---- | --------------------------------------------- |
7026  | syncFlags | number | No  | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.       |
7027  | waitTime  | number | No  | Maximum wait time for an RPC call. The default value is **TF_WAIT_TIME**.|
7028
7029**Example**
7030
7031  ```ts
7032  class TestRemoteObject extends rpc.MessageOption {
7033    constructor(syncFlags,waitTime) {
7034        super(syncFlags,waitTime);
7035    }
7036  }
7037  ```
7038### isAsync<sup>9+</sup>
7039
7040isAsync(): boolean;
7041
7042Checks whether **SendMessageRequest** is called synchronously or asynchronously.
7043
7044**System capability**: SystemCapability.Communication.IPC.Core
7045
7046**Return value**
7047
7048  | Type   | Description                                |
7049  | ------- | ------------------------------------ |
7050  | boolean | Returns **true** if **SendMessageRequest** is called synchronously; returns **false** if **SendMessageRequest** is called asynchronously.|
7051
7052**Example**
7053
7054  ```ts
7055  let option = new rpc.MessageOption();
7056  let isAsync = option.isAsync();
7057  ```
7058
7059### setAsync<sup>9+</sup>
7060
7061setAsync(async: boolean): void;
7062
7063Sets whether **SendMessageRequest** is called synchronously or asynchronously.
7064
7065**System capability**: SystemCapability.Communication.IPC.Core
7066
7067**Example**
7068
7069  ```ts
7070  let option = new rpc.MessageOption();
7071  let setAsync = option.setAsync(true);
7072  console.log("Set synchronization flag");
7073  ```
7074
7075### getFlags
7076
7077getFlags(): number
7078
7079Obtains the call flag, which can be synchronous or asynchronous.
7080
7081**System capability**: SystemCapability.Communication.IPC.Core
7082
7083**Return value**
7084
7085  | Type  | Description                                |
7086  | ------ | ------------------------------------ |
7087  | number | Call mode obtained.|
7088
7089**Example**
7090
7091  ```ts
7092  try {
7093      let option = new rpc.MessageOption();
7094      console.info("create object successfully.");
7095      let flog = option.getFlags();
7096      console.info("run getFlags success, flog is " + flog);
7097      option.setFlags(1)
7098      console.info("run setFlags success");
7099      let flog2 = option.getFlags();
7100      console.info("run getFlags success, flog2 is " + flog2);
7101  } catch (error) {
7102      console.info("error " + error);
7103  }
7104  ```
7105
7106### setFlags
7107
7108setFlags(flags: number): void
7109
7110Sets the call flag, which can be synchronous or asynchronous.
7111
7112**System capability**: SystemCapability.Communication.IPC.Core
7113
7114**Parameters**
7115
7116  | Name| Type  | Mandatory| Description                    |
7117  | ------ | ------ | ---- | ------------------------ |
7118  | flags  | number | Yes  | Call flag to set.|
7119
7120**Example**
7121
7122  ```ts
7123  try {
7124      let option = new rpc.MessageOption();
7125      option.setFlags(1)
7126      console.info("run setFlags success");
7127      let flog = option.getFlags();
7128      console.info("run getFlags success, flog is " + flog);
7129  } catch (error) {
7130      console.info("error " + error);
7131  }
7132  ```
7133
7134### getWaitTime
7135
7136getWaitTime(): number
7137
7138Obtains the maximum wait time for this RPC call.
7139
7140**System capability**: SystemCapability.Communication.IPC.Core
7141
7142**Return value**
7143
7144  | Type  | Description             |
7145  | ------ | ----------------- |
7146  | number | Maximum wait time obtained.|
7147
7148**Example**
7149
7150  ```ts
7151  try {
7152      let option = new rpc.MessageOption();
7153      let time = option.getWaitTime();
7154      console.info("run getWaitTime success");
7155      option.setWaitTime(16);
7156      let time2 = option.getWaitTime();
7157      console.info("run getWaitTime success, time is " + time);
7158  } catch (error) {
7159      console.info("error " + error);
7160  }
7161  ```
7162
7163### setWaitTime
7164
7165setWaitTime(waitTime: number): void
7166
7167Sets the maximum wait time for this RPC call.
7168
7169**System capability**: SystemCapability.Communication.IPC.Core
7170
7171**Parameters**
7172
7173  | Name  | Type  | Mandatory| Description                 |
7174  | -------- | ------ | ---- | --------------------- |
7175  | waitTime | number | Yes  | Maximum wait time to set.|
7176
7177**Example**
7178
7179  ```ts
7180  try {
7181      let option = new rpc.MessageOption();
7182      option.setWaitTime(16);
7183      let time = option.getWaitTime();
7184      console.info("run getWaitTime success, time is " + time);
7185  } catch (error) {
7186      console.info("error " + error);
7187  }
7188  ```
7189
7190## IPCSkeleton
7191
7192Obtains IPC context information, including the UID and PID, local and remote device IDs, and whether the method is invoked on the same device.
7193
7194### getContextObject
7195
7196static getContextObject(): IRemoteObject
7197
7198Obtains the system capability manager. This API is a static method.
7199
7200**System capability**: SystemCapability.Communication.IPC.Core
7201
7202**Return value**
7203
7204  | Type                           | Description                |
7205  | ------------------------------- | -------------------- |
7206  | [IRemoteObject](#iremoteobject) | System capability manager obtained.|
7207
7208**Example**
7209
7210  ```ts
7211  let samgr = rpc.IPCSkeleton.getContextObject();
7212  console.log("RpcServer: getContextObject result: " + samgr);
7213  ```
7214
7215### getCallingPid
7216
7217static getCallingPid(): number
7218
7219Obtains 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.
7220
7221**System capability**: SystemCapability.Communication.IPC.Core
7222
7223**Return value**
7224
7225  | Type  | Description             |
7226  | ------ | ----------------- |
7227  | number | PID of the caller.|
7228
7229**Example**
7230
7231  ```ts
7232  class Stub extends rpc.RemoteObject {
7233      onRemoteMessageRequest(code, data, reply, option) {
7234          let callerPid = rpc.IPCSkeleton.getCallingPid();
7235          console.log("RpcServer: getCallingPid result: " + callerPid);
7236          return true;
7237      }
7238 }
7239  ```
7240
7241### getCallingUid
7242
7243static getCallingUid(): number
7244
7245Obtains 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.
7246
7247**System capability**: SystemCapability.Communication.IPC.Core
7248
7249**Return value**
7250
7251  | Type  | Description             |
7252  | ------ | ----------------- |
7253  | number | UID of the caller.|
7254
7255**Example**
7256
7257  ```ts
7258  class Stub extends rpc.RemoteObject {
7259      onRemoteMessageRequest(code, data, reply, option) {
7260          let callerUid = rpc.IPCSkeleton.getCallingUid();
7261          console.log("RpcServer: getCallingUid result: " + callerUid);
7262          return true;
7263      }
7264  }
7265  ```
7266
7267### getCallingTokenId<sup>8+</sup>
7268
7269static getCallingTokenId(): number;
7270
7271Obtains the caller's token ID, which is used to verify the caller identity.
7272
7273**System capability**: SystemCapability.Communication.IPC.Core
7274
7275**Return value**
7276
7277   | Type  | Description                 |
7278   | ------ | --------------------- |
7279   | number | Token ID of the caller obtained.|
7280
7281**Example**
7282
7283  ```ts
7284  class Stub extends rpc.RemoteObject {
7285      onRemoteMessageRequest(code, data, reply, option) {
7286          let callerTokenId = rpc.IPCSkeleton.getCallingTokenId();
7287          console.log("RpcServer: getCallingTokenId result: " + callerTokenId);
7288          return true;
7289      }
7290  }
7291  ```
7292
7293
7294### getCallingDeviceID
7295
7296static getCallingDeviceID(): string
7297
7298Obtains the ID of the device hosting the caller's process. This API is a static method.
7299
7300**System capability**: SystemCapability.Communication.IPC.Core
7301
7302**Return value**
7303
7304  | Type  | Description                        |
7305  | ------ | ---------------------------- |
7306  | string | Device ID obtained.|
7307
7308**Example**
7309
7310  ```ts
7311  class Stub extends rpc.RemoteObject {
7312      onRemoteMessageRequest(code, data, reply, option) {
7313          let callerDeviceID = rpc.IPCSkeleton.getCallingDeviceID();
7314          console.log("RpcServer: callerDeviceID is: " + callerDeviceID);
7315          return true;
7316      }
7317  }
7318  ```
7319
7320### getLocalDeviceID
7321
7322static getLocalDeviceID(): string
7323
7324Obtains the local device ID. This API is a static method.
7325
7326**System capability**: SystemCapability.Communication.IPC.Core
7327
7328**Return value**
7329
7330  | Type  | Description              |
7331  | ------ | ------------------ |
7332  | string | Local device ID obtained.|
7333
7334**Example**
7335
7336  ```ts
7337  class Stub extends rpc.RemoteObject {
7338      onRemoteMessageRequest(code, data, reply, option) {
7339          let localDeviceID = rpc.IPCSkeleton.getLocalDeviceID();
7340          console.log("RpcServer: localDeviceID is: " + localDeviceID);
7341          return true;
7342      }
7343  }
7344  ```
7345
7346### isLocalCalling
7347
7348static isLocalCalling(): boolean
7349
7350Checks whether the remote process is a process of the local device. This API is a static method.
7351
7352**System capability**: SystemCapability.Communication.IPC.Core
7353
7354**Return value**
7355
7356  | Type   | Description                                                     |
7357  | ------- | --------------------------------------------------------- |
7358  | boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
7359
7360**Example**
7361
7362  ```ts
7363  class Stub extends rpc.RemoteObject {
7364      onRemoteMessageRequest(code, data, reply, option) {
7365          let isLocalCalling = rpc.IPCSkeleton.isLocalCalling();
7366          console.log("RpcServer: isLocalCalling is: " + isLocalCalling);
7367          return true;
7368      }
7369  }
7370  ```
7371
7372### flushCmdBuffer<sup>9+</sup>
7373
7374static flushCmdBuffer(object: IRemoteObject): void
7375
7376Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. This API is a static method. It is recommended that this method be called before any time-sensitive operation is performed.
7377
7378**System capability**: SystemCapability.Communication.IPC.Core
7379
7380**Parameters**
7381
7382  | Name| Type                           | Mandatory| Description               |
7383  | ------ | ------------------------------- | ---- | ------------------- |
7384  | object | [IRemoteObject](#iremoteobject) | Yes  | **RemoteProxy** specified. |
7385
7386
7387**Example**
7388
7389  ```ts
7390  class TestRemoteObject extends rpc.RemoteObject {
7391      constructor(descriptor) {
7392          super(descriptor);
7393      }
7394  }
7395  let remoteObject = new TestRemoteObject("aaa");
7396  try {
7397      rpc.IPCSkeleton.flushCmdBuffer(remoteObject);
7398  } catch(error) {
7399      console.info("proxy set calling identity fail, errorCode " + error.code);
7400      console.info("proxy set calling identity fail, errorMessage " + error.message);
7401  }
7402  ```
7403
7404### flushCommands<sup>(deprecated)</sup>
7405
7406>This API is no longer maintained since API version 9. You are advised to use [flushCmdBuffer](#flushcmdbuffer9).
7407
7408static flushCommands(object: IRemoteObject): number
7409
7410Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. This API is a static method. It is recommended that this method be called before any time-sensitive operation is performed.
7411
7412**System capability**: SystemCapability.Communication.IPC.Core
7413
7414**Parameters**
7415
7416  | Name| Type                           | Mandatory| Description               |
7417  | ------ | ------------------------------- | ---- | ------------------- |
7418  | object | [IRemoteObject](#iremoteobject) | Yes  | **RemoteProxy** specified. |
7419
7420**Return value**
7421
7422  | Type  | Description                                                                             |
7423  | ------ | --------------------------------------------------------------------------------- |
7424  | 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.|
7425
7426**Example**
7427
7428  ```ts
7429  class MyDeathRecipient {
7430      onRemoteDied() {
7431          console.log("server died");
7432      }
7433  }
7434  class TestRemoteObject extends rpc.RemoteObject {
7435      constructor(descriptor) {
7436          super(descriptor);
7437      }
7438      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7439          return true;
7440      }
7441      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7442          return true;
7443      }
7444      isObjectDead(): boolean {
7445          return false;
7446      }
7447  }
7448  let remoteObject = new TestRemoteObject("aaa");
7449  let ret = rpc.IPCSkeleton.flushCommands(remoteObject);
7450  console.log("RpcServer: flushCommands result: " + ret);
7451  ```
7452
7453### resetCallingIdentity
7454
7455static resetCallingIdentity(): string
7456
7457Changes the UID and PID of the remote user to the UID and PID of the local user. This API is a static method. You can use it in scenarios such as identity authentication.
7458
7459**System capability**: SystemCapability.Communication.IPC.Core
7460
7461**Return value**
7462
7463  | Type  | Description                                |
7464  | ------ | ------------------------------------ |
7465  | string | String containing the UID and PID of the remote user.|
7466
7467**Example**
7468
7469  ```ts
7470  class Stub extends rpc.RemoteObject {
7471      onRemoteMessageRequest(code, data, reply, option) {
7472          let callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
7473          console.log("RpcServer: callingIdentity is: " + callingIdentity);
7474          return true;
7475      }
7476  }
7477  ```
7478
7479
7480### restoreCallingIdentity<sup>9+</sup>
7481
7482static restoreCallingIdentity(identity: string): void
7483
7484Changes the UID and PID of the remote user to the UID and PID of the local user. This API is a static method. You can use it in scenarios such as identity authentication.
7485
7486**System capability**: SystemCapability.Communication.IPC.Core
7487
7488**Parameters**
7489
7490  | Name  | Type  | Mandatory| Description                                                              |
7491  | -------- | ------ | ---- | ------------------------------------------------------------------ |
7492  | identity | string | Yes  | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
7493
7494**Example**
7495
7496  ```ts
7497  class Stub extends rpc.RemoteObject {
7498      onRemoteMessageRequest(code, data, reply, option) {
7499          let callingIdentity = null;
7500          try {
7501              callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
7502              console.log("RpcServer: callingIdentity is: " + callingIdentity);
7503          } finally {
7504              rpc.IPCSkeleton.restoreCallingIdentity("callingIdentity ");
7505          }
7506          return true;
7507      }
7508  }
7509  ```
7510
7511### setCallingIdentity<sup>(deprecated)</sup>
7512
7513>This API is no longer maintained since API version 9. You are advised to use [restoreCallingIdentity](#restorecallingidentity9).
7514
7515static setCallingIdentity(identity: string): boolean
7516
7517Sets the UID and PID of the remote user. This API is a static method. It is usually called when the UID and PID of the remote user are required. The UID and PID of the remote user are returned by **resetCallingIdentity**.
7518
7519**System capability**: SystemCapability.Communication.IPC.Core
7520
7521**Parameters**
7522
7523  | Name  | Type  | Mandatory| Description                                                              |
7524  | -------- | ------ | ---- | ------------------------------------------------------------------ |
7525  | identity | string | Yes  | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
7526
7527**Return value**
7528
7529  | Type   | Description                                     |
7530  | ------- | ----------------------------------------- |
7531  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
7532
7533**Example**
7534
7535  ```ts
7536  class Stub extends rpc.RemoteObject {
7537      onRemoteMessageRequest(code, data, reply, option) {
7538          let callingIdentity = null;
7539          try {
7540              callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
7541              console.log("RpcServer: callingIdentity is: " + callingIdentity);
7542          } finally {
7543              let ret = rpc.IPCSkeleton.setCallingIdentity("callingIdentity ");
7544              console.log("RpcServer: setCallingIdentity is: " + ret);
7545          }
7546          return true;
7547      }
7548  }
7549  ```
7550
7551## RemoteObject
7552
7553Provides methods to implement **RemoteObject**. The service provider must inherit from this class.
7554
7555### constructor
7556
7557constructor(descriptor: string)
7558
7559A constructor used to create a **RemoteObject** object.
7560
7561**System capability**: SystemCapability.Communication.IPC.Core
7562
7563**Parameters**
7564
7565  | Name    | Type  | Mandatory| Description        |
7566  | ---------- | ------ | ---- | ------------ |
7567  | descriptor | string | Yes  | Interface descriptor.|
7568
7569
7570### sendRequest<sup>(deprecated)</sup>
7571
7572>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
7573
7574sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
7575
7576Sends 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.
7577
7578**System capability**: SystemCapability.Communication.IPC.Core
7579
7580**Parameters**
7581
7582  | Name | Type                           | Mandatory| Description                                                                                  |
7583  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
7584  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7585  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
7586  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
7587  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
7588
7589**Return value**
7590
7591  | Type   | Description                                         |
7592  | ------- | --------------------------------------------- |
7593  | boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
7594
7595**Example**
7596
7597  ```ts
7598  class MyDeathRecipient {
7599      onRemoteDied() {
7600          console.log("server died");
7601      }
7602  }
7603  class TestRemoteObject extends rpc.RemoteObject {
7604      constructor(descriptor) {
7605          super(descriptor);
7606      }
7607      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7608          return true;
7609      }
7610      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7611          return true;
7612      }
7613      isObjectDead(): boolean {
7614          return false;
7615      }
7616  }
7617  let testRemoteObject = new TestRemoteObject("testObject");
7618  let option = new rpc.MessageOption();
7619  let data = rpc.MessageParcel.create();
7620  let reply = rpc.MessageParcel.create();
7621  data.writeInt(1);
7622  data.writeString("hello");
7623  let ret: boolean = testRemoteObject.sendRequest(1, data, reply, option);
7624  if (ret) {
7625      console.log("sendRequest got result");
7626      let msg = reply.readString();
7627      console.log("RPCTest: reply msg: " + msg);
7628  } else {
7629      console.log("RPCTest: sendRequest failed");
7630  }
7631  console.log("RPCTest: sendRequest ends, reclaim parcel");
7632  data.reclaim();
7633  reply.reclaim();
7634  ```
7635
7636### sendRequest<sup>8+(deprecated)</sup>
7637
7638>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
7639
7640sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
7641
7642Sends 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.
7643
7644**System capability**: SystemCapability.Communication.IPC.Core
7645
7646**Parameters**
7647
7648  | Name | Type                           | Mandatory| Description                                                                                  |
7649  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
7650  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7651  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
7652  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
7653  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
7654
7655**Return value**
7656
7657  | Type                            | Description                                         |
7658  | -------------------------------- | --------------------------------------------- |
7659  | Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
7660
7661**Example**
7662
7663  ```ts
7664  class MyDeathRecipient {
7665      onRemoteDied() {
7666          console.log("server died");
7667      }
7668  }
7669  class TestRemoteObject extends rpc.RemoteObject {
7670      constructor(descriptor) {
7671          super(descriptor);
7672      }
7673      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7674          return true;
7675      }
7676      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7677          return true;
7678      }
7679      isObjectDead(): boolean {
7680          return false;
7681      }
7682  }
7683  let testRemoteObject = new TestRemoteObject("testObject");
7684  let option = new rpc.MessageOption();
7685  let data = rpc.MessageParcel.create();
7686  let reply = rpc.MessageParcel.create();
7687  data.writeInt(1);
7688  data.writeString("hello");
7689  testRemoteObject.sendRequest(1, data, reply, option)
7690      .then(function(result) {
7691          if (result.errCode === 0) {
7692              console.log("sendRequest got result");
7693              result.reply.readException();
7694              let msg = result.reply.readString();
7695              console.log("RPCTest: reply msg: " + msg);
7696          } else {
7697              console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
7698          }
7699      }).catch(function(e) {
7700          console.log("RPCTest: sendRequest got exception: " + e.message);
7701      }).finally (() => {
7702          console.log("RPCTest: sendRequest ends, reclaim parcel");
7703          data.reclaim();
7704          reply.reclaim();
7705      });
7706  ```
7707
7708### sendMessageRequest<sup>9+</sup>
7709
7710sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
7711
7712Sends 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.
7713
7714**System capability**: SystemCapability.Communication.IPC.Core
7715
7716**Parameters**
7717
7718  | Name | Type                           | Mandatory| Description                                                                                  |
7719  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
7720  | code    | number                          | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7721  | data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
7722  | reply   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
7723  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
7724
7725**Return value**
7726
7727  | Type                        | Description                                         |
7728  | ---------------------------- | --------------------------------------------- |
7729  | Promise&lt;RequestResult&gt; | Promise used to return the **sendRequestResult** object.|
7730
7731**Example**
7732
7733  ```ts
7734  class TestRemoteObject extends rpc.RemoteObject {
7735      constructor(descriptor) {
7736          super(descriptor);
7737      }
7738  }
7739  let testRemoteObject = new TestRemoteObject("testObject");
7740  let option = new rpc.MessageOption();
7741  let data = rpc.MessageSequence.create();
7742  let reply = rpc.MessageSequence.create();
7743  data.writeInt(1);
7744  data.writeString("hello");
7745  testRemoteObject.sendMessageRequest(1, data, reply, option)
7746      .then(function(result) {
7747          if (result.errCode === 0) {
7748              console.log("sendMessageRequest got result");
7749              result.reply.readException();
7750              let msg = result.reply.readString();
7751              console.log("RPCTest: reply msg: " + msg);
7752          } else {
7753              console.log("RPCTest: sendMessageRequest failed, errCode: " + result.errCode);
7754          }
7755      }).catch(function(e) {
7756          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
7757      }).finally (() => {
7758          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
7759          data.reclaim();
7760          reply.reclaim();
7761      });
7762  ```
7763
7764### sendMessageRequest<sup>9+</sup>
7765
7766sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void
7767
7768Sends 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.
7769
7770**System capability**: SystemCapability.Communication.IPC.Core
7771
7772**Parameters**
7773
7774  | Name       | Type                              | Mandatory| Description                                                                                  |
7775  | ------------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
7776  | code          | number                             | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7777  | data          | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
7778  | reply         | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
7779  | options       | [MessageOption](#messageoption)    | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
7780  | AsyncCallback | AsyncCallback&lt;RequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |
7781
7782**Example**
7783
7784  ```ts
7785  class TestRemoteObject extends rpc.RemoteObject {
7786      constructor(descriptor) {
7787          super(descriptor);
7788      }
7789  }
7790  function sendRequestCallback(result) {
7791      if (result.errCode === 0) {
7792          console.log("sendRequest got result");
7793          result.reply.readException();
7794          let msg = result.reply.readString();
7795          console.log("RPCTest: reply msg: " + msg);
7796      } else {
7797          console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
7798      }
7799      console.log("RPCTest: sendRequest ends, reclaim parcel");
7800      result.data.reclaim();
7801      result.reply.reclaim();
7802  }
7803  let testRemoteObject = new TestRemoteObject("testObject");
7804  let option = new rpc.MessageOption();
7805  let data = rpc.MessageSequence.create();
7806  let reply = rpc.MessageSequence.create();
7807  data.writeInt(1);
7808  data.writeString("hello");
7809  testRemoteObject.sendMessageRequest(1, data, reply, option, sendRequestCallback);
7810  ```
7811
7812### sendRequest<sup>8+(deprecated)</sup>
7813
7814>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
7815
7816sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void
7817
7818Sends 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.
7819
7820**System capability**: SystemCapability.Communication.IPC.Core
7821
7822**Parameters**
7823
7824  | Name       | Type                                  | Mandatory| Description                                                                                  |
7825  | ------------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
7826  | code          | number                                 | Yes  | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
7827  | data          | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object holding the data to send.                                             |
7828  | reply         | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object that receives the response.                                                     |
7829  | options       | [MessageOption](#messageoption)        | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
7830  | AsyncCallback | AsyncCallback&lt;SendRequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |
7831
7832**Example**
7833
7834  ```ts
7835  class MyDeathRecipient {
7836      onRemoteDied() {
7837          console.log("server died");
7838      }
7839  }
7840  class TestRemoteObject extends rpc.RemoteObject {
7841      constructor(descriptor) {
7842          super(descriptor);
7843      }
7844      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7845          return true;
7846      }
7847      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7848          return true;
7849      }
7850      isObjectDead(): boolean {
7851          return false;
7852      }
7853  }
7854  function sendRequestCallback(result) {
7855      if (result.errCode === 0) {
7856          console.log("sendRequest got result");
7857          result.reply.readException();
7858          let msg = result.reply.readString();
7859          console.log("RPCTest: reply msg: " + msg);
7860      } else {
7861          console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
7862      }
7863      console.log("RPCTest: sendRequest ends, reclaim parcel");
7864      result.data.reclaim();
7865      result.reply.reclaim();
7866  }
7867  let testRemoteObject = new TestRemoteObject("testObject");
7868  let option = new rpc.MessageOption();
7869  let data = rpc.MessageParcel.create();
7870  let reply = rpc.MessageParcel.create();
7871  data.writeInt(1);
7872  data.writeString("hello");
7873  testRemoteObject.sendRequest(1, data, reply, option, sendRequestCallback);
7874  ```
7875
7876### onRemoteRequest<sup>8+(deprecated)</sup>
7877
7878>This API is no longer maintained since API version 9. You are advised to use [onRemoteMessageRequest](#onremotemessagerequest9).
7879
7880onRemoteRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
7881
7882Provides a response to **sendMessageRequest()**. The server processes the request and returns a response in this API.
7883
7884**System capability**: SystemCapability.Communication.IPC.Core
7885
7886**Parameters**
7887
7888  | Name| Type                           | Mandatory| Description                                   |
7889  | ------ | ------------------------------- | ---- | --------------------------------------- |
7890  | code   | number                          | Yes  | Service request code sent by the remote end.                 |
7891  | data   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that holds the parameters called by the client.|
7892  | reply  | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object carrying the result.          |
7893  | option | [MessageOption](#messageoption) | Yes  | Whether the operation is synchronous or asynchronous.               |
7894
7895**Return value**
7896
7897  | Type   | Description                                     |
7898  | ------- | ----------------------------------------- |
7899  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
7900
7901**Example**
7902
7903  ```ts
7904  class MyDeathRecipient {
7905      onRemoteDied() {
7906          console.log("server died");
7907      }
7908  }
7909  class TestRemoteObject extends rpc.RemoteObject {
7910      constructor(descriptor) {
7911          super(descriptor);
7912      }
7913      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7914          return true;
7915      }
7916      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
7917          return true;
7918      }
7919      isObjectDead(): boolean {
7920          return false;
7921      }
7922      onRemoteRequest(code, data, reply, option) {
7923          if (code === 1) {
7924              console.log("RpcServer: onRemoteRequest called");
7925              return true;
7926          } else {
7927              console.log("RpcServer: unknown code: " + code);
7928              return false;
7929          }
7930      }
7931  }
7932  ```
7933
7934### onRemoteMessageRequest<sup>9+</sup>
7935
7936onRemoteMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): boolean | Promise\<boolean>
7937
7938> **NOTE**<br/>
7939>
7940>* You are advised to overload **onRemoteMessageRequest** preferentially, which implements synchronous and asynchronous message processing.
7941>* If both onRemoteRequest() and onRemoteMessageRequest() are overloaded, only the onRemoteMessageRequest() takes effect.
7942
7943Provides a response to **sendMessageRequest()**. The server processes the request synchronously or asynchronously and returns the result in this API.
7944
7945**System capability**: SystemCapability.Communication.IPC.Core
7946
7947**Parameters**
7948
7949  | Name| Type                           | Mandatory| Description                                     |
7950  | ------ | ------------------------------- | ---- | ----------------------------------------- |
7951  | code   | number                          | Yes  | Service request code sent by the remote end.                   |
7952  | data   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that holds the parameters called by the client.|
7953  | reply  | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object to which the result is written.          |
7954  | option | [MessageOption](#messageoption) | Yes  | Whether the operation is synchronous or asynchronous.                 |
7955
7956**Return value**
7957
7958  | Type             | Description                                                                                          |
7959  | ----------------- | ---------------------------------------------------------------------------------------------- |
7960  | 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.|
7961  | Promise\<boolean> | Returns a promise object if the request is processed asynchronously in **onRemoteMessageRequest**.                                |
7962
7963**Example**: Overload **onRemoteMessageRequest** to process requests synchronously.
7964
7965  ```ts
7966  class TestRemoteObject extends rpc.RemoteObject {
7967      constructor(descriptor) {
7968          super(descriptor);
7969      }
7970
7971      onRemoteMessageRequest(code, data, reply, option) {
7972          if (code === 1) {
7973              console.log("RpcServer: sync onRemoteMessageRequest is called");
7974              return true;
7975          } else {
7976              console.log("RpcServer: unknown code: " + code);
7977              return false;
7978          }
7979      }
7980  }
7981  ```
7982
7983  **Example**: Overload **onRemoteMessageRequest** to process requests asynchronously.
7984
7985  ```ts
7986  class TestRemoteObject extends rpc.RemoteObject {
7987      constructor(descriptor) {
7988          super(descriptor);
7989      }
7990
7991      async onRemoteMessageRequest(code, data, reply, option) {
7992          if (code === 1) {
7993              console.log("RpcServer: async onRemoteMessageRequest is called");
7994          } else {
7995              console.log("RpcServer: unknown code: " + code);
7996              return false;
7997          }
7998          await new Promise((resolve) => {
7999            setTimeout(resolve, 100);
8000          })
8001          return true;
8002      }
8003  }
8004  ```
8005
8006**Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests synchronously.
8007
8008  ```ts
8009  class TestRemoteObject extends rpc.RemoteObject {
8010      constructor(descriptor) {
8011          super(descriptor);
8012      }
8013
8014      onRemoteRequest(code, data, reply, option) {
8015          if (code === 1) {
8016              console.log("RpcServer: sync onRemoteMessageRequest is called");
8017              return true;
8018          } else {
8019              console.log("RpcServer: unknown code: " + code);
8020              return false;
8021          }
8022      }
8023      // Only onRemoteMessageRequest is executed.
8024      onRemoteMessageRequest(code, data, reply, option) {
8025          if (code === 1) {
8026              console.log("RpcServer: async onRemoteMessageRequest is called");
8027          } else {
8028              console.log("RpcServer: unknown code: " + code);
8029              return false;
8030          }
8031
8032          return true;
8033      }
8034  }
8035  ```
8036
8037  **Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests asynchronously.
8038
8039  ```ts
8040  class TestRemoteObject extends rpc.RemoteObject {
8041      constructor(descriptor) {
8042          super(descriptor);
8043      }
8044
8045      onRemoteRequest(code, data, reply, option) {
8046          if (code === 1) {
8047              console.log("RpcServer: sync onRemoteRequest is called");
8048              return true;
8049          } else {
8050              console.log("RpcServer: unknown code: " + code);
8051              return false;
8052          }
8053      }
8054      // Only onRemoteMessageRequest is executed.
8055      async onRemoteMessageRequest(code, data, reply, option) {
8056          if (code === 1) {
8057              console.log("RpcServer: async onRemoteMessageRequest is called");
8058          } else {
8059              console.log("RpcServer: unknown code: " + code);
8060              return false;
8061          }
8062         await new Promise((resolve) => {
8063            setTimeout(resolve, 100);
8064          })
8065          return true;
8066      }
8067  }
8068  ```
8069
8070### getCallingUid
8071
8072getCallingUid(): number
8073
8074Obtains the UID of the remote process.
8075
8076**System capability**: SystemCapability.Communication.IPC.Core
8077
8078**Return value**
8079  | Type  | Description                   |
8080  | ------ | ----------------------- |
8081  | number | UID of the remote process obtained.|
8082
8083**Example**
8084
8085  ```ts
8086  class TestRemoteObject extends rpc.RemoteObject {
8087      constructor(descriptor) {
8088          super(descriptor);
8089      }
8090  }
8091  let testRemoteObject = new TestRemoteObject("testObject");
8092  console.log("RpcServer: getCallingUid: " + testRemoteObject.getCallingUid());
8093  ```
8094
8095### getCallingPid
8096
8097getCallingPid(): number
8098
8099Obtains the PID of the remote process.
8100
8101**System capability**: SystemCapability.Communication.IPC.Core
8102
8103**Return value**
8104
8105  | Type  | Description                   |
8106  | ------ | ----------------------- |
8107  | number | PID of the remote process obtained.|
8108
8109**Example**
8110
8111  ```ts
8112  class TestRemoteObject extends rpc.RemoteObject {
8113      constructor(descriptor) {
8114          super(descriptor);
8115      }
8116  }
8117  let testRemoteObject = new TestRemoteObject("testObject");
8118  console.log("RpcServer: getCallingPid: " + testRemoteObject.getCallingPid());
8119  ```
8120
8121### getLocalInterface<sup>9+</sup>
8122
8123getLocalInterface(descriptor: string): IRemoteBroker
8124
8125Obtains the interface descriptor.
8126
8127**System capability**: SystemCapability.Communication.IPC.Core
8128
8129**Parameters**
8130
8131  | Name    | Type  | Mandatory| Description                |
8132  | ---------- | ------ | ---- | -------------------- |
8133  | descriptor | string | Yes  | Interface descriptor.|
8134
8135**Return value**
8136
8137  | Type         | Description                                         |
8138  | ------------- | --------------------------------------------- |
8139  | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
8140
8141
8142**Example**
8143
8144  ```ts
8145  class MyDeathRecipient {
8146      onRemoteDied() {
8147          console.log("server died");
8148      }
8149  }
8150  class TestRemoteObject extends rpc.RemoteObject {
8151      constructor(descriptor) {
8152          super(descriptor);
8153      }
8154      registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
8155          // Implement the method logic based on service requirements.
8156      }
8157      unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
8158          // Implement the method logic based on service requirements.
8159      }
8160      isObjectDead(): boolean {
8161          return false;
8162      }
8163  }
8164  let testRemoteObject = new TestRemoteObject("testObject");
8165  try {
8166      let broker = testRemoteObject.getLocalInterface("testObject");
8167  } catch(error) {
8168      console.info("rpc get local interface fail, errorCode " + error.code);
8169      console.info("rpc get local interface fail, errorMessage " + error.message);
8170  }
8171  ```
8172
8173### queryLocalInterface<sup>(deprecated)</sup>
8174
8175>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).
8176
8177queryLocalInterface(descriptor: string): IRemoteBroker
8178
8179Checks whether the remote object corresponding to the specified interface token exists.
8180
8181**System capability**: SystemCapability.Communication.IPC.Core
8182
8183**Parameters**
8184
8185  | Name    | Type  | Mandatory| Description                  |
8186  | ---------- | ------ | ---- | ---------------------- |
8187  | descriptor | string | Yes  | Interface descriptor.|
8188
8189**Return value**
8190
8191  | Type         | Description                                                              |
8192  | ------------- | ------------------------------------------------------------------ |
8193  | IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.|
8194
8195**Example**
8196
8197  ```ts
8198  class MyDeathRecipient {
8199      onRemoteDied() {
8200          console.log("server died");
8201      }
8202  }
8203  class TestRemoteObject extends rpc.RemoteObject {
8204      constructor(descriptor) {
8205          super(descriptor);
8206      }
8207      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8208          return true;
8209      }
8210      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8211          return true;
8212      }
8213      isObjectDead(): boolean {
8214          return false;
8215      }
8216  }
8217  let testRemoteObject = new TestRemoteObject("testObject");
8218  let broker = testRemoteObject.queryLocalInterface("testObject");
8219  ```
8220
8221### getDescriptor<sup>9+</sup>
8222
8223getDescriptor(): string
8224
8225Obtains the interface descriptor of this object. The interface descriptor is a string.
8226
8227**System capability**: SystemCapability.Communication.IPC.Core
8228
8229**Return value**
8230
8231  | Type  | Description            |
8232  | ------ | ---------------- |
8233  | string | Interface descriptor obtained.|
8234
8235**Error codes**
8236
8237For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
8238
8239  | ID| Error Message|
8240  | ------- | -------- |
8241  | 1900008 | proxy or remote object is invalid |
8242
8243**Example**
8244
8245  ```ts
8246  class MyDeathRecipient {
8247      onRemoteDied() {
8248          console.log("server died");
8249      }
8250  }
8251  class TestRemoteObject extends rpc.RemoteObject {
8252      constructor(descriptor) {
8253          super(descriptor);
8254      }
8255      registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
8256          // Implement the method logic based on service requirements.
8257      }
8258      unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
8259          // Implement the method logic based on service requirements.
8260      }
8261      isObjectDead(): boolean {
8262          return false;
8263      }
8264  }
8265  let testRemoteObject = new TestRemoteObject("testObject");
8266  console.log("RpcServer: descriptor is: " + descriptor);
8267  try {
8268      let descriptor = testRemoteObject.getDescriptor();
8269  } catch(error) {
8270      console.info("rpc get local interface fail, errorCode " + error.code);
8271      console.info("rpc get local interface fail, errorMessage " + error.message);
8272  }
8273  ```
8274
8275### getInterfaceDescriptor<sup>(deprecated)</sup>
8276
8277>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
8278
8279getInterfaceDescriptor(): string
8280
8281Obtains the interface descriptor.
8282
8283**System capability**: SystemCapability.Communication.IPC.Core
8284
8285**Return value**
8286
8287  | Type  | Description            |
8288  | ------ | ---------------- |
8289  | string | Interface descriptor obtained.|
8290
8291**Example**
8292
8293  ```ts
8294  class MyDeathRecipient {
8295      onRemoteDied() {
8296          console.log("server died");
8297      }
8298  }
8299  class TestRemoteObject extends rpc.RemoteObject {
8300      constructor(descriptor) {
8301          super(descriptor);
8302      }
8303      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8304          return true;
8305      }
8306      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8307          return true;
8308      }
8309      isObjectDead(): boolean {
8310          return false;
8311      }
8312  }
8313  let testRemoteObject = new TestRemoteObject("testObject");
8314  let descriptor = testRemoteObject.getInterfaceDescriptor();
8315  console.log("RpcServer: descriptor is: " + descriptor);
8316  ```
8317
8318### modifyLocalInterface<sup>9+</sup>
8319
8320modifyLocalInterface(localInterface: IRemoteBroker, descriptor: string): void
8321
8322Binds an interface descriptor to an **IRemoteBroker** object.
8323
8324**System capability**: SystemCapability.Communication.IPC.Core
8325
8326**Parameters**
8327
8328  | Name        | Type         | Mandatory| Description                                 |
8329  | -------------- | ------------- | ---- | ------------------------------------- |
8330  | localInterface | IRemoteBroker | Yes  | **IRemoteBroker** object.  |
8331  | descriptor     | string        | Yes  | Interface descriptor.|
8332
8333**Example**
8334
8335  ```ts
8336  class MyDeathRecipient {
8337      onRemoteDied() {
8338          console.log("server died");
8339      }
8340  }
8341  class TestRemoteObject extends rpc.RemoteObject {
8342      constructor(descriptor) {
8343          super(descriptor);
8344          try {
8345              this.modifyLocalInterface(this, descriptor);
8346          } catch(error) {
8347              console.info(" rpc attach local interface fail, errorCode " + error.code);
8348              console.info(" rpc attach local interface fail, errorMessage " + error.message);
8349          }
8350      }
8351      registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
8352          // Implement the method logic based on service requirements.
8353      }
8354      unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
8355          // Implement the method logic based on service requirements.
8356      }
8357      isObjectDead(): boolean {
8358          return false;
8359      }
8360      asObject(): rpc.IRemoteObject {
8361          return this;
8362      }
8363  }
8364  let testRemoteObject = new TestRemoteObject("testObject");
8365  ```
8366
8367### attachLocalInterface<sup>(deprecated)</sup>
8368
8369>This API is no longer maintained since API version 9. You are advised to use [modifyLocalInterface](#modifylocalinterface9).
8370
8371attachLocalInterface(localInterface: IRemoteBroker, descriptor: string): void
8372
8373Binds an interface descriptor to an **IRemoteBroker** object.
8374
8375**System capability**: SystemCapability.Communication.IPC.Core
8376
8377**Parameters**
8378
8379  | Name        | Type         | Mandatory| Description                                 |
8380  | -------------- | ------------- | ---- | ------------------------------------- |
8381  | localInterface | IRemoteBroker | Yes  | **IRemoteBroker** object.  |
8382  | descriptor     | string        | Yes  | Interface descriptor.|
8383
8384**Example**
8385
8386  ```ts
8387  class MyDeathRecipient {
8388      onRemoteDied() {
8389          console.log("server died");
8390      }
8391  }
8392  class TestRemoteObject extends rpc.RemoteObject {
8393      constructor(descriptor) {
8394          super(descriptor);
8395          this.attachLocalInterface(this, descriptor);
8396      }
8397      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8398          return true;
8399      }
8400      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
8401          return true;
8402      }
8403      isObjectDead(): boolean {
8404          return false;
8405      }
8406      asObject(): rpc.IRemoteObject {
8407          return this;
8408      }
8409  }
8410  let testRemoteObject = new TestRemoteObject("testObject");
8411  ```
8412
8413## Ashmem<sup>8+</sup>
8414
8415Provides 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.
8416
8417**System capability**: SystemCapability.Communication.IPC.Core
8418
8419The table below describes the protection types of the mapped memory.
8420
8421  | Name      | Value | Description              |
8422  | ---------- | --- | ------------------ |
8423  | PROT_EXEC  | 4   | The mapped memory is executable.  |
8424  | PROT_NONE  | 0   | The mapped memory is inaccessible.|
8425  | PROT_READ  | 1   | The mapped memory is readable.    |
8426  | PROT_WRITE | 2   | The mapped memory is writeable.    |
8427
8428### create<sup>9+</sup>
8429
8430static create(name: string, size: number): Ashmem
8431
8432Creates an **Ashmem** object with the specified name and size. This API is a static method.
8433
8434**System capability**: SystemCapability.Communication.IPC.Core
8435
8436**Parameters**
8437
8438  | Name| Type  | Mandatory| Description                        |
8439  | ------ | ------ | ---- | ---------------------------- |
8440  | name   | string | Yes  | Name of the **Ashmem** object to create.  |
8441  | size   | number | Yes  | Size (in bytes) of the **Ashmem** object to create.|
8442
8443**Return value**
8444
8445  | Type  | Description                                          |
8446  | ------ | ---------------------------------------------- |
8447  | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
8448
8449**Example**
8450
8451  ```ts
8452  let ashmem;
8453  try {
8454      ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8455  } catch(error) {
8456      console.info("Rpc creat ashmem fail, errorCode " + error.code);
8457      console.info("Rpc creat ashmem  fail, errorMessage " + error.message);
8458  }
8459  let size = ashmem.getAshmemSize();
8460  console.log("RpcTest: get ashemm by create : " + ashmem + " size is : " + size);
8461  ```
8462
8463### createAshmem<sup>8+(deprecated)</sup>
8464
8465>This API is no longer maintained since API version 9. You are advised to use [create](#create9).
8466
8467static createAshmem(name: string, size: number): Ashmem
8468
8469Creates an **Ashmem** object with the specified name and size. This API is a static method.
8470
8471**System capability**: SystemCapability.Communication.IPC.Core
8472
8473**Parameters**
8474
8475  | Name| Type  | Mandatory| Description                        |
8476  | ------ | ------ | ---- | ---------------------------- |
8477  | name   | string | Yes  | Name of the **Ashmem** object to create.  |
8478  | size   | number | Yes  | Size (in bytes) of the **Ashmem** object to create.|
8479
8480**Return value**
8481
8482  | Type  | Description                                          |
8483  | ------ | ---------------------------------------------- |
8484  | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
8485
8486**Example**
8487
8488  ```ts
8489  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8490  let size = ashmem.getAshmemSize();
8491  console.log("RpcTest: get ashemm by createAshmem : " + ashmem + " size is : " + size);
8492  ```
8493
8494### create<sup>9+</sup>
8495
8496static create(ashmem: Ashmem): Ashmem
8497
8498Creates an **Ashmem** object by copying the file descriptor of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
8499
8500**System capability**: SystemCapability.Communication.IPC.Core
8501
8502**Parameters**
8503
8504  | Name| Type  | Mandatory| Description                |
8505  | ------ | ------ | ---- | -------------------- |
8506  | ashmem | Ashmem | Yes  | Existing **Ashmem** object.|
8507
8508**Return value**
8509
8510  | Type  | Description                  |
8511  | ------ | ---------------------- |
8512  | Ashmem | **Ashmem** object created.|
8513
8514
8515**Example**
8516
8517  ```ts
8518  let ashmem2;
8519  try {
8520      let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8521      let ashmem2 = rpc.Ashmem.create(ashmem);
8522  } catch(error) {
8523      console.info("Rpc creat ashmem from existing fail, errorCode " + error.code);
8524      console.info("Rpc creat ashmem from existing  fail, errorMessage " + error.message);
8525  }
8526  let size = ashmem2.getAshmemSize();
8527  console.log("RpcTest: get ashemm by create : " + ashmem2 + " size is : " + size);
8528  ```
8529
8530### createAshmemFromExisting<sup>8+(deprecated)</sup>
8531
8532>This API is no longer maintained since API version 9. You are advised to use [create](#create9).
8533
8534static createAshmemFromExisting(ashmem: Ashmem): Ashmem
8535
8536Creates an **Ashmem** object by copying the file descriptor of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
8537
8538**System capability**: SystemCapability.Communication.IPC.Core
8539
8540**Parameters**
8541
8542  | Name| Type  | Mandatory| Description                |
8543  | ------ | ------ | ---- | -------------------- |
8544  | ashmem | Ashmem | Yes  | Existing **Ashmem** object.|
8545
8546**Return value**
8547
8548  | Type  | Description                  |
8549  | ------ | ---------------------- |
8550  | Ashmem | **Ashmem** object created.|
8551
8552**Example**
8553
8554  ```ts
8555  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8556  let ashmem2 = rpc.Ashmem.createAshmemFromExisting(ashmem);
8557  let size = ashmem2.getAshmemSize();
8558  console.log("RpcTest: get ashemm by createAshmemFromExisting : " + ashmem2 + " size is : " + size);
8559  ```
8560
8561### closeAshmem<sup>8+</sup>
8562
8563closeAshmem(): void
8564
8565Closes this **Ashmem** object.
8566
8567**System capability**: SystemCapability.Communication.IPC.Core
8568
8569**Example**
8570
8571  ```ts
8572  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8573  ashmem.closeAshmem();
8574  ```
8575
8576### unmapAshmem<sup>8+</sup>
8577
8578unmapAshmem(): void
8579
8580Deletes the mappings for the specified address range of this **Ashmem** object.
8581
8582**System capability**: SystemCapability.Communication.IPC.Core
8583
8584**Example**
8585
8586  ```ts
8587  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8588  ashmem.unmapAshmem();
8589  ```
8590
8591### getAshmemSize<sup>8+</sup>
8592
8593getAshmemSize(): number
8594
8595Obtains the memory size of this **Ashmem** object.
8596
8597**System capability**: SystemCapability.Communication.IPC.Core
8598
8599**Return value**
8600
8601  | Type  | Description                      |
8602  | ------ | -------------------------- |
8603  | number | **Ashmem** size obtained.|
8604
8605**Example**
8606
8607  ```ts
8608  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8609  let size = ashmem.getAshmemSize();
8610  console.log("RpcTest: get ashmem is " + ashmem + " size is : " + size);
8611  ```
8612
8613### mapTypedAshmem<sup>9+</sup>
8614
8615mapTypedAshmem(mapType: number): void
8616
8617Creates the shared file mapping on the virtual address space of this process. The size of the mapping region is specified by this **Ashmem** object.
8618
8619**System capability**: SystemCapability.Communication.IPC.Core
8620
8621**Parameters**
8622
8623  | Name | Type  | Mandatory| Description                          |
8624  | ------- | ------ | ---- | ------------------------------ |
8625  | mapType | number | Yes  | Protection level of the memory region to which the shared file is mapped.|
8626
8627**Error codes**
8628
8629For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
8630
8631  | ID| Error Message|
8632  | ------- | ------ |
8633  | 1900001     | call mmap function failed |
8634
8635**Example**
8636
8637  ```ts
8638  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8639  try {
8640      ashmem.mapTypedAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
8641  } catch(error) {
8642      console.info("Rpc map ashmem fail, errorCode " + error.code);
8643      console.info("Rpc map ashmem fail, errorMessage " + error.message);
8644  }
8645  ```
8646
8647### mapAshmem<sup>8+(deprecated)</sup>
8648
8649>This API is no longer maintained since API version 9. You are advised to use [mapTypedAshmem](#maptypedashmem9).
8650
8651mapAshmem(mapType: number): boolean
8652
8653Creates the shared file mapping on the virtual address space of this process. The size of the mapping region is specified by this **Ashmem** object.
8654
8655**System capability**: SystemCapability.Communication.IPC.Core
8656
8657**Parameters**
8658
8659  | Name | Type  | Mandatory| Description                          |
8660  | ------- | ------ | ---- | ------------------------------ |
8661  | mapType | number | Yes  | Protection level of the memory region to which the shared file is mapped.|
8662
8663**Return value**
8664
8665  | Type   | Description                                     |
8666  | ------- | ----------------------------------------- |
8667  | boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
8668
8669**Example**
8670
8671  ```ts
8672  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8673  let mapReadAndWrite = ashmem.mapAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
8674  console.log("RpcTest: map ashmem result is  : " + mapReadAndWrite);
8675  ```
8676
8677### mapReadWriteAshmem<sup>9+</sup>
8678
8679mapReadWriteAshmem(): void
8680
8681Maps the shared file to the readable and writable virtual address space of the process.
8682
8683**System capability**: SystemCapability.Communication.IPC.Core
8684
8685**Error codes**
8686
8687For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
8688
8689  | ID| Error Message|
8690  | ------- | -------- |
8691  | 1900001 | call mmap function failed |
8692
8693**Example**
8694
8695  ```ts
8696  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8697  try {
8698      ashmem.mapReadWriteAshmem();
8699  } catch(error) {
8700      console.info("Rpc map read and write ashmem fail, errorCode " + error.code);
8701      console.info("Rpc map read and write ashmem fail, errorMessage " + error.message);
8702  }
8703  ```
8704
8705### mapReadAndWriteAshmem<sup>8+(deprecated)</sup>
8706
8707>This API is no longer maintained since API version 9. You are advised to use [mapReadWriteAshmem](#mapreadwriteashmem9).
8708
8709mapReadAndWriteAshmem(): boolean
8710
8711Maps the shared file to the readable and writable virtual address space of the process.
8712
8713**System capability**: SystemCapability.Communication.IPC.Core
8714
8715**Return value**
8716
8717  | Type   | Description                                     |
8718  | ------- | ----------------------------------------- |
8719  | boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
8720
8721**Example**
8722
8723  ```ts
8724  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8725  let mapResult = ashmem.mapReadAndWriteAshmem();
8726  console.log("RpcTest: map ashmem result is  : " + mapResult);
8727  ```
8728
8729### mapReadonlyAshmem<sup>9+</sup>
8730
8731mapReadonlyAshmem(): void
8732
8733Maps the shared file to the read-only virtual address space of the process.
8734
8735**System capability**: SystemCapability.Communication.IPC.Core
8736
8737**Error codes**
8738
8739For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
8740
8741  | ID| Error Message|
8742  | ------- | -------- |
8743  | 1900001 | call mmap function failed |
8744
8745**Example**
8746
8747  ```ts
8748  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8749  try {
8750      ashmem.mapReadonlyAshmem();
8751  } catch(error) {
8752      console.info("Rpc map read and write ashmem fail, errorCode " + error.code);
8753      console.info("Rpc map read and write ashmem fail, errorMessage " + error.message);
8754  }
8755  ```
8756
8757### mapReadOnlyAshmem<sup>8+(deprecated)</sup>
8758
8759>This API is no longer maintained since API version 9. You are advised to use [mapReadonlyAshmem](#mapreadonlyashmem9).
8760
8761mapReadOnlyAshmem(): boolean
8762
8763Maps the shared file to the read-only virtual address space of the process.
8764
8765**System capability**: SystemCapability.Communication.IPC.Core
8766
8767**Return value**
8768
8769  | Type   | Description                                     |
8770  | ------- | ----------------------------------------- |
8771  | boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
8772
8773**Example**
8774
8775  ```ts
8776  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8777  let mapResult = ashmem.mapReadOnlyAshmem();
8778  console.log("RpcTest: Ashmem mapReadOnlyAshmem result is : " + mapResult);
8779  ```
8780
8781### setProtectionType<sup>9+</sup>
8782
8783setProtectionType(protectionType: number): void
8784
8785Sets the protection level of the memory region to which the shared file is mapped.
8786
8787**System capability**: SystemCapability.Communication.IPC.Core
8788
8789**Parameters**
8790
8791  | Name        | Type  | Mandatory| Description              |
8792  | -------------- | ------ | ---- | ------------------ |
8793  | protectionType | number | Yes  | Protection type to set.|
8794
8795**Error codes**
8796
8797For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
8798
8799  | ID| Error Message|
8800  | -------- | ------- |
8801  | 1900002 | call os ioctl function failed |
8802
8803**Example**
8804
8805  ```ts
8806  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8807  try {
8808      ashmem.setProtection(ashmem.PROT_READ);
8809  } catch(error) {
8810      console.info("Rpc set protection type fail, errorCode " + error.code);
8811      console.info("Rpc set protection type fail, errorMessage " + error.message);
8812  }
8813  ```
8814
8815### setProtection<sup>8+(deprecated)</sup>
8816
8817>This API is no longer maintained since API version 9. You are advised to use [setProtectionType](#setprotectiontype9).
8818
8819setProtection(protectionType: number): boolean
8820
8821Sets the protection level of the memory region to which the shared file is mapped.
8822
8823**System capability**: SystemCapability.Communication.IPC.Core
8824
8825**Parameters**
8826
8827  | Name        | Type  | Mandatory| Description              |
8828  | -------------- | ------ | ---- | ------------------ |
8829  | protectionType | number | Yes  | Protection type to set.|
8830
8831**Return value**
8832
8833  | Type   | Description                                     |
8834  | ------- | ----------------------------------------- |
8835  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
8836
8837**Example**
8838
8839  ```ts
8840  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8841  let result = ashmem.setProtection(ashmem.PROT_READ);
8842  console.log("RpcTest: Ashmem setProtection result is : " + result);
8843  ```
8844
8845### writeAshmem<sup>9+</sup>
8846
8847writeAshmem(buf: number[], size: number, offset: number): void
8848
8849Writes data to the shared file associated with this **Ashmem** object.
8850
8851**System capability**: SystemCapability.Communication.IPC.Core
8852
8853**Parameters**
8854
8855  | Name| Type    | Mandatory| Description                                              |
8856  | ------ | -------- | ---- | -------------------------------------------------- |
8857  | buf    | number[] | Yes  | Data to write.                            |
8858  | size   | number   | Yes  | Size of the data to write.                                |
8859  | offset | number   | Yes  | Start position of the data to write in the memory region associated with this **Ashmem** object.|
8860
8861**Error codes**
8862
8863For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
8864
8865  | ID| Error Message|
8866  | ------- | -------- |
8867  | 1900003 | write to ashmem failed |
8868
8869**Example**
8870
8871  ```ts
8872  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8873  ashmem.mapReadWriteAshmem();
8874  var ByteArrayVar = [1, 2, 3, 4, 5];
8875  try {
8876      ashmem.writeAshmem(ByteArrayVar, 5, 0);
8877  } catch(error) {
8878      console.info("Rpc write to ashmem fail, errorCode " + error.code);
8879      console.info("Rpc write to ashmem fail, errorMessage " + error.message);
8880  }
8881  ```
8882
8883### writeToAshmem<sup>8+(deprecated)</sup>
8884
8885>This API is no longer maintained since API version 9. You are advised to use [writeAshmem](#writeashmem9).
8886
8887writeToAshmem(buf: number[], size: number, offset: number): boolean
8888
8889Writes data to the shared file associated with this **Ashmem** object.
8890
8891**System capability**: SystemCapability.Communication.IPC.Core
8892
8893**Parameters**
8894
8895  | Name| Type    | Mandatory| Description                                              |
8896  | ------ | -------- | ---- | -------------------------------------------------- |
8897  | buf    | number[] | Yes  | Data to write.                            |
8898  | size   | number   | Yes  | Size of the data to write.                                |
8899  | offset | number   | Yes  | Start position of the data to write in the memory region associated with this **Ashmem** object.|
8900
8901**Return value**
8902
8903  | Type   | Description                                                                                     |
8904  | ------- | ----------------------------------------------------------------------------------------- |
8905  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
8906
8907**Example**
8908
8909  ```ts
8910  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8911  let mapResult = ashmem.mapReadAndWriteAshmem();
8912  console.info("RpcTest map ashmem result is " + mapResult);
8913  var ByteArrayVar = [1, 2, 3, 4, 5];
8914  let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
8915  console.log("RpcTest: write to Ashmem result is  : " + writeResult);
8916  ```
8917
8918### readAshmem<sup>9+</sup>
8919
8920readAshmem(size: number, offset: number): number[]
8921
8922Reads data from the shared file associated with this **Ashmem** object.
8923
8924**System capability**: SystemCapability.Communication.IPC.Core
8925
8926**Parameters**
8927
8928  | Name| Type  | Mandatory| Description                                              |
8929  | ------ | ------ | ---- | -------------------------------------------------- |
8930  | size   | number | Yes  | Size of the data to read.                              |
8931  | offset | number | Yes  | Start position of the data to read in the memory region associated with this **Ashmem** object.|
8932
8933**Return value**
8934
8935  | Type    | Description            |
8936  | -------- | ---------------- |
8937  | number[] | Data read.|
8938
8939**Error codes**
8940
8941For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
8942
8943  | ID | Error Message|
8944  | -------- | -------- |
8945  | 1900004 | read from ashmem failed |
8946
8947**Example**
8948
8949  ```ts
8950  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
8951  ashmem.mapReadWriteAshmem();
8952  var ByteArrayVar = [1, 2, 3, 4, 5];
8953  ashmem.writeAshmem(ByteArrayVar, 5, 0);
8954  try {
8955      let readResult = ashmem.readAshmem(5, 0);
8956      console.log("RpcTest: read from Ashmem result is  : " + readResult);
8957  } catch(error) {
8958      console.info("Rpc read from ashmem fail, errorCode " + error.code);
8959      console.info("Rpc read from ashmem fail, errorMessage " + error.message);
8960  }
8961  ```
8962
8963### readFromAshmem<sup>8+(deprecated)</sup>
8964
8965>This API is no longer maintained since API version 9. You are advised to use [readAshmem](#readashmem9).
8966
8967readFromAshmem(size: number, offset: number): number[]
8968
8969Reads data from the shared file associated with this **Ashmem** object.
8970
8971**System capability**: SystemCapability.Communication.IPC.Core
8972
8973**Parameters**
8974
8975  | Name| Type  | Mandatory| Description                                              |
8976  | ------ | ------ | ---- | -------------------------------------------------- |
8977  | size   | number | Yes  | Size of the data to read.                              |
8978  | offset | number | Yes  | Start position of the data to read in the memory region associated with this **Ashmem** object.|
8979
8980**Return value**
8981
8982  | Type    | Description            |
8983  | -------- | ---------------- |
8984  | number[] | Data read.|
8985
8986**Example**
8987
8988 ```ts
8989  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
8990  let mapResult = ashmem.mapReadAndWriteAshmem();
8991  console.info("RpcTest map ashmem result is " + mapResult);
8992  var ByteArrayVar = [1, 2, 3, 4, 5];
8993  let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
8994  console.log("RpcTest: write to Ashmem result is  : " + writeResult);
8995  let readResult = ashmem.readFromAshmem(5, 0);
8996  console.log("RpcTest: read to Ashmem result is  : " + readResult);
8997  ```
8998