js-apis-rpc.md 270.2 KB
Newer Older
A
annie_wangli 已提交
1
# RPC
Z
zengyawen 已提交
2

A
Annie_wang 已提交
3
The **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.
Z
zengyawen 已提交
4

A
Annie_wang 已提交
5
> **NOTE**<br>
Z
zengyawen 已提交
6
> 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.
A
Annie_wang 已提交
7
> This module supports return of error codes since API version 9.
Z
zengyawen 已提交
8 9 10 11 12 13 14 15 16


## Modules to Import

```
import rpc from '@ohos.rpc';
```


A
Annie_wang 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
## ErrorCode<sup>9+</sup>

The APIs of this module return exceptions since API version 9. The following table lists the error codes.

**System capability**: SystemCapability.Communication.IPC.Core

  | Name                                 | Value     | Description                                         |
  | ------------------------------------- | ------- | --------------------------------------------- |
  | CHECK_PARAM_ERROR                     | 401     | Parameter check failed.                               |
  | OS_MMAP_ERROR                         | 1900001 | Failed to call mmap.                       |
  | OS_IOCTL_ERROR                        | 1900002 | Failed to execute **ioctl** with the shared memory file descriptor.|
  | WRITE_TO_ASHMEM_ERROR                 | 1900003 | Failed to write data to the shared memory.                       |
  | READ_FROM_ASHMEM_ERROR                | 1900004 | Failed to read data from the shared memory.                       |
  | ONLY_PROXY_OBJECT_PERMITTED_ERROR     | 1900005 | This operation is allowed only on the proxy object.                    |
  | ONLY_REMOTE_OBJECT_PERMITTED_ERROR    | 1900006 | This operation is allowed only on the remote object.                   |
  | COMMUNICATION_ERROR                   | 1900007 | Failed to communicate with the remote object over IPC.               |
  | PROXY_OR_REMOTE_OBJECT_INVALID_ERROR  | 1900008 | Invalid proxy or remote object.                 |
  | WRITE_DATA_TO_MESSAGE_SEQUENCE_ERROR  | 1900009 | Failed to write data to MessageSequence.                |
  | READ_DATA_FROM_MESSAGE_SEQUENCE_ERROR | 1900010 | Failed to read data from MessageSequence.                |
  | PARCEL_MEMORY_ALLOC_ERROR             | 1900011 | Failed to allocate memory during serialization.                   |
  | CALL_JS_METHOD_ERROR                  | 1900012 | Failed to invoke the JS callback.                         |
  | OS_DUP_ERROR                          | 1900013 | Failed to call dup.                        |

Z
zengyawen 已提交
40

A
Annie_wang 已提交
41
## MessageSequence<sup>9+</sup>
Z
zengyawen 已提交
42

A
Annie_wang 已提交
43
  Provides APIs for reading and writing data in specific format. During RPC, 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.
Z
zengyawen 已提交
44 45 46

### create

A
Annie_wang 已提交
47
  create(): MessageSequence
Z
zengyawen 已提交
48

A
Annie_wang 已提交
49
  Creates a **MessageSequence** object. This API is a static method.
Z
zengyawen 已提交
50

A
annie_wangli 已提交
51
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
52

A
Annie_wang 已提交
53
**Return value**
A
Annie_wang 已提交
54

A
Annie_wang 已提交
55 56 57
  | Type           | Description                           |
  | --------------- | ------------------------------- |
  | MessageSequence | **MessageSequence** object created.|
Z
zengyawen 已提交
58

A
Annie_wang 已提交
59
**Example**
A
annie_wangli 已提交
60

Z
zengyawen 已提交
61
  ```
A
Annie_wang 已提交
62
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
63 64 65 66 67 68 69
  console.log("RpcClient: data is " + data);
  ```

### reclaim

reclaim(): void

A
Annie_wang 已提交
70
Reclaims the **MessageSequence** object that is no longer used.
Z
zengyawen 已提交
71

A
annie_wangli 已提交
72
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
73

A
Annie_wang 已提交
74
**Example**
A
annie_wangli 已提交
75

Z
zengyawen 已提交
76
  ```
A
Annie_wang 已提交
77
  let reply = rpc.MessageSequence.create();
Z
zengyawen 已提交
78 79 80 81 82
  reply.reclaim();
  ```

### writeRemoteObject

A
Annie_wang 已提交
83
writeRemoteObject(object: [IRemoteObject](#iremoteobject)): void
Z
zengyawen 已提交
84

A
Annie_wang 已提交
85
Serializes a remote object and writes it to this **MessageSequence** object.
A
annie_wangli 已提交
86 87 88

**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
89
**Parameters**
A
Annie_wang 已提交
90

A
Annie_wang 已提交
91 92 93
  | Name| Type                           | Mandatory| Description                                     |
  | ------ | ------------------------------- | ---- | ----------------------------------------- |
  | object | [IRemoteObject](#iremoteobject) | Yes  | Remote object to serialize and write to the **MessageSequence** object.|
Z
zengyawen 已提交
94

A
Annie_wang 已提交
95
**Error codes**
A
Annie_wang 已提交
96

A
Annie_wang 已提交
97 98 99 100 101 102
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900008 | proxy or remote object is invalid |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
103

A
Annie_wang 已提交
104
**Example**
A
annie_wangli 已提交
105

Z
zengyawen 已提交
106 107 108 109 110 111
  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
  }
A
Annie_wang 已提交
112
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
113
  let testRemoteObject = new TestRemoteObject("testObject");
A
Annie_wang 已提交
114 115 116 117 118 119
  try {
      data.writeRemoteObject(testRemoteObject);
  } catch(error) {
      console.info("Rpc write remote object fail, errorCode " + error.code);
      console.info("Rpc write remote object fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
120 121 122 123 124 125
  ```

### readRemoteObject

readRemoteObject(): IRemoteObject

A
Annie_wang 已提交
126
Reads a 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.
Z
zengyawen 已提交
127

A
annie_wangli 已提交
128
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
129

A
Annie_wang 已提交
130
**Return value**
A
Annie_wang 已提交
131

A
Annie_wang 已提交
132 133
  | Type                           | Description              |
  | ------------------------------- | ------------------ |
A
annie_wangli 已提交
134
  | [IRemoteObject](#iremoteobject) | Remote object obtained.|
Z
zengyawen 已提交
135

A
Annie_wang 已提交
136 137 138 139 140 141 142 143 144
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900008 | proxy or remote object is invalid |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
145
**Example**
A
annie_wangli 已提交
146

Z
zengyawen 已提交
147 148 149 150 151 152
  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
  }
A
Annie_wang 已提交
153
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
154
  let testRemoteObject = new TestRemoteObject("testObject");
A
Annie_wang 已提交
155 156 157 158 159 160 161
  try {
      data.writeRemoteObject(testRemoteObject);
      let proxy = data.readRemoteObject();
  } catch(error) {
      console.info("Rpc write remote object fail, errorCode " + error.code);
      console.info("Rpc write remote object fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
162 163 164 165
  ```

### writeInterfaceToken

A
Annie_wang 已提交
166
writeInterfaceToken(token: string): void
Z
zengyawen 已提交
167

A
Annie_wang 已提交
168
Writes an interface token to this **MessageSequence** object. The remote object can use this interface token to verify the communication.
Z
zengyawen 已提交
169

A
annie_wangli 已提交
170
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
171

A
Annie_wang 已提交
172
**Parameters**
A
Annie_wang 已提交
173

A
Annie_wang 已提交
174 175 176
  | Name| Type  | Mandatory| Description              |
  | ------ | ------ | ---- | ------------------ |
  | token  | string | Yes  | Interface token to write.|
Z
zengyawen 已提交
177

A
Annie_wang 已提交
178
**Error codes**
A
Annie_wang 已提交
179

A
Annie_wang 已提交
180 181 182 183 184
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
185

A
Annie_wang 已提交
186
**Example**
A
annie_wangli 已提交
187

Z
zengyawen 已提交
188
  ```
A
Annie_wang 已提交
189 190 191 192 193 194 195
  let data = rpc.MessageSequence.create();
  try {
      data.writeInterfaceToken("aaa");
  } catch(error) {
      console.info("rpc write interface fail, errorCode " + error.code);
      console.info("rpc write interface fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
196 197 198 199 200 201
  ```

### readInterfaceToken

readInterfaceToken(): string

A
Annie_wang 已提交
202
Reads 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.
Z
zengyawen 已提交
203

A
annie_wangli 已提交
204
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
205

A
Annie_wang 已提交
206
**Return value**
A
Annie_wang 已提交
207

A
Annie_wang 已提交
208 209
  | Type  | Description                    |
  | ------ | ------------------------ |
A
annie_wangli 已提交
210
  | string | Interface token obtained.|
Z
zengyawen 已提交
211

A
Annie_wang 已提交
212 213 214 215 216 217 218 219 220
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ----- |
  | 1900010 | read data from message sequence failed |


A
Annie_wang 已提交
221
**Example**
A
annie_wangli 已提交
222

Z
zengyawen 已提交
223 224 225
  ```
  class Stub extends rpc.RemoteObject {
      onRemoteRequest(code, data, reply, option) {
A
Annie_wang 已提交
226 227 228 229 230 231 232
          try {
              let interfaceToken = data.readInterfaceToken();
              console.log("RpcServer: interfaceToken is " + interfaceToken);
          } catch(error) {
              console.info("RpcServer: read interfaceToken failed, errorCode " + error.code);
              console.info("RpcServer: read interfaceToken failed, errorMessage " + error.message);
          }
Z
zengyawen 已提交
233 234 235 236 237 238 239 240 241
          return true;
      }
  }
  ```

### getSize

getSize(): number

A
Annie_wang 已提交
242
Obtains the data size of this **MessageSequence** object.
Z
zengyawen 已提交
243

A
annie_wangli 已提交
244
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
245

A
Annie_wang 已提交
246
**Return value**
A
Annie_wang 已提交
247

A
Annie_wang 已提交
248 249 250
  | Type  | Description                                           |
  | ------ | ----------------------------------------------- |
  | number | Size of the **MessageSequence** object obtained, in bytes.|
Z
zengyawen 已提交
251

A
Annie_wang 已提交
252
**Example**
A
annie_wangli 已提交
253

Z
zengyawen 已提交
254
  ```
A
Annie_wang 已提交
255
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
256 257 258 259 260 261 262 263
  let size = data.getSize();
  console.log("RpcClient: size is " + size);
  ```

### getCapacity

getCapacity(): number

A
Annie_wang 已提交
264
Obtains the capacity of this **MessageSequence** object.
Z
zengyawen 已提交
265

A
annie_wangli 已提交
266
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
267

A
Annie_wang 已提交
268
**Return value**
A
Annie_wang 已提交
269

A
Annie_wang 已提交
270 271 272
  | Type  | Description|
  | ------ | ----- |
  | number | **MessageSequence** capacity obtained, in bytes.|
Z
zengyawen 已提交
273

A
Annie_wang 已提交
274
**Example**
A
annie_wangli 已提交
275

Z
zengyawen 已提交
276
  ```
A
Annie_wang 已提交
277
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
278 279 280 281 282 283
  let result = data.getCapacity();
  console.log("RpcClient: capacity is " + result);
  ```

### setSize

A
Annie_wang 已提交
284
setSize(size: number): void
Z
zengyawen 已提交
285

A
Annie_wang 已提交
286
Sets the size of data contained in this **MessageSequence** object.
Z
zengyawen 已提交
287

A
annie_wangli 已提交
288
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
289

A
Annie_wang 已提交
290
**Parameters**
A
Annie_wang 已提交
291

A
Annie_wang 已提交
292 293
  | Name| Type  | Mandatory| Description|
  | ------ | ------ | ---- | ------ |
A
annie_wangli 已提交
294
  | size | number | Yes| Data size to set, in bytes.|
Z
zengyawen 已提交
295

A
Annie_wang 已提交
296
**Example**
A
annie_wangli 已提交
297

Z
zengyawen 已提交
298
  ```
A
Annie_wang 已提交
299 300 301 302 303 304 305 306
  let data = rpc.MessageSequence.create();
  try {
      data.setSize(16);
      console.log("RpcClient: setSize is " + data.getSize());
  } catch(error) {
      console.info("rpc set size of MessageSequence fail, errorCode " + error.code);
      console.info("rpc set size of MessageSequence fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
307 308 309 310
  ```

### setCapacity

A
Annie_wang 已提交
311
setCapacity(size: number): void
Z
zengyawen 已提交
312

A
Annie_wang 已提交
313
Sets the storage capacity of this **MessageSequence** object.
Z
zengyawen 已提交
314

A
annie_wangli 已提交
315
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
316

A
Annie_wang 已提交
317
**Parameters**
A
Annie_wang 已提交
318

A
Annie_wang 已提交
319 320 321
  | Name| Type  | Mandatory| Description                                         |
  | ------ | ------ | ---- | --------------------------------------------- |
  | size   | number | Yes  | Storage capacity of the **MessageSequence** object to set, in bytes.|
Z
zengyawen 已提交
322

A
Annie_wang 已提交
323
**Error codes**
A
Annie_wang 已提交
324

A
Annie_wang 已提交
325 326 327 328 329
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------ |
  | 1900011 | parcel memory alloc failed |
Z
zengyawen 已提交
330

A
Annie_wang 已提交
331
**Example**
A
annie_wangli 已提交
332

Z
zengyawen 已提交
333
  ```
A
Annie_wang 已提交
334 335 336 337 338 339 340 341
  let data = rpc.MessageSequence.create();
  try {
      data.setCapacity(100);
      console.log("RpcClient: setCapacity is " + data.getCapacity());
  } catch(error) {
      console.info("rpc memory alloc fail, errorCode " + error.code);
      console.info("rpc memory alloc fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
342 343 344 345 346 347
  ```

### getWritableBytes

getWritableBytes(): number

A
Annie_wang 已提交
348
Obtains the writable capacity of this **MessageSequence** object.
Z
zengyawen 已提交
349

A
annie_wangli 已提交
350
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
351

A
Annie_wang 已提交
352
**Return value**
A
Annie_wang 已提交
353 354

  | Type| Description|
A
Annie_wang 已提交
355 356
  | ------ | ------ |
  | number | **MessageSequence** writable capacity obtained, in bytes.|
Z
zengyawen 已提交
357

A
Annie_wang 已提交
358
**Example**
A
annie_wangli 已提交
359

Z
zengyawen 已提交
360 361 362 363 364 365 366 367 368 369 370 371 372 373
  ```
  class Stub extends rpc.RemoteObject {
      onRemoteRequest(code, data, reply, option) {
          let getWritableBytes = data.getWritableBytes();
          console.log("RpcServer: getWritableBytes is " + getWritableBytes);
          return true;
      }
  }
  ```

### getReadableBytes

getReadableBytes(): number

A
Annie_wang 已提交
374
Obtains the readable capacity of this **MessageSequence** object.
Z
zengyawen 已提交
375

A
annie_wangli 已提交
376
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
377

A
Annie_wang 已提交
378
**Return value**
A
Annie_wang 已提交
379 380

  | Type| Description|
A
Annie_wang 已提交
381 382
  | ------ | ------- |
  | number | **MessageSequence** readable capacity obtained, in bytes.|
Z
zengyawen 已提交
383

A
Annie_wang 已提交
384
**Example**
A
annie_wangli 已提交
385

Z
zengyawen 已提交
386 387 388 389 390 391 392 393 394 395 396 397 398 399
  ```
  class Stub extends rpc.RemoteObject {
      onRemoteRequest(code, data, reply, option) {
          let result = data.getReadableBytes();
          console.log("RpcServer: getReadableBytes is " + result);
          return true;
      }
  }
  ```

### getReadPosition

getReadPosition(): number

A
Annie_wang 已提交
400
Obtains the read position of this **MessageSequence** object.
Z
zengyawen 已提交
401

A
annie_wangli 已提交
402
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
403

A
Annie_wang 已提交
404
**Return value**
A
Annie_wang 已提交
405 406

  | Type| Description|
A
Annie_wang 已提交
407 408
  | ------ | ------ |
  | number | Current read position of the **MessageSequence** object.|
Z
zengyawen 已提交
409

A
Annie_wang 已提交
410
**Example**
A
annie_wangli 已提交
411

Z
zengyawen 已提交
412
  ```
A
Annie_wang 已提交
413
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
414 415 416 417 418 419 420 421
  let readPos = data.getReadPosition();
  console.log("RpcClient: readPos is " + readPos);
  ```

### getWritePosition

getWritePosition(): number

A
Annie_wang 已提交
422
Obtains the write position of this **MessageSequence** object.
Z
zengyawen 已提交
423

A
annie_wangli 已提交
424
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
425

A
Annie_wang 已提交
426
**Return value**
A
Annie_wang 已提交
427 428

  | Type| Description|
A
Annie_wang 已提交
429 430
  | ------ | ----- |
  | number | Current write position of the **MessageSequence** object.|
Z
zengyawen 已提交
431

A
Annie_wang 已提交
432
**Example**
A
annie_wangli 已提交
433

Z
zengyawen 已提交
434
  ```
A
Annie_wang 已提交
435
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
436 437 438 439 440 441 442
  data.writeInt(10);
  let bwPos = data.getWritePosition();
  console.log("RpcClient: bwPos is " + bwPos);
  ```

### rewindRead

A
Annie_wang 已提交
443
rewindRead(pos: number): void
Z
zengyawen 已提交
444 445 446

Moves the read pointer to the specified position.

A
annie_wangli 已提交
447
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
448

A
Annie_wang 已提交
449
**Parameters**
A
Annie_wang 已提交
450 451

  | Name| Type| Mandatory| Description|
A
Annie_wang 已提交
452 453
  | ------ | ------ | ---- | ------- |
  | pos    | number | Yes  | Position from which data is to read.|
Z
zengyawen 已提交
454

A
Annie_wang 已提交
455
**Example**
A
annie_wangli 已提交
456

Z
zengyawen 已提交
457
  ```
A
Annie_wang 已提交
458
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
459
  data.writeInt(12);
A
Annie_wang 已提交
460
  data.writeString("sequence");
Z
zengyawen 已提交
461 462
  let number = data.readInt();
  console.log("RpcClient: number is " + number);
A
Annie_wang 已提交
463 464 465 466 467 468
  try {
      data.rewindRead(0);
  } catch(error) {
      console.info("rpc rewind read data fail, errorCode " + error.code);
      console.info("rpc rewind read data fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
469 470 471 472 473 474
  let number2 = data.readInt();
  console.log("RpcClient: rewindRead is " + number2);
  ```

### rewindWrite

A
Annie_wang 已提交
475
rewindWrite(pos: number): void
Z
zengyawen 已提交
476 477 478

Moves the write pointer to the specified position.

A
annie_wangli 已提交
479
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
480

A
Annie_wang 已提交
481
**Parameters**
A
Annie_wang 已提交
482 483

  | Name| Type| Mandatory| Description|
A
Annie_wang 已提交
484 485
  | ------ | ------ | ---- | ----- |
  | pos    | number | Yes  | Position from which data is to write.|
Z
zengyawen 已提交
486

A
Annie_wang 已提交
487
**Example**
A
annie_wangli 已提交
488

Z
zengyawen 已提交
489
  ```
A
Annie_wang 已提交
490
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
491
  data.writeInt(4);
A
Annie_wang 已提交
492 493 494 495 496 497
  try {
      data.rewindWrite(0);
  } catch(error) {
      console.info("rpc rewind read data fail, errorCode " + error.code);
      console.info("rpc rewind read data fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
498 499 500 501 502 503 504
  data.writeInt(5);
  let number = data.readInt();
  console.log("RpcClient: rewindWrite is: " + number);
  ```

### writeByte

A
Annie_wang 已提交
505
writeByte(val: number): void
Z
zengyawen 已提交
506

A
Annie_wang 已提交
507
Writes a Byte value to this **MessageSequence** object.
Z
zengyawen 已提交
508

A
annie_wangli 已提交
509
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
510

A
Annie_wang 已提交
511
**Parameters**
A
Annie_wang 已提交
512

A
Annie_wang 已提交
513 514
  | Name| Type  | Mandatory| Description|
  | ----- | ------ | ---- | ----- |
A
annie_wangli 已提交
515
  | val | number | Yes| Byte value to write.|
Z
zengyawen 已提交
516

A
Annie_wang 已提交
517
**Error codes**
A
Annie_wang 已提交
518

A
Annie_wang 已提交
519 520 521 522 523
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
524

A
Annie_wang 已提交
525
**Example**
A
annie_wangli 已提交
526

Z
zengyawen 已提交
527
  ```
A
Annie_wang 已提交
528 529 530 531 532 533 534
  let data = rpc.MessageSequence.create();
  try {
      data.writeByte(2);
  } catch(error) {
    console.info("rpc write byte fail, errorCode " + error.code);
    console.info("rpc write byte fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
535 536 537 538 539 540
  ```

### readByte

readByte(): number

A
Annie_wang 已提交
541
Reads the Byte value from this **MessageSequence** object.
Z
zengyawen 已提交
542

A
annie_wangli 已提交
543
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
544

A
Annie_wang 已提交
545
**Return value**
A
Annie_wang 已提交
546

A
Annie_wang 已提交
547 548
  | Type  | Description|
  | ------ | ----- |
A
annie_wangli 已提交
549
  | number | Byte value read.|
Z
zengyawen 已提交
550

A
Annie_wang 已提交
551 552 553 554 555 556 557 558
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | --------  |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
559
**Example**
A
annie_wangli 已提交
560

Z
zengyawen 已提交
561
  ```
A
Annie_wang 已提交
562 563 564 565 566 567 568 569 570 571 572 573 574 575
  let data = rpc.MessageSequence.create();
  try {
      data.writeByte(2);
  } catch(error) {
    console.info("rpc write byte fail, errorCode " + error.code);
    console.info("rpc write byte fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readByte();
      console.log("RpcClient: readByte is: " + ret);
  } catch(error) {
    console.info("rpc write byte fail, errorCode " + error.code);
    console.info("rpc write byte fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
576 577 578 579
  ```

### writeShort

A
Annie_wang 已提交
580
writeShort(val: number): void
Z
zengyawen 已提交
581

A
Annie_wang 已提交
582
Writes a short integer to this **MessageSequence** object.
Z
zengyawen 已提交
583

A
annie_wangli 已提交
584
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
585

A
Annie_wang 已提交
586
**Parameters**
A
Annie_wang 已提交
587

A
Annie_wang 已提交
588 589 590
  | Name| Type  | Mandatory| Description|
  | ------ | ------ | --- | --- |
  | val | number | Yes| Short integer to write.|
Z
zengyawen 已提交
591

A
Annie_wang 已提交
592
**Error codes**
A
Annie_wang 已提交
593

A
Annie_wang 已提交
594 595 596 597 598
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------ |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
599

A
Annie_wang 已提交
600
**Example**
A
annie_wangli 已提交
601

Z
zengyawen 已提交
602
  ```
A
Annie_wang 已提交
603 604 605 606 607 608 609
  let data = rpc.MessageSequence.create();
  try {
      data.writeShort(8);
  } catch(error) {
      console.info("rpc write short fail, errorCode " + error.code);
      console.info("rpc write short fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
610 611 612 613 614 615
  ```

### readShort

readShort(): number

A
Annie_wang 已提交
616
Reads the short integer from this **MessageSequence** object.
Z
zengyawen 已提交
617

A
annie_wangli 已提交
618
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
619

A
Annie_wang 已提交
620
**Return value**
A
Annie_wang 已提交
621

A
Annie_wang 已提交
622 623 624 625 626 627 628 629 630 631 632
  | Type  | Description          |
  | ------ | -------------- |
  | number | Short integer read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
633

A
Annie_wang 已提交
634
**Example**
A
annie_wangli 已提交
635

Z
zengyawen 已提交
636
  ```
A
Annie_wang 已提交
637 638 639 640 641 642 643 644 645 646 647 648 649 650
  let data = rpc.MessageSequence.create();
  try {
      data.writeShort(8);
  } catch(error) {
      console.info("rpc write short fail, errorCode " + error.code);
      console.info("rpc write short fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readShort(8);
  } catch(error) {
      console.info("rpc read short fail, errorCode " + error.code);
      console.info("rpc read short fail, errorMessage" + error.message);
  }
  console.log("RpcClient: readByte is: " + ret);
Z
zengyawen 已提交
651 652 653 654
  ```

### writeInt

A
Annie_wang 已提交
655
writeInt(val: number): void
Z
zengyawen 已提交
656

A
Annie_wang 已提交
657
Writes an integer to this **MessageSequence** object.
Z
zengyawen 已提交
658

A
annie_wangli 已提交
659
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
660

A
Annie_wang 已提交
661
**Parameters**
A
Annie_wang 已提交
662

A
Annie_wang 已提交
663 664 665
  | Name| Type  | Mandatory| Description            |
  | ------ | ------ | ---- | ---------------- |
  | val    | number | Yes  | Integer to write.|
Z
zengyawen 已提交
666

A
Annie_wang 已提交
667
**Error codes**
A
Annie_wang 已提交
668

A
Annie_wang 已提交
669 670 671 672 673
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
674

A
Annie_wang 已提交
675
**Example**
A
annie_wangli 已提交
676

Z
zengyawen 已提交
677
  ```
A
Annie_wang 已提交
678 679 680 681 682 683 684
  let data = rpc.MessageSequence.create();
  try {
      data.writeInt(10);
  } catch(error) {
      console.info("rpc write int fail, errorCode " + error.code);
      console.info("rpc write int fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
685 686 687 688 689 690
  ```

### readInt

readInt(): number

A
Annie_wang 已提交
691
Reads the integer from this **MessageSequence** object.
Z
zengyawen 已提交
692

A
annie_wangli 已提交
693
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
694

A
Annie_wang 已提交
695
**Return value**
A
Annie_wang 已提交
696

A
Annie_wang 已提交
697 698 699 700 701 702 703 704 705 706 707
  | Type  | Description        |
  | ------ | ------------ |
  | number | Integer read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
708

A
Annie_wang 已提交
709
**Example**
A
annie_wangli 已提交
710

Z
zengyawen 已提交
711
  ```
A
Annie_wang 已提交
712 713 714 715 716 717 718 719 720 721 722 723 724 725
  let data = rpc.MessageSequence.create();
  try {
      data.writeInt(10);
  } catch(error) {
      console.info("rpc write int fail, errorCode " + error.code);
      console.info("rpc write int fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readInt();
      console.log("RpcClient: readInt is " + ret);
  } catch(error) {
      console.info("rpc read int fail, errorCode " + error.code);
      console.info("rpc read int fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
726 727 728 729
  ```

### writeLong

A
Annie_wang 已提交
730
writeLong(val: number): void
Z
zengyawen 已提交
731

A
Annie_wang 已提交
732
Writes a long integer to this **MessageSequence** object.
Z
zengyawen 已提交
733

A
annie_wangli 已提交
734
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
735

A
Annie_wang 已提交
736
**Parameters**
A
Annie_wang 已提交
737

A
Annie_wang 已提交
738 739 740
  | Name| Type  | Mandatory| Description            |
  | ------ | ------ | ---- | ---------------- |
  | val    | number | Yes  | Long integer to write.|
Z
zengyawen 已提交
741

A
Annie_wang 已提交
742
**Error codes**
A
Annie_wang 已提交
743

A
Annie_wang 已提交
744 745 746 747 748
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
749

A
Annie_wang 已提交
750
**Example**
A
annie_wangli 已提交
751

Z
zengyawen 已提交
752
  ```
A
Annie_wang 已提交
753 754 755 756 757 758 759
  let data = rpc.MessageSequence.create();
  try {
      data.writeLong(10000);
  } catch(error) {
      console.info("rpc write long fail, errorCode " + error.code);
      console.info("rpc write long fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
760 761 762 763 764 765
  ```

### readLong

readLong(): number

A
Annie_wang 已提交
766
Reads the long integer from this **MessageSequence** object.
Z
zengyawen 已提交
767

A
annie_wangli 已提交
768
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
769

A
Annie_wang 已提交
770
**Return value**
A
Annie_wang 已提交
771

A
Annie_wang 已提交
772 773 774 775 776 777 778 779 780 781 782
  | Type  | Description          |
  | ------ | -------------- |
  | number | Long integer read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
783

A
Annie_wang 已提交
784
**Example**
A
annie_wangli 已提交
785

Z
zengyawen 已提交
786
  ```
A
Annie_wang 已提交
787 788 789 790 791 792 793 794 795 796 797 798 799 800
  let data = rpc.MessageSequence.create();
  try {
      data.writeLong(10000);
  } catch(error) {
      console.info("rpc write long fail, errorCode " + error.code);
      console.info("rpc write long fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readLong();
      console.log("RpcClient: readLong is " + ret);
  } catch(error) {
      console.info("rpc read long fail, errorCode " + error.code);
      console.info("rpc read long fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
801 802 803 804
  ```

### writeFloat

A
Annie_wang 已提交
805
writeFloat(val: number): void
Z
zengyawen 已提交
806

A
Annie_wang 已提交
807
Writes a floating-point number to this **MessageSequence** object.
Z
zengyawen 已提交
808

A
annie_wangli 已提交
809
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
810

A
Annie_wang 已提交
811
**Parameters**
A
Annie_wang 已提交
812 813

  | Name| Type| Mandatory| Description|
A
Annie_wang 已提交
814 815
  | ----- | ---- | ---- | ----- |
  | val | number | Yes| Floating-point number to write.|
Z
zengyawen 已提交
816

A
Annie_wang 已提交
817
**Error codes**
A
Annie_wang 已提交
818

A
Annie_wang 已提交
819 820 821 822 823
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
824

A
Annie_wang 已提交
825
**Example**
A
annie_wangli 已提交
826

Z
zengyawen 已提交
827
  ```
A
Annie_wang 已提交
828 829 830 831 832 833 834
  let data = rpc.MessageSequence.create();
  try {
      data.writeFloat(1.2);
  } catch(error) {
      console.info("rpc write float fail, errorCode " + error.code);
      console.info("rpc write float fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
835 836 837 838 839 840
  ```

### readFloat

readFloat(): number

A
Annie_wang 已提交
841
Reads the floating-pointer number from this **MessageSequence** object.
Z
zengyawen 已提交
842

A
annie_wangli 已提交
843
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
844

A
Annie_wang 已提交
845
**Return value**
A
Annie_wang 已提交
846

A
Annie_wang 已提交
847 848 849 850 851 852 853 854 855 856 857
  | Type  | Description        |
  | ------ | ------------ |
  | number | Floating-point number read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
858

A
Annie_wang 已提交
859
**Example**
A
annie_wangli 已提交
860

Z
zengyawen 已提交
861
  ```
A
Annie_wang 已提交
862 863 864 865 866 867 868 869 870 871 872 873 874 875
  let data = rpc.MessageSequence.create();
  try {
      data.writeFloat(1.2);
  } catch(error) {
      console.info("rpc write float fail, errorCode " + error.code);
      console.info("rpc write float fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readFloat();
      console.log("RpcClient: readFloat is " + ret);
  } catch(error) {
      console.info("rpc read float fail, errorCode " + error.code);
      console.info("rpc read float fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
876 877 878 879
  ```

### writeDouble

A
Annie_wang 已提交
880
writeDouble(val: number): void
Z
zengyawen 已提交
881

A
Annie_wang 已提交
882
Writes a double-precision floating-point number to this **MessageSequence** object.
Z
zengyawen 已提交
883

A
annie_wangli 已提交
884
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
885

A
Annie_wang 已提交
886
**Parameters**
A
Annie_wang 已提交
887 888

  | Name| Type| Mandatory| Description|
A
Annie_wang 已提交
889 890
  | ------ | ------ | ---- | ------ |
  | val  number | Yes| Double-precision floating-point number to write.|
Z
zengyawen 已提交
891

A
Annie_wang 已提交
892
**Error codes**
A
Annie_wang 已提交
893

A
Annie_wang 已提交
894 895 896 897 898
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
899

A
Annie_wang 已提交
900
**Example**
A
annie_wangli 已提交
901

Z
zengyawen 已提交
902
  ```
A
Annie_wang 已提交
903 904 905 906 907 908 909
  let data = rpc.MessageSequence.create();
  try {
      data.writeDouble(10.2);
  } catch(error) {
      console.info("rpc read float fail, errorCode " + error.code);
      console.info("rpc read float fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
910 911 912 913 914 915
  ```

### readDouble

readDouble(): number

A
Annie_wang 已提交
916
Reads the double-precision floating-point number from this **MessageSequence** object.
Z
zengyawen 已提交
917

A
annie_wangli 已提交
918
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
919

A
Annie_wang 已提交
920
**Return value**
A
Annie_wang 已提交
921

A
Annie_wang 已提交
922 923 924 925 926 927 928 929 930 931 932
  | Type  | Description              |
  | ------ | ------------------ |
  | number | Double-precision floating-point number read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
933

A
Annie_wang 已提交
934
**Example**
A
annie_wangli 已提交
935

Z
zengyawen 已提交
936
  ```
A
Annie_wang 已提交
937 938 939 940 941 942 943 944 945 946 947 948 949 950
  let data = rpc.MessageSequence.create();
  try {
      data.writeDouble(10.2);
  } catch(error) {
      console.info("rpc write double fail, errorCode " + error.code);
      console.info("rpc write double fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readDouble();
      console.log("RpcClient: readDouble is " + ret);
  } catch(error) {
      console.info("rpc read double fail, errorCode " + error.code);
      console.info("rpc read double fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
951 952 953 954
  ```

### writeBoolean

A
Annie_wang 已提交
955
writeBoolean(val: boolean): void
Z
zengyawen 已提交
956

A
Annie_wang 已提交
957
Writes a Boolean value to this **MessageSequence** object.
Z
zengyawen 已提交
958

A
annie_wangli 已提交
959
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
960

A
Annie_wang 已提交
961
**Parameters**
A
Annie_wang 已提交
962

A
Annie_wang 已提交
963 964 965
  | Name| Type   | Mandatory| Description            |
  | ------ | ------- | ---- | ---------------- |
  | val    | boolean | Yes  | Boolean value to write.|
Z
zengyawen 已提交
966

A
Annie_wang 已提交
967
**Error codes**
A
Annie_wang 已提交
968

A
Annie_wang 已提交
969 970 971 972 973
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
974

A
Annie_wang 已提交
975
**Example**
A
annie_wangli 已提交
976

Z
zengyawen 已提交
977
  ```
A
Annie_wang 已提交
978 979 980 981 982 983 984
  let data = rpc.MessageSequence.create();
  try {
      data.writeBoolean(false);
  } catch(error) {
      console.info("rpc write boolean fail, errorCode " + error.code);
      console.info("rpc write boolean fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
985 986 987 988 989 990
  ```

### readBoolean

readBoolean(): boolean

A
Annie_wang 已提交
991
Reads the Boolean value from this **MessageSequence** object.
Z
zengyawen 已提交
992

A
annie_wangli 已提交
993
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
994

A
Annie_wang 已提交
995
**Return value**
A
Annie_wang 已提交
996

A
Annie_wang 已提交
997 998
  | Type   | Description                |
  | ------- | -------------------- |
A
annie_wangli 已提交
999
  | boolean | Boolean value read.|
Z
zengyawen 已提交
1000

A
Annie_wang 已提交
1001 1002 1003 1004 1005 1006 1007 1008
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
1009
**Example**
A
annie_wangli 已提交
1010

Z
zengyawen 已提交
1011
  ```
A
Annie_wang 已提交
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
  let data = rpc.MessageSequence.create();
  try {
      data.writeBoolean(false);
  } catch(error) {
      console.info("rpc write boolean fail, errorCode " + error.code);
      console.info("rpc write boolean fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readBoolean();
      console.log("RpcClient: readBoolean is " + ret);
  } catch(error) {
      console.info("rpc read boolean fail, errorCode " + error.code);
      console.info("rpc read boolean fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1026 1027 1028 1029
  ```

### writeChar

A
Annie_wang 已提交
1030
writeChar(val: number): void
Z
zengyawen 已提交
1031

A
Annie_wang 已提交
1032
Writes a character to this **MessageSequence** object.
Z
zengyawen 已提交
1033

A
annie_wangli 已提交
1034
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1035

A
Annie_wang 已提交
1036
**Parameters**
A
Annie_wang 已提交
1037

A
Annie_wang 已提交
1038 1039 1040
  | Name| Type  | Mandatory| Description                |
  | ------ | ------ | ---- | -------------------- |
  | val    | number | Yes  | Single character to write.|
Z
zengyawen 已提交
1041

A
Annie_wang 已提交
1042
**Error codes**
A
Annie_wang 已提交
1043

A
Annie_wang 已提交
1044 1045 1046 1047 1048
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1049

A
Annie_wang 已提交
1050
**Example**
A
annie_wangli 已提交
1051

Z
zengyawen 已提交
1052
  ```
A
Annie_wang 已提交
1053 1054 1055 1056 1057 1058 1059
  let data = rpc.MessageSequence.create();
  try {
      data.writeChar(97);
  } catch(error) {
      console.info("rpc write char fail, errorCode " + error.code);
      console.info("rpc write char fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1060 1061 1062 1063 1064 1065
  ```

### readChar

readChar(): number

A
Annie_wang 已提交
1066
Reads the character from this **MessageSequence** object.
Z
zengyawen 已提交
1067

A
annie_wangli 已提交
1068
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1069

A
Annie_wang 已提交
1070
**Return value**
A
Annie_wang 已提交
1071

A
Annie_wang 已提交
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
  | Type  | Description|
  | ------ | ---- |
  | number | Character read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------ | --------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1083

A
Annie_wang 已提交
1084
**Example**
A
annie_wangli 已提交
1085

Z
zengyawen 已提交
1086
  ```
A
Annie_wang 已提交
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
  let data = rpc.MessageSequence.create();
  try {
      data.writeChar(97);
  } catch(error) {
      console.info("rpc write char fail, errorCode " + error.code);
      console.info("rpc write char fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readChar();
      console.log("RpcClient: readChar is " + ret);
  } catch(error) {
      console.info("rpc read char fail, errorCode " + error.code);
      console.info("rpc read char fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1101 1102 1103 1104
  ```

### writeString

A
Annie_wang 已提交
1105
writeString(val: string): void
Z
zengyawen 已提交
1106

A
Annie_wang 已提交
1107
Writes a string to this **MessageSequence** object.
Z
zengyawen 已提交
1108

A
annie_wangli 已提交
1109
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1110

A
Annie_wang 已提交
1111
**Parameters**
A
Annie_wang 已提交
1112

A
Annie_wang 已提交
1113 1114 1115
  | Name| Type  | Mandatory| Description                                     |
  | ------ | ------ | ---- | ----------------------------------------- |
  | val    | string | Yes  | String to write. The length of the string must be less than 40960 bytes.|
Z
zengyawen 已提交
1116

A
Annie_wang 已提交
1117
**Error codes**
A
Annie_wang 已提交
1118

A
Annie_wang 已提交
1119 1120 1121 1122 1123
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1124

A
Annie_wang 已提交
1125
**Example**
A
annie_wangli 已提交
1126

Z
zengyawen 已提交
1127
  ```
A
Annie_wang 已提交
1128 1129 1130 1131 1132 1133 1134
  let data = rpc.MessageSequence.create();
  try {
      data.writeString('abc');
  } catch(error) {
      console.info("rpc write string fail, errorCode " + error.code);
      console.info("rpc write string fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1135 1136 1137 1138 1139 1140
  ```

### readString

readString(): string

A
Annie_wang 已提交
1141
Reads the string from this **MessageSequence** object.
Z
zengyawen 已提交
1142

A
annie_wangli 已提交
1143
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1144

A
Annie_wang 已提交
1145
**Return value**
A
Annie_wang 已提交
1146

A
Annie_wang 已提交
1147 1148
  | Type  | Description          |
  | ------ | -------------- |
A
Annie_wang 已提交
1149
  | string | String read.|
Z
zengyawen 已提交
1150

A
Annie_wang 已提交
1151 1152 1153 1154 1155 1156 1157 1158
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
1159
**Example**
A
annie_wangli 已提交
1160

Z
zengyawen 已提交
1161
  ```
A
Annie_wang 已提交
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
  let data = rpc.MessageSequence.create();
  try {
      data.writeString('abc');
  } catch(error) {
      console.info("rpc write string fail, errorCode " + error.code);
      console.info("rpc write string fail, errorMessage" + error.message);
  }
  try {
      let ret = data.readString();
      console.log("RpcClient: readString is " + ret);
  } catch(error) {
      console.info("rpc read string fail, errorCode " + error.code);
      console.info("rpc read string fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1176 1177
  ```

A
Annie_wang 已提交
1178
### writeParcelable
Z
zengyawen 已提交
1179

A
Annie_wang 已提交
1180
writeParcelable(val: Parcelable): void
Z
zengyawen 已提交
1181

A
Annie_wang 已提交
1182
Writes a **Parcelable** object to this **MessageSequence** object.
Z
zengyawen 已提交
1183

A
annie_wangli 已提交
1184
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1185

A
Annie_wang 已提交
1186
**Parameters**
A
Annie_wang 已提交
1187 1188

  | Name| Type| Mandatory| Description|
A
Annie_wang 已提交
1189 1190
  | ------ | --------- | ---- | ------ |
  | val    | Parcelable | Yes  | **Parcelable** object to write.|
Z
zengyawen 已提交
1191

A
Annie_wang 已提交
1192
**Error codes**
A
Annie_wang 已提交
1193

A
Annie_wang 已提交
1194 1195 1196 1197 1198
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1199

A
Annie_wang 已提交
1200
**Example**
A
annie_wangli 已提交
1201

Z
zengyawen 已提交
1202 1203
  ```
  class MySequenceable {
A
Annie_wang 已提交
1204 1205 1206
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
1207
          this.num = num;
A
Annie_wang 已提交
1208
          this.str = str;
Z
zengyawen 已提交
1209
      }
A
Annie_wang 已提交
1210 1211 1212
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
Z
zengyawen 已提交
1213 1214
          return true;
      }
A
Annie_wang 已提交
1215 1216 1217
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
Z
zengyawen 已提交
1218 1219 1220
          return true;
      }
  }
A
Annie_wang 已提交
1221 1222 1223 1224 1225 1226 1227 1228
  let parcelable = new MySequenceable(1, "aaa");
  let data = rpc.MessageSequence.create();
  try {
      data.writeParcelable(parcelable);
  } catch(error) {
      console.info("rpc write parcelable fail, errorCode " + error.code);
      console.info("rpc write parcelable fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1229 1230
  ```

A
Annie_wang 已提交
1231
### readParcelable
Z
zengyawen 已提交
1232

A
Annie_wang 已提交
1233
readParcelable(dataIn: Parcelable): void
Z
zengyawen 已提交
1234

A
Annie_wang 已提交
1235
Reads a **Parcelable** object from this **MessageSequence** object to the specified object (**dataIn**).
Z
zengyawen 已提交
1236

A
annie_wangli 已提交
1237
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1238

A
Annie_wang 已提交
1239
**Parameters**
A
Annie_wang 已提交
1240

A
Annie_wang 已提交
1241 1242 1243
  | Name| Type                     | Mandatory| Description                                     |
  | ------ | ------------------------- | ---- | ----------------------------------------- |
  | dataIn | Parcelable | Yes  | **Parcelable** object to read.|
Z
zengyawen 已提交
1244

A
Annie_wang 已提交
1245
**Error codes**
A
Annie_wang 已提交
1246

A
Annie_wang 已提交
1247 1248 1249 1250 1251 1252
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900010 | read data from message sequence failed |
  | 1900012 | call js callback function failed |
Z
zengyawen 已提交
1253

A
Annie_wang 已提交
1254
**Example**
A
annie_wangli 已提交
1255

Z
zengyawen 已提交
1256 1257
  ```
  class MySequenceable {
A
Annie_wang 已提交
1258 1259 1260
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
1261
          this.num = num;
A
Annie_wang 已提交
1262
          this.str = str;
Z
zengyawen 已提交
1263
      }
A
Annie_wang 已提交
1264 1265 1266
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
Z
zengyawen 已提交
1267 1268
          return true;
      }
A
Annie_wang 已提交
1269 1270 1271
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
Z
zengyawen 已提交
1272 1273 1274
          return true;
      }
  }
A
Annie_wang 已提交
1275 1276 1277
  let parcelable = new MySequenceable(1, "aaa");
  let data = rpc.MessageSequence.create();
  data.writeParcelable(parcelable);
Z
zengyawen 已提交
1278
  let ret = new MySequenceable(0, "");
A
Annie_wang 已提交
1279 1280 1281 1282 1283 1284
  try {
      data.readParcelable(ret);
  }catch(error) {
      console.info("rpc read parcelable fail, errorCode " + error.code);
      console.info("rpc read parcelable fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1285 1286 1287 1288
  ```

### writeByteArray

A
Annie_wang 已提交
1289
writeByteArray(byteArray: number[]): void
Z
zengyawen 已提交
1290

A
Annie_wang 已提交
1291
Writes a byte array to this **MessageSequence** object.
Z
zengyawen 已提交
1292

A
annie_wangli 已提交
1293
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1294

A
Annie_wang 已提交
1295
**Parameters**
A
Annie_wang 已提交
1296

A
Annie_wang 已提交
1297 1298 1299
  | Name   | Type    | Mandatory| Description              |
  | --------- | -------- | ---- | ------------------ |
  | byteArray | number[] | Yes  | Byte array to write.|
Z
zengyawen 已提交
1300

A
Annie_wang 已提交
1301
**Error codes**
A
Annie_wang 已提交
1302

A
Annie_wang 已提交
1303 1304 1305 1306 1307
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1308

A
Annie_wang 已提交
1309
**Example**
A
annie_wangli 已提交
1310

Z
zengyawen 已提交
1311
  ```
A
Annie_wang 已提交
1312
  let data = rpc.MessageSequence.create();
A
Annie_wang 已提交
1313
  let ByteArrayVar = [1, 2, 3, 4, 5];
A
Annie_wang 已提交
1314 1315 1316 1317 1318 1319
  try {
      data.writeByteArray(ByteArrayVar);
  } catch(error) {
      console.info("rpc write byteArray fail, errorCode " + error.code);
      console.info("rpc write byteArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1320 1321 1322 1323
  ```

### readByteArray

A
Annie_wang 已提交
1324
readByteArray(dataIn: number[]): void
Z
zengyawen 已提交
1325

A
Annie_wang 已提交
1326
Reads a byte array from this **MessageSequence** object.
Z
zengyawen 已提交
1327

A
annie_wangli 已提交
1328
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1329

A
Annie_wang 已提交
1330
**Parameters**
A
Annie_wang 已提交
1331

A
Annie_wang 已提交
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
  | Name| Type    | Mandatory| Description              |
  | ------ | -------- | ---- | ------------------ |
  | dataIn | number[] | Yes  | Byte array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1343

A
Annie_wang 已提交
1344
**Example**
A
annie_wangli 已提交
1345

Z
zengyawen 已提交
1346
  ```
A
Annie_wang 已提交
1347
  let data = rpc.MessageSequence.create();
A
Annie_wang 已提交
1348
  let ByteArrayVar = [1, 2, 3, 4, 5];
A
Annie_wang 已提交
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
  try {
      data.writeByteArray(ByteArrayVar);
  } catch(error) {
      console.info("rpc write byteArray fail, errorCode " + error.code);
      console.info("rpc write byteArray fail, errorMessage" + error.message);
  }
  try {
      let array = new Array(5);
      data.readByteArray(array);
  } catch(error) {
      console.info("rpc write byteArray fail, errorCode " + error.code);
      console.info("rpc write byteArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1362 1363 1364 1365 1366 1367
  ```

### readByteArray

readByteArray(): number[]

A
Annie_wang 已提交
1368
Reads the byte array from this **MessageSequence** object.
Z
zengyawen 已提交
1369

A
annie_wangli 已提交
1370
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1371

A
Annie_wang 已提交
1372
**Return value**
A
Annie_wang 已提交
1373

A
Annie_wang 已提交
1374 1375
  | Type    | Description          |
  | -------- | -------------- |
A
Annie_wang 已提交
1376
  | number[] | Byte array read.|
Z
zengyawen 已提交
1377

A
Annie_wang 已提交
1378 1379 1380 1381 1382 1383 1384 1385
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
1386
**Example**
A
annie_wangli 已提交
1387

Z
zengyawen 已提交
1388
  ```
A
Annie_wang 已提交
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
  let data = rpc.MessageSequence.create();
  let byteArrayVar = [1, 2, 3, 4, 5];
  try {
      data.writeByteArray(byteArrayVar);
  } catch(error) {
      console.info("rpc write byteArray fail, errorCode " + error.code);
      console.info("rpc write byteArray fail, errorMessage" + error.message);
  }
  try {
      let array = data.readByteArray();
      console.log("RpcClient: readByteArray is " + array);
  } catch(error) {
      console.info("rpc read byteArray fail, errorCode " + error.code);
      console.info("rpc read byteArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1404 1405 1406 1407
  ```

### writeShortArray

A
Annie_wang 已提交
1408
writeShortArray(shortArray: number[]): void
Z
zengyawen 已提交
1409

A
Annie_wang 已提交
1410
Writes a short array to this **MessageSequence** object.
Z
zengyawen 已提交
1411

A
annie_wangli 已提交
1412
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1413

A
Annie_wang 已提交
1414
**Parameters**
A
Annie_wang 已提交
1415

A
Annie_wang 已提交
1416 1417 1418
  | Name    | Type    | Mandatory| Description                |
  | ---------- | -------- | ---- | -------------------- |
  | shortArray | number[] | Yes  | Short array to write.|
Z
zengyawen 已提交
1419

A
Annie_wang 已提交
1420
**Error codes**
A
Annie_wang 已提交
1421

A
Annie_wang 已提交
1422 1423 1424 1425 1426
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ----- | ----- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1427

A
Annie_wang 已提交
1428
**Example**
A
annie_wangli 已提交
1429

Z
zengyawen 已提交
1430
  ```
A
Annie_wang 已提交
1431 1432 1433 1434 1435 1436 1437
  let data = rpc.MessageSequence.create();
  try {
      data.writeShortArray([11, 12, 13]);
  } catch(error) {
      console.info("rpc read byteArray fail, errorCode " + error.code);
      console.info("rpc read byteArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1438 1439 1440 1441
  ```

### readShortArray

A
Annie_wang 已提交
1442
readShortArray(dataIn: number[]): void
Z
zengyawen 已提交
1443

A
Annie_wang 已提交
1444
Reads a short array from this **MessageSequence** object.
Z
zengyawen 已提交
1445

A
annie_wangli 已提交
1446
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1447

A
Annie_wang 已提交
1448
**Parameters**
A
Annie_wang 已提交
1449

A
Annie_wang 已提交
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
  | Name| Type    | Mandatory| Description                |
  | ------ | -------- | ---- | -------------------- |
  | dataIn | number[] | Yes  | Short array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------ | ------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1461

A
Annie_wang 已提交
1462
**Example**
A
annie_wangli 已提交
1463

Z
zengyawen 已提交
1464
  ```
A
Annie_wang 已提交
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478
  let data = rpc.MessageSequence.create();
  try {
      data.writeShortArray([11, 12, 13]);
  } catch(error) {
      console.info("rpc write shortArray fail, errorCode " + error.code);
      console.info("rpc write shortArray fail, errorMessage" + error.message);
  }
  try {
      let array = new Array(3);
      data.readShortArray(array);
  } catch(error) {
      console.info("rpc read shortArray fail, errorCode " + error.code);
      console.info("rpc read shortArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1479 1480 1481 1482 1483 1484
  ```

### readShortArray

readShortArray(): number[]

A
Annie_wang 已提交
1485
Reads the short array from this **MessageSequence** object.
Z
zengyawen 已提交
1486

A
annie_wangli 已提交
1487
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1488

A
Annie_wang 已提交
1489
**Return value**
A
Annie_wang 已提交
1490

A
Annie_wang 已提交
1491 1492
  | Type    | Description            |
  | -------- | ---------------- |
A
Annie_wang 已提交
1493
  | number[] | Short array read.|
Z
zengyawen 已提交
1494

A
Annie_wang 已提交
1495 1496 1497 1498 1499 1500 1501 1502
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
1503
**Example**
A
annie_wangli 已提交
1504

Z
zengyawen 已提交
1505
  ```
A
Annie_wang 已提交
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
  let data = rpc.MessageSequence.create();
  try {
      data.writeShortArray([11, 12, 13]);
  } catch(error) {
      console.info("rpc write shortArray fail, errorCode " + error.code);
      console.info("rpc write shortArray fail, errorMessage" + error.message);
  }
  try {
      let array = data.readShortArray();
      console.log("RpcClient: readShortArray is " + array);
  } catch(error) {
      console.info("rpc read shortArray fail, errorCode " + error.code);
      console.info("rpc read shortArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1520 1521 1522 1523
  ```

### writeIntArray

A
Annie_wang 已提交
1524
writeIntArray(intArray: number[]): void
Z
zengyawen 已提交
1525

A
Annie_wang 已提交
1526
Writes an integer array to this **MessageSequence** object.
Z
zengyawen 已提交
1527

A
annie_wangli 已提交
1528
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1529

A
Annie_wang 已提交
1530
**Parameters**
A
Annie_wang 已提交
1531

A
Annie_wang 已提交
1532 1533 1534
  | Name  | Type    | Mandatory| Description              |
  | -------- | -------- | ---- | ------------------ |
  | intArray | number[] | Yes  | Integer array to write.|
Z
zengyawen 已提交
1535

A
Annie_wang 已提交
1536
**Error codes**
A
Annie_wang 已提交
1537

A
Annie_wang 已提交
1538 1539 1540 1541 1542
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ----- | --------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1543

A
Annie_wang 已提交
1544
**Example**
A
annie_wangli 已提交
1545

Z
zengyawen 已提交
1546
  ```
A
Annie_wang 已提交
1547 1548 1549 1550 1551 1552 1553
  let data = rpc.MessageSequence.create();
  try {
      data.writeIntArray([100, 111, 112]);
  } catch(error) {
      console.info("rpc write intArray fail, errorCode " + error.code);
      console.info("rpc write intArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1554 1555 1556 1557
  ```

### readIntArray

A
Annie_wang 已提交
1558
readIntArray(dataIn: number[]): void
Z
zengyawen 已提交
1559

A
Annie_wang 已提交
1560
Reads an integer array from this **MessageSequence** object.
Z
zengyawen 已提交
1561

A
annie_wangli 已提交
1562
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1563

A
Annie_wang 已提交
1564
**Parameters**
A
Annie_wang 已提交
1565

A
Annie_wang 已提交
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
  | Name| Type    | Mandatory| Description              |
  | ------ | -------- | ---- | ------------------ |
  | dataIn | number[] | Yes  | Integer array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1577

A
Annie_wang 已提交
1578
**Example**
A
annie_wangli 已提交
1579

Z
zengyawen 已提交
1580
  ```
A
Annie_wang 已提交
1581 1582 1583 1584 1585 1586 1587
  let data = rpc.MessageSequence.create();
  try {
      data.writeIntArray([100, 111, 112]);
  } catch(error) {
      console.info("rpc write intArray fail, errorCode " + error.code);
      console.info("rpc write intArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1588
  let array = new Array(3);
A
Annie_wang 已提交
1589 1590 1591 1592 1593 1594
  try {
      data.readIntArray(array);
  } catch(error) {
      console.info("rpc read intArray fail, errorCode " + error.code);
      console.info("rpc read intArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1595 1596 1597 1598 1599 1600
  ```

### readIntArray

readIntArray(): number[]

A
Annie_wang 已提交
1601
Reads the integer array from this **MessageSequence** object.
Z
zengyawen 已提交
1602

A
annie_wangli 已提交
1603
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1604

A
Annie_wang 已提交
1605
**Return value**
A
Annie_wang 已提交
1606

A
Annie_wang 已提交
1607 1608
  | Type    | Description          |
  | -------- | -------------- |
A
Annie_wang 已提交
1609
  | number[] | Integer array read.|
Z
zengyawen 已提交
1610

A
Annie_wang 已提交
1611 1612 1613 1614 1615 1616 1617 1618
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ----- | ------- |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
1619
**Example**
A
annie_wangli 已提交
1620

Z
zengyawen 已提交
1621
  ```
A
Annie_wang 已提交
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
  let data = rpc.MessageSequence.create();
  try {
      data.writeIntArray([100, 111, 112]);
  } catch(error) {
      console.info("rpc write intArray fail, errorCode " + error.code);
      console.info("rpc write intArray fail, errorMessage" + error.message);
  }
  try {
    let array = data.readIntArray();
    console.log("RpcClient: readIntArray is " + array);
  } catch(error) {
      console.info("rpc read intArray fail, errorCode " + error.code);
      console.info("rpc read intArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1636 1637 1638 1639
  ```

### writeLongArray

A
Annie_wang 已提交
1640
writeLongArray(longArray: number[]): void
Z
zengyawen 已提交
1641

A
Annie_wang 已提交
1642
Writes a long array to this **MessageSequence** object.
Z
zengyawen 已提交
1643

A
annie_wangli 已提交
1644
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1645

A
Annie_wang 已提交
1646
**Parameters**
A
Annie_wang 已提交
1647

A
Annie_wang 已提交
1648 1649 1650
  | Name   | Type    | Mandatory| Description                |
  | --------- | -------- | ---- | -------------------- |
  | longArray | number[] | Yes  | Long array to write.|
Z
zengyawen 已提交
1651

A
Annie_wang 已提交
1652
**Error codes**
A
Annie_wang 已提交
1653

A
Annie_wang 已提交
1654 1655 1656 1657 1658
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------  | ----- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1659

A
Annie_wang 已提交
1660
**Example**
A
annie_wangli 已提交
1661

Z
zengyawen 已提交
1662
  ```
A
Annie_wang 已提交
1663 1664 1665 1666 1667 1668 1669
  let data = rpc.MessageSequence.create();
  try {
      data.writeLongArray([1111, 1112, 1113]);
  }catch(error){
      console.info("rpc write longArray fail, errorCode " + error.code);
      console.info("rpc write longArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1670 1671 1672 1673
  ```

### readLongArray

A
Annie_wang 已提交
1674
readLongArray(dataIn: number[]): void
Z
zengyawen 已提交
1675

A
Annie_wang 已提交
1676
Reads a long array from this **MessageSequence** object.
Z
zengyawen 已提交
1677

A
annie_wangli 已提交
1678
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1679

A
Annie_wang 已提交
1680
**Parameters**
A
Annie_wang 已提交
1681

A
Annie_wang 已提交
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
  | Name| Type    | Mandatory| Description                |
  | ------ | -------- | ---- | -------------------- |
  | dataIn | number[] | Yes  | Long array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------ |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1693

A
Annie_wang 已提交
1694
**Example**
A
annie_wangli 已提交
1695

Z
zengyawen 已提交
1696
  ```
A
Annie_wang 已提交
1697 1698 1699 1700 1701 1702 1703
  let data = rpc.MessageSequence.create();
  try {
      data.writeLongArray([1111, 1112, 1113]);
  } catch(error) {
      console.info("rpc write longArray fail, errorCode " + error.code);
      console.info("rpc write longArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1704
  let array = new Array(3);
A
Annie_wang 已提交
1705 1706 1707 1708 1709 1710
  try {
      data.readLongArray(array);
  } catch(error) {
      console.info("rpc read longArray fail, errorCode " + error.code);
      console.info("rpc read longArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1711 1712 1713 1714 1715 1716
  ```

### readLongArray

readLongArray(): number[]

A
Annie_wang 已提交
1717
Reads the long array from this **MessageSequence** object.
Z
zengyawen 已提交
1718

A
annie_wangli 已提交
1719
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1720

A
Annie_wang 已提交
1721
**Return value**
A
Annie_wang 已提交
1722

A
Annie_wang 已提交
1723 1724
  | Type    | Description            |
  | -------- | ---------------- |
A
Annie_wang 已提交
1725
  | number[] | Long array read.|
Z
zengyawen 已提交
1726

A
Annie_wang 已提交
1727 1728 1729 1730 1731 1732 1733 1734
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
1735
**Example**
A
annie_wangli 已提交
1736

Z
zengyawen 已提交
1737
  ```
A
Annie_wang 已提交
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
  let data = rpc.MessageSequence.create();
  try {
      data.writeLongArray([1111, 1112, 1113]);
  } catch(error) {
      console.info("rpc write longArray fail, errorCode " + error.code);
      console.info("rpc write longArray fail, errorMessage" + error.message);
  }
  try {
      let array = data.readLongArray();
      console.log("RpcClient: readLongArray is " + array);
  } catch(error) {
      console.info("rpc read longArray fail, errorCode " + error.code);
      console.info("rpc read longArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1752 1753 1754 1755
  ```

### writeFloatArray

A
Annie_wang 已提交
1756
writeFloatArray(floatArray: number[]): void
Z
zengyawen 已提交
1757

A
Annie_wang 已提交
1758
Writes a floating-point array to this **MessageSequence** object.
Z
zengyawen 已提交
1759

A
annie_wangli 已提交
1760
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1761

A
Annie_wang 已提交
1762
**Parameters**
A
Annie_wang 已提交
1763

A
Annie_wang 已提交
1764 1765 1766
  | Name    | Type    | Mandatory| Description                                                                                                                   |
  | ---------- | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
  | 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.|
Z
zengyawen 已提交
1767

A
Annie_wang 已提交
1768
**Error codes**
A
Annie_wang 已提交
1769

A
Annie_wang 已提交
1770 1771 1772 1773 1774
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1775

A
Annie_wang 已提交
1776
**Example**
A
annie_wangli 已提交
1777

Z
zengyawen 已提交
1778
  ```
A
Annie_wang 已提交
1779 1780 1781 1782 1783 1784 1785
  let data = rpc.MessageSequence.create();
  try {
      data.writeFloatArray([1.2, 1.3, 1.4]);
  } catch(error) {
      console.info("rpc write floatArray fail, errorCode " + error.code);
      console.info("rpc write floatArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1786 1787 1788 1789
  ```

### readFloatArray

A
Annie_wang 已提交
1790
readFloatArray(dataIn: number[]): void
Z
zengyawen 已提交
1791

A
Annie_wang 已提交
1792
Reads a floating-point array from this **MessageSequence** object.
A
annie_wangli 已提交
1793 1794

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1795

A
Annie_wang 已提交
1796
**Parameters**
A
Annie_wang 已提交
1797

A
Annie_wang 已提交
1798 1799 1800 1801 1802 1803 1804
  | Name| Type    | Mandatory| Description                                                                                                                   |
  | ------ | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
  | 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.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
Z
zengyawen 已提交
1805

A
Annie_wang 已提交
1806 1807 1808
  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1809

A
Annie_wang 已提交
1810
**Example**
A
annie_wangli 已提交
1811

Z
zengyawen 已提交
1812
  ```
A
Annie_wang 已提交
1813 1814 1815 1816 1817 1818 1819
  let data = rpc.MessageSequence.create();
  try {
      data.writeFloatArray([1.2, 1.3, 1.4]);
  }catch(error){
      console.info("rpc write floatArray fail, errorCode " + error.code);
      console.info("rpc write floatArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1820
  let array = new Array(3);
A
Annie_wang 已提交
1821 1822 1823 1824 1825 1826
  try {
      data.readFloatArray(array);
  } catch(error) {
      console.info("rpc read floatArray fail, errorCode " + error.code);
      console.info("rpc read floatArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1827 1828 1829 1830 1831 1832
  ```

### readFloatArray

readFloatArray(): number[]

A
Annie_wang 已提交
1833
Reads the floating-point array from this **MessageSequence** object.
Z
zengyawen 已提交
1834

A
annie_wangli 已提交
1835
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1836

A
Annie_wang 已提交
1837
**Return value**
A
Annie_wang 已提交
1838

A
Annie_wang 已提交
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
  | Type    | Description          |
  | -------- | -------------- |
  | number[] | Floating-point array read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1850

A
Annie_wang 已提交
1851
**Example**
A
annie_wangli 已提交
1852

Z
zengyawen 已提交
1853
  ```
A
Annie_wang 已提交
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867
  let data = rpc.MessageSequence.create();
  try {
      data.writeFloatArray([1.2, 1.3, 1.4]);
  } catch(error) {
      console.info("rpc write floatArray fail, errorCode " + error.code);
      console.info("rpc write floatArray fail, errorMessage" + error.message);
  }
  try {
      let array = data.readFloatArray();
      console.log("RpcClient: readFloatArray is " + array);
  } catch(error) {
      console.info("rpc read floatArray fail, errorCode " + error.code);
      console.info("rpc read floatArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1868 1869 1870 1871
  ```

### writeDoubleArray

A
Annie_wang 已提交
1872
writeDoubleArray(doubleArray: number[]): void
Z
zengyawen 已提交
1873

A
Annie_wang 已提交
1874
Writes a double-precision floating-point array to this **MessageSequence** object.
Z
zengyawen 已提交
1875

A
annie_wangli 已提交
1876
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1877

A
Annie_wang 已提交
1878
**Parameters**
A
Annie_wang 已提交
1879

A
Annie_wang 已提交
1880 1881 1882
  | Name     | Type    | Mandatory| Description                    |
  | ----------- | -------- | ---- | ------------------------ |
  | doubleArray | number[] | Yes  | Double-precision floating-point array to write.|
Z
zengyawen 已提交
1883

A
Annie_wang 已提交
1884
**Error codes**
A
Annie_wang 已提交
1885

A
Annie_wang 已提交
1886 1887 1888 1889 1890
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
1891

A
Annie_wang 已提交
1892
**Example**
A
annie_wangli 已提交
1893

Z
zengyawen 已提交
1894
  ```
A
Annie_wang 已提交
1895 1896 1897 1898 1899 1900 1901
  let data = rpc.MessageSequence.create();
  try {
      data.writeDoubleArray([11.1, 12.2, 13.3]);
  } catch(error) {
      console.info("rpc write doubleArray fail, errorCode " + error.code);
      console.info("rpc write doubleArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1902 1903 1904 1905
  ```

### readDoubleArray

A
Annie_wang 已提交
1906
readDoubleArray(dataIn: number[]): void
Z
zengyawen 已提交
1907

A
Annie_wang 已提交
1908
Reads a double-precision floating-point array from this **MessageSequence** object.
Z
zengyawen 已提交
1909

A
annie_wangli 已提交
1910
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1911

A
Annie_wang 已提交
1912
**Parameters**
A
Annie_wang 已提交
1913

A
Annie_wang 已提交
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924
  | Name| Type    | Mandatory| Description                    |
  | ------ | -------- | ---- | ------------------------ |
  | dataIn | number[] | Yes  | Double-precision floating-point array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1925

A
Annie_wang 已提交
1926
**Example**
A
annie_wangli 已提交
1927

Z
zengyawen 已提交
1928
  ```
A
Annie_wang 已提交
1929 1930 1931 1932 1933 1934 1935
  let data = rpc.MessageSequence.create();
  try {
      data.writeDoubleArray([11.1, 12.2, 13.3]);
  } catch(error) {
      console.info("rpc write doubleArray fail, errorCode " + error.code);
      console.info("rpc write doubleArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1936
  let array = new Array(3);
A
Annie_wang 已提交
1937 1938 1939 1940 1941 1942
  try {
      data.readDoubleArray(array);
  } catch(error) {
      console.info("rpc read doubleArray fail, errorCode " + error.code);
      console.info("rpc read doubleArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1943 1944 1945 1946 1947 1948
  ```

### readDoubleArray

readDoubleArray(): number[]

A
Annie_wang 已提交
1949
Reads the double-precision floating-point array from this **MessageSequence** object.
Z
zengyawen 已提交
1950

A
annie_wangli 已提交
1951
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1952

A
Annie_wang 已提交
1953
**Return value**
A
Annie_wang 已提交
1954

A
Annie_wang 已提交
1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
  | Type    | Description                |
  | -------- | -------------------- |
  | number[] | Double-precision floating-point array read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
1966

A
Annie_wang 已提交
1967
**Example**
A
annie_wangli 已提交
1968

Z
zengyawen 已提交
1969
  ```
A
Annie_wang 已提交
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983
  let data = rpc.MessageSequence.create();
  try {
      data.writeDoubleArray([11.1, 12.2, 13.3]);
  } catch(error) {
      console.info("rpc write doubleArray fail, errorCode " + error.code);
      console.info("rpc write doubleArray fail, errorMessage" + error.message);
  }
  try {
      let array = data.readDoubleArray();
      console.log("RpcClient: readDoubleArray is " + array);
  } catch(error) {
      console.info("rpc read doubleArray fail, errorCode " + error.code);
      console.info("rpc read doubleArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
1984 1985 1986 1987
  ```

### writeBooleanArray

A
Annie_wang 已提交
1988
writeBooleanArray(booleanArray: boolean[]): void
Z
zengyawen 已提交
1989

A
Annie_wang 已提交
1990
Writes a Boolean array to this **MessageSequence** object.
Z
zengyawen 已提交
1991

A
annie_wangli 已提交
1992
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
1993

A
Annie_wang 已提交
1994
**Parameters**
A
Annie_wang 已提交
1995

A
Annie_wang 已提交
1996 1997 1998
  | Name      | Type     | Mandatory| Description              |
  | ------------ | --------- | ---- | ------------------ |
  | booleanArray | boolean[] | Yes  | Boolean array to write.|
Z
zengyawen 已提交
1999

A
Annie_wang 已提交
2000
**Error codes**
A
Annie_wang 已提交
2001

A
Annie_wang 已提交
2002 2003 2004 2005 2006
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
2007

A
Annie_wang 已提交
2008
**Example**
A
annie_wangli 已提交
2009

Z
zengyawen 已提交
2010
  ```
A
Annie_wang 已提交
2011 2012 2013 2014 2015 2016 2017
  let data = rpc.MessageSequence.create();
  try {
      data.writeBooleanArray([false, true, false]);
  } catch(error) {
      console.info("rpc write booleanArray fail, errorCode " + error.code);
      console.info("rpc write booleanArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2018 2019 2020 2021
  ```

### readBooleanArray

A
Annie_wang 已提交
2022
readBooleanArray(dataIn: boolean[]): void
Z
zengyawen 已提交
2023

A
Annie_wang 已提交
2024
Reads a Boolean array from this **MessageSequence** object.
Z
zengyawen 已提交
2025

A
annie_wangli 已提交
2026
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2027

A
Annie_wang 已提交
2028
**Parameters**
A
Annie_wang 已提交
2029

A
Annie_wang 已提交
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
  | Name| Type     | Mandatory| Description              |
  | ------ | --------- | ---- | ------------------ |
  | dataIn | boolean[] | Yes  | Boolean array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
2041

A
Annie_wang 已提交
2042
**Example**
A
annie_wangli 已提交
2043

Z
zengyawen 已提交
2044
  ```
A
Annie_wang 已提交
2045 2046 2047 2048 2049 2050 2051
  let data = rpc.MessageSequence.create();
  try {
      data.writeBooleanArray([false, true, false]);
  } catch(error) {
      console.info("rpc write booleanArray fail, errorCode " + error.code);
      console.info("rpc write booleanArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2052
  let array = new Array(3);
A
Annie_wang 已提交
2053 2054 2055 2056 2057 2058
  try {
      data.readBooleanArray(array);
  } catch(error) {
      console.info("rpc read booleanArray fail, errorCode " + error.code);
      console.info("rpc read booleanArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2059 2060 2061 2062 2063 2064
  ```

### readBooleanArray

readBooleanArray(): boolean[]

A
Annie_wang 已提交
2065
Reads the Boolean array from this **MessageSequence** object.
Z
zengyawen 已提交
2066

A
annie_wangli 已提交
2067
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2068

A
Annie_wang 已提交
2069
**Return value**
A
Annie_wang 已提交
2070

A
Annie_wang 已提交
2071 2072
  | Type     | Description          |
  | --------- | -------------- |
A
Annie_wang 已提交
2073
  | boolean[] | Boolean array read.|
A
annie_wangli 已提交
2074

A
Annie_wang 已提交
2075 2076 2077 2078 2079 2080 2081 2082 2083
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |

**Example**
Z
zengyawen 已提交
2084 2085

  ```
A
Annie_wang 已提交
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099
  let data = rpc.MessageSequence.create();
  try {
      data.writeBooleanArray([false, true, false]);
  } catch(error) {
      console.info("rpc write booleanArray fail, errorCode " + error.code);
      console.info("rpc write booleanArray fail, errorMessage" + error.message);
  }
  try {
      let array = data.readBooleanArray();
      console.log("RpcClient: readBooleanArray is " + array);
  } catch(error) {
      console.info("rpc read booleanArray fail, errorCode " + error.code);
      console.info("rpc read booleanArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2100 2101 2102 2103
  ```

### writeCharArray

A
Annie_wang 已提交
2104
writeCharArray(charArray: number[]): void
Z
zengyawen 已提交
2105

A
Annie_wang 已提交
2106
Writes a character array to this **MessageSequence** object.
Z
zengyawen 已提交
2107

A
annie_wangli 已提交
2108
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2109

A
Annie_wang 已提交
2110
**Parameters**
A
Annie_wang 已提交
2111

A
Annie_wang 已提交
2112 2113 2114
  | Name   | Type    | Mandatory| Description                  |
  | --------- | -------- | ---- | ---------------------- |
  | charArray | number[] | Yes  | Character array to write.|
Z
zengyawen 已提交
2115

A
Annie_wang 已提交
2116
**Error codes**
A
Annie_wang 已提交
2117

A
Annie_wang 已提交
2118 2119 2120 2121 2122
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------ |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
2123

A
Annie_wang 已提交
2124
**Example**
A
annie_wangli 已提交
2125

Z
zengyawen 已提交
2126
  ```
A
Annie_wang 已提交
2127 2128 2129 2130 2131 2132 2133
  let data = rpc.MessageSequence.create();
  try {
      data.writeCharArray([97, 98, 88]);
  } catch(error) {
      console.info("rpc write charArray fail, errorCode " + error.code);
      console.info("rpc write charArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2134 2135 2136 2137
  ```

### readCharArray

A
Annie_wang 已提交
2138
readCharArray(dataIn: number[]): void
Z
zengyawen 已提交
2139

A
Annie_wang 已提交
2140
Reads a character array from this **MessageSequence** object.
Z
zengyawen 已提交
2141

A
annie_wangli 已提交
2142
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2143

A
Annie_wang 已提交
2144
**Parameters**
A
Annie_wang 已提交
2145

A
Annie_wang 已提交
2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156
  | Name| Type    | Mandatory| Description                  |
  | ------ | -------- | ---- | ---------------------- |
  | dataIn | number[] | Yes  | Character array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
2157

A
Annie_wang 已提交
2158
**Example**
A
annie_wangli 已提交
2159

Z
zengyawen 已提交
2160
  ```
A
Annie_wang 已提交
2161 2162 2163 2164 2165 2166 2167
  let data = rpc.MessageSequence.create();
  try {
      data.writeCharArray([97, 98, 88]);
  } catch(error) {
      console.info("rpc write charArray fail, errorCode " + error.code);
      console.info("rpc write charArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2168
  let array = new Array(3);
A
Annie_wang 已提交
2169 2170 2171 2172 2173 2174
  try {
      data.readCharArray(array);
  } catch(error) {
      console.info("rpc read charArray fail, errorCode " + error.code);
      console.info("rpc read charArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2175 2176 2177 2178
  ```

### readCharArray

A
annie_wangli 已提交
2179
readCharArray(): number[]
Z
zengyawen 已提交
2180

A
Annie_wang 已提交
2181
Reads the character array from this **MessageSequence** object.
Z
zengyawen 已提交
2182

A
annie_wangli 已提交
2183
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2184

A
Annie_wang 已提交
2185
**Return value**
A
Annie_wang 已提交
2186

A
Annie_wang 已提交
2187 2188
  | Type    | Description              |
  | -------- | ------------------ |
A
Annie_wang 已提交
2189
  | number[] | Character array read.|
Z
zengyawen 已提交
2190

A
Annie_wang 已提交
2191
**Error codes**
A
annie_wangli 已提交
2192

A
Annie_wang 已提交
2193 2194 2195 2196 2197 2198 2199
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |

**Example**
Z
zengyawen 已提交
2200

A
Annie_wang 已提交
2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217
  ```
  let data = rpc.MessageSequence.create();
  try {
      data.writeCharArray([97, 98, 88]);
  } catch(error) {
      console.info("rpc write charArray fail, errorCode " + error.code);
      console.info("rpc write charArray fail, errorMessage" + error.message);
  }
  let array = new Array(3);
  try {
      let array = data.readCharArray();
      console.log("RpcClient: readCharArray is " + array);
  } catch(error) {
      console.info("rpc read charArray fail, errorCode " + error.code);
      console.info("rpc read charArray fail, errorMessage" + error.message);
  }
  ```
Z
zengyawen 已提交
2218 2219 2220

### writeStringArray

A
Annie_wang 已提交
2221
writeStringArray(stringArray: string[]): void
Z
zengyawen 已提交
2222

A
Annie_wang 已提交
2223
Writes a string array to this **MessageSequence** object.
Z
zengyawen 已提交
2224

A
annie_wangli 已提交
2225
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2226

A
Annie_wang 已提交
2227
**Parameters**
A
Annie_wang 已提交
2228

A
Annie_wang 已提交
2229 2230 2231
  | Name     | Type    | Mandatory| Description                                                   |
  | ----------- | -------- | ---- | ------------------------------------------------------- |
  | stringArray | string[] | Yes  | String array to write. The length of a single element in the array must be less than 40960 bytes.|
Z
zengyawen 已提交
2232

A
Annie_wang 已提交
2233
**Error codes**
A
Annie_wang 已提交
2234

A
Annie_wang 已提交
2235 2236 2237 2238 2239
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
2240

A
Annie_wang 已提交
2241
**Example**
A
annie_wangli 已提交
2242

Z
zengyawen 已提交
2243
  ```
A
Annie_wang 已提交
2244 2245 2246 2247 2248 2249 2250
  let data = rpc.MessageSequence.create();
  try {
      data.writeStringArray(["abc", "def"]);
  } catch(error) {
      console.info("rpc write stringArray fail, errorCode " + error.code);
      console.info("rpc write stringArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2251 2252 2253 2254
  ```

### readStringArray

A
Annie_wang 已提交
2255
readStringArray(dataIn: string[]): void
Z
zengyawen 已提交
2256

A
Annie_wang 已提交
2257
Reads a string array from this **MessageSequence** object.
Z
zengyawen 已提交
2258

A
annie_wangli 已提交
2259
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2260

A
Annie_wang 已提交
2261
**Parameters**
A
Annie_wang 已提交
2262

A
Annie_wang 已提交
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273
  | Name| Type    | Mandatory| Description                |
  | ------ | -------- | ---- | -------------------- |
  | dataIn | string[] | Yes  | String array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
2274

A
Annie_wang 已提交
2275
**Example**
A
annie_wangli 已提交
2276

Z
zengyawen 已提交
2277
  ```
A
Annie_wang 已提交
2278 2279 2280 2281 2282 2283 2284
  let data = rpc.MessageSequence.create();
  try {
      data.writeStringArray(["abc", "def"]);
  } catch(error) {
      console.info("rpc write stringArray fail, errorCode " + error.code);
      console.info("rpc write stringArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2285
  let array = new Array(2);
A
Annie_wang 已提交
2286 2287 2288 2289 2290 2291
  try {
      data.readStringArray(array);
  } catch(error) {
      console.info("rpc read stringArray fail, errorCode " + error.code);
      console.info("rpc read stringArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2292 2293 2294 2295 2296 2297
  ```

### readStringArray

readStringArray(): string[]

A
Annie_wang 已提交
2298
Reads the string array from this **MessageSequence** object.
Z
zengyawen 已提交
2299

A
annie_wangli 已提交
2300
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2301

A
Annie_wang 已提交
2302
**Return value**
A
Annie_wang 已提交
2303

A
Annie_wang 已提交
2304 2305
  | Type    | Description            |
  | -------- | ---------------- |
A
Annie_wang 已提交
2306
  | string[] | String array read.|
Z
zengyawen 已提交
2307

A
Annie_wang 已提交
2308 2309 2310 2311 2312 2313 2314 2315
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
2316
**Example**
A
annie_wangli 已提交
2317

Z
zengyawen 已提交
2318
  ```
A
Annie_wang 已提交
2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332
  let data = rpc.MessageSequence.create();
  try {
      data.writeStringArray(["abc", "def"]);
  } catch(error) {
      console.info("rpc write stringArray fail, errorCode " + error.code);
      console.info("rpc write stringArray fail, errorMessage" + error.message);
  }
  try {
      let array = data.readStringArray();
      console.log("RpcClient: readStringArray is " + array);
  } catch(error) {
      console.info("rpc read stringArray fail, errorCode " + error.code);
      console.info("rpc read stringArray fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2333 2334
  ```

A
Annie_wang 已提交
2335
### writeNoException
Z
zengyawen 已提交
2336 2337 2338

writeNoException(): void

A
Annie_wang 已提交
2339
Writes information to this **MessageSequence** object indicating that no exception occurred.
Z
zengyawen 已提交
2340

A
annie_wangli 已提交
2341
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2342

A
Annie_wang 已提交
2343 2344 2345 2346 2347 2348 2349 2350
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |

A
Annie_wang 已提交
2351
**Example**
A
annie_wangli 已提交
2352

Z
zengyawen 已提交
2353 2354 2355 2356 2357
  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
2358

Z
zengyawen 已提交
2359 2360 2361
      onRemoteRequest(code, data, reply, option) {
          if (code === 1) {
              console.log("RpcServer: onRemoteRequest called");
A
Annie_wang 已提交
2362 2363 2364 2365 2366 2367
              try {
                  reply.writeNoException();
              } catch(error) {
                  console.info("rpc write no exception fail, errorCode " + error.code);
                  console.info("rpc write no exception fail, errorMessage" + error.message);
              }
Z
zengyawen 已提交
2368 2369 2370 2371 2372 2373 2374 2375 2376
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
  }
  ```

A
Annie_wang 已提交
2377
### readException
Z
zengyawen 已提交
2378 2379 2380

readException(): void

A
Annie_wang 已提交
2381
Reads the exception information from this **MessageSequence** object.
Z
zengyawen 已提交
2382

A
annie_wangli 已提交
2383
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2384

A
Annie_wang 已提交
2385 2386 2387 2388 2389 2390 2391 2392
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |

A
Annie_wang 已提交
2393
**Example**
A
annie_wangli 已提交
2394

Z
zengyawen 已提交
2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410
  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
annie_wangli 已提交
2411 2412
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
2413 2414 2415
  };
  FA.connectAbility(want, connect);
  let option = new rpc.MessageOption();
A
Annie_wang 已提交
2416 2417
  let data = rpc.MessageSequence.create();
  let reply = rpc.MessageSequence.create();
Z
zengyawen 已提交
2418 2419
  data.writeInt(1);
  data.writeString("hello");
A
Annie_wang 已提交
2420
  proxy.sendMessageRequest(1, data, reply, option)
Z
zengyawen 已提交
2421 2422
      .then(function(errCode) {
          if (errCode === 0) {
A
Annie_wang 已提交
2423 2424 2425 2426 2427 2428 2429
              console.log("sendMessageRequest got result");
              try {
                  reply.readException();
              } catch(error) {
                  console.info("rpc read exception fail, errorCode " + error.code);
                  console.info("rpc read no exception fail, errorMessage" + error.message);
              }
Z
zengyawen 已提交
2430 2431 2432
              let msg = reply.readString();
              console.log("RPCTest: reply msg: " + msg);
          } else {
A
Annie_wang 已提交
2433
              console.log("RPCTest: sendMessageRequest failed, errCode: " + errCode);
Z
zengyawen 已提交
2434 2435
          }
      }).catch(function(e) {
A
Annie_wang 已提交
2436
          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
Z
zengyawen 已提交
2437
      }).finally (() => {
A
Annie_wang 已提交
2438
          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
Z
zengyawen 已提交
2439 2440 2441 2442 2443
          data.reclaim();
          reply.reclaim();
      });
  ```

A
Annie_wang 已提交
2444
### writeParcelableArray
Z
zengyawen 已提交
2445

A
Annie_wang 已提交
2446
writeParcelableArray(parcelableArray: Parcelable[]): void
Z
zengyawen 已提交
2447

A
Annie_wang 已提交
2448
Writes a **Parcelable** array to this **MessageSequence** object.
Z
zengyawen 已提交
2449

A
annie_wangli 已提交
2450
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2451

A
Annie_wang 已提交
2452
**Parameters**
A
Annie_wang 已提交
2453

A
Annie_wang 已提交
2454 2455 2456
  | Name         | Type        | Mandatory| Description                      |
  | --------------- | ------------ | ---- | -------------------------- |
  | parcelableArray | Parcelable[] | Yes  | **Parcelable** array to write.|
Z
zengyawen 已提交
2457

A
Annie_wang 已提交
2458
**Error codes**
A
Annie_wang 已提交
2459

A
Annie_wang 已提交
2460 2461 2462 2463 2464
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
2465

A
Annie_wang 已提交
2466
**Example**
A
annie_wangli 已提交
2467

Z
zengyawen 已提交
2468
  ```
A
Annie_wang 已提交
2469
  class MyParcelable {
A
Annie_wang 已提交
2470 2471 2472
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
2473
          this.num = num;
A
Annie_wang 已提交
2474
          this.str = str;
Z
zengyawen 已提交
2475
      }
A
Annie_wang 已提交
2476 2477 2478
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
Z
zengyawen 已提交
2479 2480
          return true;
      }
A
Annie_wang 已提交
2481 2482 2483
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
Z
zengyawen 已提交
2484 2485 2486
          return true;
      }
  }
A
Annie_wang 已提交
2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497
  let parcelable = new MyParcelable(1, "aaa");
  let parcelable2 = new MyParcelable(2, "bbb");
  let parcelable3 = new MyParcelable(3, "ccc");
  let a = [parcelable, parcelable2, parcelable3];
  let data = rpc.MessageSequence.create();
  try {
      data.writeParcelableArray(a);
  } catch(error) {
      console.info("rpc write parcelable array fail, errorCode " + error.code);
      console.info("rpc write parcelable array fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2498 2499
  ```

A
Annie_wang 已提交
2500
### readParcelableArray
Z
zengyawen 已提交
2501

A
Annie_wang 已提交
2502
readParcelableArray(parcelableArray: Parcelable[]): void
Z
zengyawen 已提交
2503

A
Annie_wang 已提交
2504
Reads a **Parcelable** array from this **MessageSequence** object.
Z
zengyawen 已提交
2505

A
annie_wangli 已提交
2506
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2507

A
Annie_wang 已提交
2508
**Parameters**
A
Annie_wang 已提交
2509

A
Annie_wang 已提交
2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521
  | Name         | Type        | Mandatory| Description                      |
  | --------------- | ------------ | ---- | -------------------------- |
  | parcelableArray | Parcelable[] | Yes  | **Parcelable** array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
  | 1900012 | call js callback function failed |
Z
zengyawen 已提交
2522

A
Annie_wang 已提交
2523
**Example**
A
annie_wangli 已提交
2524

Z
zengyawen 已提交
2525
  ```
A
Annie_wang 已提交
2526
  class MyParcelable {
A
Annie_wang 已提交
2527 2528 2529
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
2530
          this.num = num;
A
Annie_wang 已提交
2531
          this.str = str;
Z
zengyawen 已提交
2532
      }
A
Annie_wang 已提交
2533 2534 2535
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
Z
zengyawen 已提交
2536 2537
          return true;
      }
A
Annie_wang 已提交
2538 2539 2540
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
Z
zengyawen 已提交
2541 2542 2543
          return true;
      }
  }
A
Annie_wang 已提交
2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558
  let parcelable = new MyParcelable(1, "aaa");
  let parcelable2 = new MyParcelable(2, "bbb");
  let parcelable3 = new MyParcelable(3, "ccc");
  let a = [parcelable, parcelable2, parcelable3];
  let data = rpc.MessageSequence.create();
  let result = data.writeParcelableArray(a);
  console.log("RpcClient: writeParcelableArray is " + result);
  let b = [new MyParcelable(0, ""), new MyParcelable(0, ""), new MyParcelable(0, "")];
  try {
      data.readParcelableArray(b);
  } catch(error) {
      console.info("rpc read parcelable array fail, errorCode " + error.code);
      console.info("rpc read parcelable array fail, errorMessage" + error.message);
  }
  data.readParcelableArray(b);
Z
zengyawen 已提交
2559 2560
  ```

A
Annie_wang 已提交
2561
### writeRemoteObjectArray
Z
zengyawen 已提交
2562

A
Annie_wang 已提交
2563
writeRemoteObjectArray(objectArray: IRemoteObject[]): void
Z
zengyawen 已提交
2564

A
Annie_wang 已提交
2565
Writes an array of **IRemoteObject** objects to this **MessageSequence** object.
Z
zengyawen 已提交
2566

A
annie_wangli 已提交
2567
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2568

A
Annie_wang 已提交
2569
**Parameters**
A
Annie_wang 已提交
2570

A
Annie_wang 已提交
2571 2572 2573
  | Name     | Type           | Mandatory| Description                                          |
  | ----------- | --------------- | ---- | ---------------------------------------------- |
  | objectArray | IRemoteObject[] | Yes  | Array of **IRemoteObject** objects to write.|
Z
zengyawen 已提交
2574

A
Annie_wang 已提交
2575
**Error codes**
A
Annie_wang 已提交
2576

A
Annie_wang 已提交
2577 2578 2579 2580 2581
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------- |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
2582

A
Annie_wang 已提交
2583
**Example**
A
annie_wangli 已提交
2584

Z
zengyawen 已提交
2585 2586 2587 2588
  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
A
Annie_wang 已提交
2589
          this.modifyLocalInterface(this, descriptor);
A
Annie_wang 已提交
2590
      }
A
Annie_wang 已提交
2591

A
Annie_wang 已提交
2592 2593 2594
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
2595 2596
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
A
Annie_wang 已提交
2597
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
2598
  let result = data.writeRemoteObjectArray(a);
A
Annie_wang 已提交
2599 2600 2601 2602 2603 2604
  try {
      data.writeRemoteObjectArray(a);
  } catch(error) {
      console.info("rpc write remote object array fail, errorCode " + error.code);
      console.info("rpc write remote object array fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2605 2606 2607
  console.log("RpcClient: writeRemoteObjectArray is " + result);
  ```

A
Annie_wang 已提交
2608
### readRemoteObjectArray
Z
zengyawen 已提交
2609 2610 2611

readRemoteObjectArray(objects: IRemoteObject[]): void

A
Annie_wang 已提交
2612
Reads an array of **IRemoteObject** objects from this **MessageSequence** object.
Z
zengyawen 已提交
2613

A
annie_wangli 已提交
2614
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2615

A
Annie_wang 已提交
2616
**Parameters**
A
Annie_wang 已提交
2617

A
Annie_wang 已提交
2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628
  | Name | Type           | Mandatory| Description                                          |
  | ------- | --------------- | ---- | ---------------------------------------------- |
  | objects | IRemoteObject[] | Yes  | **IRemoteObject** array to read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
2629

A
Annie_wang 已提交
2630
**Example**
A
annie_wangli 已提交
2631

Z
zengyawen 已提交
2632
  ```
A
Annie_wang 已提交
2633 2634 2635 2636 2637
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
2638 2639 2640
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
A
Annie_wang 已提交
2641
          this.modifyLocalInterface(this, descriptor);
A
Annie_wang 已提交
2642
      }
A
Annie_wang 已提交
2643

A
Annie_wang 已提交
2644 2645 2646
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
2647 2648
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
A
Annie_wang 已提交
2649 2650
  let data = rpc.MessageSequence.create();
  data.writeRemoteObjectArray(a);
Z
zengyawen 已提交
2651
  let b = new Array(3);
A
Annie_wang 已提交
2652 2653 2654 2655 2656 2657
  try {
      data.readRemoteObjectArray(b);
  } catch(error) {
      console.info("rpc read remote object array fail, errorCode " + error.code);
      console.info("rpc read remote object array fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2658 2659 2660
  data.readRemoteObjectArray(b);
  ```

A
Annie_wang 已提交
2661
### readRemoteObjectArray
Z
zengyawen 已提交
2662 2663 2664

readRemoteObjectArray(): IRemoteObject[]

A
Annie_wang 已提交
2665
Reads the **IRemoteObject** object array from this **MessageSequence** object.
Z
zengyawen 已提交
2666

A
annie_wangli 已提交
2667
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2668

A
Annie_wang 已提交
2669
**Return value**
A
Annie_wang 已提交
2670

A
Annie_wang 已提交
2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681
  | Type           | Description                       |
  | --------------- | --------------------------- |
  | IRemoteObject[] | **IRemoteObject** object array read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |
Z
zengyawen 已提交
2682

A
Annie_wang 已提交
2683
**Example**
A
annie_wangli 已提交
2684

Z
zengyawen 已提交
2685 2686 2687 2688
  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
A
Annie_wang 已提交
2689
          this.modifyLocalInterface(this, descriptor);
A
Annie_wang 已提交
2690
      }
A
Annie_wang 已提交
2691
 
A
Annie_wang 已提交
2692 2693 2694
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
2695 2696
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
A
Annie_wang 已提交
2697 2698 2699 2700 2701 2702 2703 2704 2705
  let data = rpc.MessageSequence.create();
  data.writeRemoteObjectArray(a);
  try {
      let b = data.readRemoteObjectArray();
      console.log("RpcClient: readRemoteObjectArray is " + b);
  } catch(error) {
      console.info("rpc read remote object array fail, errorCode " + error.code);
      console.info("rpc read remote object array fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2706 2707 2708
  ```


A
Annie_wang 已提交
2709
### closeFileDescriptor<sup>9+</sup>
Z
zengyawen 已提交
2710 2711 2712

static closeFileDescriptor(fd: number): void

A
annie_wangli 已提交
2713
Closes a file descriptor.
Z
zengyawen 已提交
2714

A
annie_wangli 已提交
2715
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2716

A
Annie_wang 已提交
2717
**Parameters**
A
Annie_wang 已提交
2718

A
Annie_wang 已提交
2719 2720 2721
  | Name| Type  | Mandatory| Description                |
  | ------ | ------ | ---- | -------------------- |
  | fd     | number | Yes  | File descriptor to close.|
Z
zengyawen 已提交
2722

A
Annie_wang 已提交
2723
**Example**
A
annie_wangli 已提交
2724

Z
zengyawen 已提交
2725 2726 2727 2728
  ```
  import fileio from '@ohos.fileio';
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
A
Annie_wang 已提交
2729 2730 2731 2732 2733 2734
  try {
      rpc.MessageSequence.closeFileDescriptor(fd);
  } catch(error) {
      console.info("rpc close file descriptor fail, errorCode " + error.code);
      console.info("rpc close file descriptor fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2735 2736
  ```

A
Annie_wang 已提交
2737
### dupFileDescriptor
Z
zengyawen 已提交
2738 2739 2740

static dupFileDescriptor(fd: number) :number

A
annie_wangli 已提交
2741
Duplicates a file descriptor.
Z
zengyawen 已提交
2742

A
annie_wangli 已提交
2743
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2744

A
Annie_wang 已提交
2745
**Parameters**
A
Annie_wang 已提交
2746

A
Annie_wang 已提交
2747 2748 2749
  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | fd     | number | Yes  | File descriptor to duplicate.|
Z
zengyawen 已提交
2750

A
Annie_wang 已提交
2751
**Return value**
A
Annie_wang 已提交
2752

A
Annie_wang 已提交
2753 2754
  | Type  | Description                |
  | ------ | -------------------- |
A
annie_wangli 已提交
2755
  | number | New file descriptor.|
Z
zengyawen 已提交
2756

A
Annie_wang 已提交
2757 2758 2759 2760 2761 2762 2763 2764
**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------- |
  | 1900013 | call os dup function failed |

A
Annie_wang 已提交
2765
**Example**
A
annie_wangli 已提交
2766

Z
zengyawen 已提交
2767 2768 2769 2770
  ```
  import fileio from '@ohos.fileio';
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
A
Annie_wang 已提交
2771 2772 2773 2774 2775 2776
  try {
      let newFd = rpc.MessageSequence.dupFileDescriptor(fd);
  } catch(error) {
      console.info("rpc dup file descriptor fail, errorCode " + error.code);
      console.info("rpc dup file descriptor fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2777 2778
  ```

A
Annie_wang 已提交
2779
### containFileDescriptors
Z
zengyawen 已提交
2780 2781 2782

containFileDescriptors(): boolean

A
Annie_wang 已提交
2783
Checks whether this **MessageSequence** object contains file descriptors.
Z
zengyawen 已提交
2784

A
annie_wangli 已提交
2785
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2786

A
Annie_wang 已提交
2787
**Return value**
A
Annie_wang 已提交
2788

A
Annie_wang 已提交
2789 2790 2791
  | Type   | Description                                                                |
  | ------- | -------------------------------------------------------------------- |
  | boolean | Returns **true** if the **MessageSequence** object contains file descriptors; returns **false** otherwise.|
Z
zengyawen 已提交
2792

A
Annie_wang 已提交
2793
**Example**
A
annie_wangli 已提交
2794

A
Annie_wang 已提交
2795

Z
zengyawen 已提交
2796 2797
  ```
  import fileio from '@ohos.fileio';
A
Annie_wang 已提交
2798
  let sequence = new rpc.MessageSequence();
Z
zengyawen 已提交
2799
  let filePath = "path/to/file";
A
Annie_wang 已提交
2800
  let r1 = sequence.containFileDescriptors();
Z
zengyawen 已提交
2801
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
A
Annie_wang 已提交
2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814
  try {
      sequence.writeFileDescriptor(fd);
  } catch(error) {
      console.info("rpc write file descriptor fail, errorCode " + error.code);
      console.info("rpc write file descriptor fail, errorMessage" + error.message);
  }
  try {
      let containFD = sequence.containFileDescriptors();
      console.log("RpcTest: sequence after write fd containFd result is : " + containFD);
  } catch(error) {
      console.info("rpc contain file descriptor fail, errorCode " + error.code);
      console.info("rpc contain file descriptor fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2815 2816
  ```

A
Annie_wang 已提交
2817
### writeFileDescriptor
Z
zengyawen 已提交
2818

A
Annie_wang 已提交
2819
writeFileDescriptor(fd: number): void
Z
zengyawen 已提交
2820

A
Annie_wang 已提交
2821
Writes a file descriptor to this **MessageSequence** object.
Z
zengyawen 已提交
2822

A
annie_wangli 已提交
2823
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
2824

A
Annie_wang 已提交
2825
**Parameters**
A
Annie_wang 已提交
2826

A
Annie_wang 已提交
2827 2828 2829
  | Name| Type  | Mandatory| Description        |
  | ------ | ------ | ---- | ------------ |
  | fd     | number | Yes  | File descriptor to write.|
Z
zengyawen 已提交
2830

A
Annie_wang 已提交
2831
**Error codes**
A
Annie_wang 已提交
2832

A
Annie_wang 已提交
2833 2834 2835 2836 2837
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------ |
  | 1900009 | write data to message sequence failed |
Z
zengyawen 已提交
2838

A
Annie_wang 已提交
2839
**Example**
A
annie_wangli 已提交
2840

Z
zengyawen 已提交
2841 2842
  ```
  import fileio from '@ohos.fileio';
A
Annie_wang 已提交
2843
  let sequence = new rpc.MessageSequence();
Z
zengyawen 已提交
2844 2845
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
A
Annie_wang 已提交
2846 2847 2848 2849 2850 2851
  try {
      sequence.writeFileDescriptor(fd);
  } catch(error) {
      console.info("rpc write file descriptor fail, errorCode " + error.code);
      console.info("rpc write file descriptor fail, errorMessage" + error.message);
  }
Z
zengyawen 已提交
2852 2853 2854
  ```


A
Annie_wang 已提交
2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313
### readFileDescriptor

readFileDescriptor(): number

Reads a file descriptor from this **MessageSequence** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description            |
  | ------ | ---------------- |
  | number | File descriptor read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |

**Example**

  ```
  import fileio from '@ohos.fileio';
  let sequence = new rpc.MessageSequence();
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
  try {
      sequence.writeFileDescriptor(fd);
  } catch(error) {
      console.info("rpc write file descriptor fail, errorCode " + error.code);
      console.info("rpc write file descriptor fail, errorMessage" + error.message);
  }
  try {
      let readFD = sequence.readFileDescriptor();
  } catch(error) {
      console.info("rpc read file descriptor fail, errorCode " + error.code);
      console.info("rpc read file descriptor fail, errorMessage" + error.message);
  }
  ```


### writeAshmem

writeAshmem(ashmem: Ashmem): void

Writes an anonymous shared object to this **MessageSequence** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                                 |
  | ------ | ------ | ---- | ------------------------------------- |
  | ashmem | Ashmem | Yes  | Anonymous shared object to write.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------- |
  | 1900003 | write to ashmem failed |

**Example**

  ```
  let sequence = new rpc.MessageSequence();
  let ashmem;
  try {
      ashmem = rpc.Ashmem.create("ashmem", 1024);
  } catch(error) {
      console.info("rpc create ashmem fail, errorCode " + error.code);
      console.info("rpc creat ashmem fail, errorMessage" + error.message);
  }
  try {
      sequence.writeAshmem(ashmem);
  } catch(error) {
      console.info("rpc write ashmem fail, errorCode " + error.code);
      console.info("rpc write ashmem fail, errorMessage" + error.message);
  }
  ```


### readAshmem

readAshmem(): Ashmem

Reads the anonymous shared object from this **MessageSequence** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description              |
  | ------ | ------------------ |
  | Ashmem | Anonymous share object read.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900004 | read from ashmem failed |

**Example**

  ```
  let sequence = new rpc.MessageSequence();
  let ashmem;
  try {
      ashmem = rpc.Ashmem.create("ashmem", 1024);
  } catch(error) {
      console.info("rpc create ashmem fail, errorCode " + error.code);
      console.info("rpc creat ashmem fail, errorMessage" + error.message);
  }
  try {
      sequence.writeAshmem(ashmem);
  } catch(error) {
      console.info("rpc write ashmem fail, errorCode " + error.code);
      console.info("rpc write ashmem fail, errorMessage" + error.message);
  }
  try {
      let readAshmem = sequence.readAshmem();
      console.log("RpcTest: read ashmem to result is : " + readAshmem);
  } catch(error) {
      console.info("rpc read ashmem fail, errorCode " + error.code);
      console.info("rpc read ashmem fail, errorMessage" + error.message);
  }
  ```


### getRawDataCapacity

getRawDataCapacity(): number

Obtains the maximum amount of raw data that can be held by this **MessageSequence** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                                                        |
  | ------ | ------------------------------------------------------------ |
  | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageSequence** object.|

**Example**

  ```
  let sequence = new rpc.MessageSequence();
  let result = sequence.getRawDataCapacity();
  console.log("RpcTest: sequence get RawDataCapacity result is : " + result);
  ```


### writeRawData

writeRawData(rawData: number[], size: number): void

Writes raw data to this **MessageSequence** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name | Type    | Mandatory| Description                              |
  | ------- | -------- | ---- | ---------------------------------- |
  | rawData | number[] | Yes  | Raw data to write.                |
  | size    | number   | Yes  | Size of the raw data, in bytes.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------ |
  | 1900009 | write data to message sequence failed |

**Example**

  ```
  let sequence = new rpc.MessageSequence();
  let arr = [1, 2, 3, 4, 5];
  try {
      sequence.writeRawData(arr, arr.length);
  } catch(error) {
      console.info("rpc write rawdata fail, errorCode " + error.code);
      console.info("rpc write rawdata fail, errorMessage" + error.message);
  }
  ```


### readRawData

readRawData(size: number): number[]

Reads raw data from this **MessageSequence** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | size   | number | Yes  | Size of the raw data to read.|

**Return value**

  | Type    | Description                          |
  | -------- | ------------------------------ |
  | number[] | Raw data read, in bytes.|

**Error codes**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900010 | read data from message sequence failed |

**Example**

  ```
  let sequence = new rpc.MessageSequence();
  let arr = [1, 2, 3, 4, 5];
  try {
      sequence.writeRawData(arr, arr.length);
  } catch(error) {
      console.info("rpc write rawdata fail, errorCode " + error.code);
      console.info("rpc write rawdata fail, errorMessage" + error.message);
  }
  try {
      let result = sequence.readRawData(5);
      console.log("RpcTest: sequence read raw data result is : " + result);
  } catch(error) {
      console.info("rpc read rawdata fail, errorCode " + error.code);
      console.info("rpc read rawdata fail, errorMessage" + error.message);
  }
  ```

## MessageParcel<sup>(deprecated)</sup>

>This class is no longer maintained since API version 9. You are advised to use [MessageSequence](#messagesequence9).

Provides APIs for reading and writing data in specific format. During RPC, the sender can use the **write()** method provided by **MessageParcel** to write data in specific format to a **MessageParcel** object. The receiver can use the **read()** method provided by **MessageParcel** to read data in specific format from a **MessageParcel** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.

### create

create(): MessageParcel

Creates a **MessageParcel** object. This method is a static method.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type         | Description                         |
  | ------------- | ----------------------------- |
  | MessageParcel | **MessageParcel** object created.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  console.log("RpcClient: data is " + data);
  ```

### reclaim

reclaim(): void

Reclaims the **MessageParcel** object that is no longer used.

**System capability**: SystemCapability.Communication.IPC.Core

**Example**

  ```
  let reply = rpc.MessageParcel.create();
  reply.reclaim();
  ```

### writeRemoteObject

writeRemoteObject(object: [IRemoteObject](#iremoteobject)): boolean

Serializes a remote object and writes it to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type                           | Mandatory| Description                                   |
  | ------ | ------------------------------- | ---- | --------------------------------------- |
  | object | [IRemoteObject](#iremoteobject) | Yes  | Remote object to serialize and write to the **MessageParcel** object.|

**Return value**

  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
  }
  let data = rpc.MessageParcel.create();
  let testRemoteObject = new TestRemoteObject("testObject");
  data.writeRemoteObject(testRemoteObject);
  ```

### readRemoteObject

readRemoteObject(): IRemoteObject

Reads 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.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type                           | Description              |
  | ------------------------------- | ------------------ |
  | [IRemoteObject](#iremoteobject) | Remote object obtained.|

**Example**

  ```
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
  }
  let data = rpc.MessageParcel.create();
  let testRemoteObject = new TestRemoteObject("testObject");
  data.writeRemoteObject(testRemoteObject);
  let proxy = data.readRemoteObject();
  ```

### writeInterfaceToken

writeInterfaceToken(token: string): boolean

Writes an interface token to this **MessageParcel** object. The remote object can use this interface token to verify the communication.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description              |
  | ------ | ------ | ---- | ------------------ |
  | token  | string | Yes  | Interface token to write.|

**Return value**

  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeInterfaceToken("aaa");
  console.log("RpcServer: writeInterfaceToken is " + result);
  ```


### readInterfaceToken

readInterfaceToken(): string

Reads 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.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                    |
  | ------ | ------------------------ |
  | string | Interface token obtained.|

**Example**

  ```
  class Stub extends rpc.RemoteObject {
      onRemoteMessageRequest(code, data, reply, option) {
          let interfaceToken = data.readInterfaceToken();
          console.log("RpcServer: interfaceToken is " + interfaceToken);
          return true;
      }
  }
  ```


### getSize

getSize(): number

Obtains the data size of this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                                         |
  | ------ | --------------------------------------------- |
  | number | Size of the **MessageParcel** object obtained, in bytes.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let size = data.getSize();
  console.log("RpcClient: size is " + size);
  ```


### getCapacity

getCapacity(): number

Obtains the capacity of this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                                         |
  | ------ | --------------------------------------------- |
  | number | **MessageParcel** capacity obtained, in bytes.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.getCapacity();
  console.log("RpcClient: capacity is " + result);
  ```


### setSize

setSize(size: number): boolean

Sets the size of data contained in this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                                       |
  | ------ | ------ | ---- | ------------------------------------------- |
  | size   | number | Yes  | Data size to set, in bytes.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let setSize = data.setSize(16);
  console.log("RpcClient: setSize is " + setSize);
  ```


### setCapacity

setCapacity(size: number): boolean

Sets the storage capacity of this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                                       |
  | ------ | ------ | ---- | ------------------------------------------- |
  | size   | number | Yes  | Storage capacity to set, in bytes.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.setCapacity(100);
  console.log("RpcClient: setCapacity is " + result);
  ```


### getWritableBytes

getWritableBytes(): number

Obtains the writable capacity of this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                                               |
  | ------ | --------------------------------------------------- |
  | number | **MessageParcel** writable capacity obtained, in bytes.|

**Example**

  ```
  class Stub extends rpc.RemoteObject {
      onRemoteMessageRequest(code, data, reply, option) {
          let getWritableBytes = data.getWritableBytes();
          console.log("RpcServer: getWritableBytes is " + getWritableBytes);
          return true;
      }
  }
  ```


### getReadableBytes

getReadableBytes(): number

Obtains the readable capacity of this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                                               |
  | ------ | --------------------------------------------------- |
  | number | **MessageParcel** object readable capacity, in bytes.|

**Example**

  ```
  class Stub extends rpc.RemoteObject {
      onRemoteRequest(code, data, reply, option) {
          let result = data.getReadableBytes();
          console.log("RpcServer: getReadableBytes is " + result);
          return true;
      }
  }
  ```


### getReadPosition

getReadPosition(): number

Obtains the read position of this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                                   |
  | ------ | --------------------------------------- |
  | number | Current read position of the **MessageParcel** object.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let readPos = data.getReadPosition();
  console.log("RpcClient: readPos is " + readPos);
  ```


### getWritePosition

getWritePosition(): number

Obtains the write position of this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                                   |
  | ------ | --------------------------------------- |
  | number | Current write position of the **MessageParcel** object.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  data.writeInt(10);
  let bwPos = data.getWritePosition();
  console.log("RpcClient: bwPos is " + bwPos);
  ```


### rewindRead

rewindRead(pos: number): boolean

Moves the read pointer to the specified position.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | pos    | number | Yes  | Position from which data is to read.|

**Return value**

  | Type   | Description                                             |
  | ------- | ------------------------------------------------- |
  | boolean | Returns **true** if the read position changes; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  data.writeInt(12);
  data.writeString("parcel");
  let number = data.readInt();
  console.log("RpcClient: number is " + number);
  data.rewindRead(0);
  let number2 = data.readInt();
  console.log("RpcClient: rewindRead is " + number2);
  ```


### rewindWrite

rewindWrite(pos: number): boolean

Moves the write pointer to the specified position.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | pos    | number | Yes  | Position from which data is to write.|

**Return value**

  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
  | boolean | Returns **true** if the write position changes; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  data.writeInt(4);
  data.rewindWrite(0);
  data.writeInt(5);
  let number = data.readInt();
  console.log("RpcClient: rewindWrite is: " + number);
  ```


### writeByte

writeByte(val: number): boolean

Writes a Byte value to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description            |
  | ------ | ------ | ---- | ---------------- |
  | val    | number | Yes  | Byte value to write.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeByte(2);
  console.log("RpcClient: writeByte is: " + result);
  ```


### readByte

readByte(): number

Reads the Byte value from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description        |
  | ------ | ------------ |
  | number | Byte value read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeByte(2);
  console.log("RpcClient: writeByte is: " + result);
  let ret = data.readByte();
  console.log("RpcClient: readByte is: " + ret);
  ```


### writeShort

writeShort(val: number): boolean

Writes a Short int value to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description              |
  | ------ | ------ | ---- | ------------------ |
  | val    | number | Yes  | Short int value to write.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeShort(8);
  console.log("RpcClient: writeShort is: " + result);
  ```


### readShort

readShort(): number

Reads the Short int value from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description          |
  | ------ | -------------- |
  | number | Short int value read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeShort(8);
  console.log("RpcClient: writeShort is: " + result);
  let ret = data.readShort();
  console.log("RpcClient: readShort is: " + ret);
  ```


### writeInt

writeInt(val: number): boolean

Writes an Int value to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description            |
  | ------ | ------ | ---- | ---------------- |
  | val    | number | Yes  | Int value to write.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeInt(10);
  console.log("RpcClient: writeInt is " + result);
  ```


### readInt

readInt(): number

Reads the Int value from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description        |
  | ------ | ------------ |
  | number | Int value read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeInt(10);
  console.log("RpcClient: writeInt is " + result);
  let ret = data.readInt();
  console.log("RpcClient: readInt is " + ret);
  ```


### writeLong

writeLong(val: number): boolean

Writes a Long int value to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description            |
  | ------ | ------ | ---- | ---------------- |
  | val    | number | Yes  | Long int value to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeLong(10000);
  console.log("RpcClient: writeLong is " + result);
  ```


### readLong

readLong(): number

Reads the Long int value from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description          |
  | ------ | -------------- |
  | number | Long int value read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeLong(10000);
  console.log("RpcClient: writeLong is " + result);
  let ret = data.readLong();
  console.log("RpcClient: readLong is " + ret);
  ```


### writeFloat

writeFloat(val: number): boolean

Writes a Float value to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description            |
  | ------ | ------ | ---- | ---------------- |
  | val    | number | Yes  | Float value to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeFloat(1.2);
  console.log("RpcClient: writeFloat is " + result);
  ```


### readFloat

readFloat(): number

Reads the Float value from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description        |
  | ------ | ------------ |
  | number | Float value read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeFloat(1.2);
  console.log("RpcClient: writeFloat is " + result);
  let ret = data.readFloat();
  console.log("RpcClient: readFloat is " + ret);
  ```


### writeDouble

writeDouble(val: number): boolean

Writes a Double value to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                  |
  | ------ | ------ | ---- | ---------------------- |
  | val    | number | Yes  | Double value to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeDouble(10.2);
  console.log("RpcClient: writeDouble is " + result);
  ```


### readDouble

readDouble(): number

Reads the Double value from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description              |
  | ------ | ------------------ |
  | number | Double value read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeDouble(10.2);
  console.log("RpcClient: writeDouble is " + result);
  let ret = data.readDouble();
  console.log("RpcClient: readDouble is " + ret);
  ```

### writeBoolean

writeBoolean(val: boolean): boolean

Writes a Boolean value to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type   | Mandatory| Description            |
  | ------ | ------- | ---- | ---------------- |
  | val    | boolean | Yes  | Boolean value to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeBoolean(false);
  console.log("RpcClient: writeBoolean is " + result);
  ```


### readBoolean

readBoolean(): boolean

Reads the Boolean value from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type   | Description                |
  | ------- | -------------------- |
  | boolean | Boolean value read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeBoolean(false);
  console.log("RpcClient: writeBoolean is " + result);
  let ret = data.readBoolean();
  console.log("RpcClient: readBoolean is " + ret);
  ```


### writeChar

writeChar(val: number): boolean

Writes a Char value to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                |
  | ------ | ------ | ---- | -------------------- |
  | val    | number | Yes  | Char value to write.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeChar(97);
  console.log("RpcClient: writeChar is " + result);
  ```


### readChar

readChar(): number

Reads the Char value from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description            |
  | ------ | ---------------- |
  | number | Char value read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeChar(97);
  console.log("RpcClient: writeChar is " + result);
  let ret = data.readChar();
  console.log("RpcClient: readChar is " + ret);
  ```


### writeString

writeString(val: string): boolean

Writes a string to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                                     |
  | ------ | ------ | ---- | ----------------------------------------- |
  | val    | string | Yes  | String to write. The length of the string must be less than 40960 bytes.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeString('abc');
  console.log("RpcClient: writeString  is " + result);
  ```


### readString

readString(): string

Reads a string from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description          |
  | ------ | -------------- |
  | string | String read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeString('abc');
  console.log("RpcClient: writeString  is " + result);
  let ret = data.readString();
  console.log("RpcClient: readString is " + ret);
  ```


### writeSequenceable

writeSequenceable(val: Sequenceable): boolean

Writes a sequenceable object to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type                         | Mandatory| Description                |
  | ------ | ----------------------------- | ---- | -------------------- |
  | val    | [Sequenceable](#sequenceable) | Yes  | Sequenceable object to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  class MySequenceable {
      num: number;
      str: string;
      constructor(num, str) {
          this.num = num;
          this.str = str;
      }
      marshalling(messageParcel) {
          messageParcel.writeInt(this.num);
          messageParcel.writeString(this.str);
          return true;
      }
      unmarshalling(messageParcel) {
          this.num = messageParcel.readInt();
          this.str = messageParcel.readString();
          return true;
      }
  }
  let sequenceable = new MySequenceable(1, "aaa");
  let data = rpc.MessageParcel.create();
  let result = data.writeSequenceable(sequenceable);
  console.log("RpcClient: writeSequenceable is " + result);
  ```


### readSequenceable

readSequenceable(dataIn: Sequenceable): boolean

Reads member variables from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type                         | Mandatory| Description                                   |
  | ------ | ----------------------------- | ---- | --------------------------------------- |
  | dataIn | [Sequenceable](#sequenceabledeprecated) | Yes  | Object that reads member variables from the **MessageParcel** object.|

**Return value**

  | Type   | Description                                       |
  | ------- | ------------------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  class MySequenceable {
      num: number;
      str: string;
      constructor(num, str) {
          this.num = num;
          this.str = str;
      }
      marshalling(messageParcel) {
          messageParcel.writeInt(this.num);
          messageParcel.writeString(this.str);
          return true;
      }
      unmarshalling(messageParcel) {
          this.num = messageParcel.readInt();
          this.str = messageParcel.readString();
          return true;
      }
  }
  let sequenceable = new MySequenceable(1, "aaa");
  let data = rpc.MessageParcel.create();
  let result = data.writeSequenceable(sequenceable);
  console.log("RpcClient: writeSequenceable is " + result);
  let ret = new MySequenceable(0, "");
  let result2 = data.readSequenceable(ret);
  console.log("RpcClient: writeSequenceable is " + result2);
  ```


### writeByteArray

writeByteArray(byteArray: number[]): boolean

Writes a byte array to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name   | Type    | Mandatory| Description              |
  | --------- | -------- | ---- | ------------------ |
  | byteArray | number[] | Yes  | Byte array to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let ByteArrayVar = [1, 2, 3, 4, 5];
  let result = data.writeByteArray(ByteArrayVar);
  console.log("RpcClient: writeByteArray is " + result);
  ```


### readByteArray

readByteArray(dataIn: number[]): void

Reads a byte array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type    | Mandatory| Description              |
  | ------ | -------- | ---- | ------------------ |
  | dataIn | number[] | Yes  | Byte array to read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let ByteArrayVar = [1, 2, 3, 4, 5];
  let result = data.writeByteArray(ByteArrayVar);
  console.log("RpcClient: writeByteArray is " + result);
  let array = new Array(5);
  data.readByteArray(array);
  ```


### readByteArray

readByteArray(): number[]

Reads the byte array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type    | Description          |
  | -------- | -------------- |
  | number[] | Byte array read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let ByteArrayVar = [1, 2, 3, 4, 5];
  let result = data.writeByteArray(ByteArrayVar);
  console.log("RpcClient: writeByteArray is " + result);
  let array = data.readByteArray();
  console.log("RpcClient: readByteArray is " + array);
  ```


### writeShortArray

writeShortArray(shortArray: number[]): boolean

Writes a short array to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name    | Type    | Mandatory| Description                |
  | ---------- | -------- | ---- | -------------------- |
  | shortArray | number[] | Yes  | Short array to write.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeShortArray([11, 12, 13]);
  console.log("RpcClient: writeShortArray is " + result);
  ```


### readShortArray

readShortArray(dataIn: number[]): void

Reads a short array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type    | Mandatory| Description                |
  | ------ | -------- | ---- | -------------------- |
  | dataIn | number[] | Yes  | Short array to read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeShortArray([11, 12, 13]);
  console.log("RpcClient: writeShortArray is " + result);
  let array = new Array(3);
  data.readShortArray(array);
  ```


### readShortArray

readShortArray(): number[]

Reads the short array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type    | Description            |
  | -------- | ---------------- |
  | number[] | Short array read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeShortArray([11, 12, 13]);
  console.log("RpcClient: writeShortArray is " + result);
  let array = data.readShortArray();
 console.log("RpcClient: readShortArray is " + array);
  ```


### writeIntArray

writeIntArray(intArray: number[]): boolean

Writes an integer array to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name  | Type    | Mandatory| Description              |
  | -------- | -------- | ---- | ------------------ |
  | intArray | number[] | Yes  | Integer array to write.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeIntArray([100, 111, 112]);
  console.log("RpcClient: writeIntArray is " + result);
  ```


### readIntArray

readIntArray(dataIn: number[]): void

Reads an integer array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type    | Mandatory| Description              |
  | ------ | -------- | ---- | ------------------ |
  | dataIn | number[] | Yes  | Integer array to read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeIntArray([100, 111, 112]);
  console.log("RpcClient: writeIntArray is " + result);
  let array = new Array(3);
  data.readIntArray(array);
  ```


### readIntArray

readIntArray(): number[]

Reads the integer array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type    | Description          |
  | -------- | -------------- |
  | number[] | Integer array read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeIntArray([100, 111, 112]);
  console.log("RpcClient: writeIntArray is " + result);
  let array = data.readIntArray();
  console.log("RpcClient: readIntArray is " + array);
  ```


### writeLongArray

writeLongArray(longArray: number[]): boolean

Writes a long array to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name   | Type    | Mandatory| Description                |
  | --------- | -------- | ---- | -------------------- |
  | longArray | number[] | Yes  | Long array to write.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeLongArray([1111, 1112, 1113]);
  console.log("RpcClient: writeLongArray is " + result);
  ```


### readLongArray

readLongArray(dataIn: number[]): void

Reads a long array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type    | Mandatory| Description                |
  | ------ | -------- | ---- | -------------------- |
  | dataIn | number[] | Yes  | Long array to read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeLongArray([1111, 1112, 1113]);
  console.log("RpcClient: writeLongArray is " + result);
  let array = new Array(3);
  data.readLongArray(array);
  ```


### readLongArray

readLongArray(): number[]

Reads the long array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

 | Type    | Description            |
 | -------- | ---------------- |
 | number[] | Long array read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeLongArray([1111, 1112, 1113]);
  console.log("RpcClient: writeLongArray is " + result);
  let array = data.readLongArray();
  console.log("RpcClient: readLongArray is " + array);
  ```


### writeFloatArray

writeFloatArray(floatArray: number[]): boolean

Writes a FloatArray to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type| Mandatory| Description|
  | ---------- | -------- | ---- | --- |
  | 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.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
  console.log("RpcClient: writeFloatArray is " + result);
  ```


### readFloatArray

readFloatArray(dataIn: number[]): void

Reads a FloatArray from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type| Mandatory| Description|
  | ------ | -------- | ---- | ------ |
  | 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.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
  console.log("RpcClient: writeFloatArray is " + result);
  let array = new Array(3);
  data.readFloatArray(array);
  ```


### readFloatArray

readFloatArray(): number[]

Reads the FloatArray from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type    | Description          |
  | -------- | -------------- |
  | number[] | FloatArray read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeFloatArray([1.2, 1.3, 1.4]);
  console.log("RpcClient: writeFloatArray is " + result);
  let array = data.readFloatArray();
  console.log("RpcClient: readFloatArray is " + array);
  ```


### writeDoubleArray

writeDoubleArray(doubleArray: number[]): boolean

Writes a DoubleArray to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name     | Type    | Mandatory| Description                    |
  | ----------- | -------- | ---- | ------------------------ |
  | doubleArray | number[] | Yes  | DoubleArray to write.|

**Return value**

  | Type   | Description                         |
  | ------- | ----------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
  console.log("RpcClient: writeDoubleArray is " + result);
  ```


### readDoubleArray

readDoubleArray(dataIn: number[]): void

Reads a DoubleArray from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type    | Mandatory| Description                    |
  | ------ | -------- | ---- | ------------------------ |
  | dataIn | number[] | Yes  | DoubleArray to read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
  console.log("RpcClient: writeDoubleArray is " + result);
  let array = new Array(3);
  data.readDoubleArray(array);
  ```


### readDoubleArray

readDoubleArray(): number[]

Reads the DoubleArray from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type    | Description                |
  | -------- | -------------------- |
  | number[] | DoubleArray read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
  console.log("RpcClient: writeDoubleArray is " + result);
  let array = data.readDoubleArray();
  console.log("RpcClient: readDoubleArray is " + array);
  ```


### writeBooleanArray

writeBooleanArray(booleanArray: boolean[]): boolean

Writes a Boolean array to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name      | Type     | Mandatory| Description              |
  | ------------ | --------- | ---- | ------------------ |
  | booleanArray | boolean[] | Yes  | Boolean array to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeBooleanArray([false, true, false]);
  console.log("RpcClient: writeBooleanArray is " + result);
  ```


### readBooleanArray

readBooleanArray(dataIn: boolean[]): void

Reads a Boolean array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type     | Mandatory| Description              |
  | ------ | --------- | ---- | ------------------ |
  | dataIn | boolean[] | Yes  | Boolean array to read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeBooleanArray([false, true, false]);
  console.log("RpcClient: writeBooleanArray is " + result);
  let array = new Array(3);
  data.readBooleanArray(array);
  ```


### readBooleanArray

readBooleanArray(): boolean[]

Reads the Boolean array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type     | Description          |
  | --------- | -------------- |
  | boolean[] | Boolean array read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeBooleanArray([false, true, false]);
  console.log("RpcClient: writeBooleanArray is " + result);
  let array = data.readBooleanArray();
  console.log("RpcClient: readBooleanArray is " + array);
  ```


### writeCharArray

writeCharArray(charArray: number[]): boolean

Writes a character array to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name   | Type    | Mandatory| Description                  |
  | --------- | -------- | ---- | ---------------------- |
  | charArray | number[] | Yes  | Character array to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeCharArray([97, 98, 88]);
  console.log("RpcClient: writeCharArray is " + result);
  ```


### readCharArray

readCharArray(dataIn: number[]): void

Reads a character array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type    | Mandatory| Description                  |
  | ------ | -------- | ---- | ---------------------- |
  | dataIn | number[] | Yes  | Character array to read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeCharArray([97, 98, 99]);
  console.log("RpcClient: writeCharArray is " + result);
  let array = new Array(3);
  data.readCharArray(array);
  ```


### readCharArray

readCharArray(): number[]

Reads the character array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type    | Description              |
  | -------- | ------------------ |
  | number[] | Character array read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeCharArray([97, 98, 99]);
  console.log("RpcClient: writeCharArray is " + result);
  let array = data.readCharArray();
  console.log("RpcClient: readCharArray is " + array);
  ```


### writeStringArray

writeStringArray(stringArray: string[]): boolean

Writes a string array to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name     | Type    | Mandatory| Description|
  | ----------- | -------- | ---- | ---------------- |
  | stringArray | string[] | Yes  | String array to write. The length of a single element in the array must be less than 40960 bytes.|

**Return value**

  | Type   | Description|
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeStringArray(["abc", "def"]);
  console.log("RpcClient: writeStringArray is " + result);
  ```


### readStringArray

readStringArray(dataIn: string[]): void

Reads a string array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type    | Mandatory| Description                |
  | ------ | -------- | ---- | -------------------- |
  | dataIn | string[] | Yes  | String array to read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeStringArray(["abc", "def"]);
  console.log("RpcClient: writeStringArray is " + result);
  let array = new Array(2);
  data.readStringArray(array);
  ```


### readStringArray

readStringArray(): string[]

Reads the string array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type    | Description            |
  | -------- | ---------------- |
  | string[] | String array read.|

**Example**

  ```
  let data = rpc.MessageParcel.create();
  let result = data.writeStringArray(["abc", "def"]);
  console.log("RpcClient: writeStringArray is " + result);
  let array = data.readStringArray();
  console.log("RpcClient: readStringArray is " + array);
  ```


### writeNoException<sup>8+</sup>

writeNoException(): void

Writes information to this **MessageParcel** object indicating that no exception occurred.

**System capability**: SystemCapability.Communication.IPC.Core

**Example**

  ```
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
      onRemoteRequest(code, data, reply, option) {
          if (code === 1) {
              console.log("RpcServer: onRemoteRequest called");
              reply.writeNoException();
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
  }
  ```

### readException<sup>8+</sup>

readException(): void

Reads the exception information from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Example**

  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
  };
  FA.connectAbility(want, connect);
  let option = new rpc.MessageOption();
  let data = rpc.MessageParcel.create();
  let reply = rpc.MessageParcel.create();
  data.writeInt(1);
  data.writeString("hello");
  proxy.sendMessageRequest(1, data, reply, option)
      .then(function(errCode) {
          if (errCode === 0) {
              console.log("sendMessageRequest got result");
              reply.readException();
              let msg = reply.readString();
              console.log("RPCTest: reply msg: " + msg);
          } else {
              console.log("RPCTest: sendMessageRequest failed, errCode: " + errCode);
          }
      }).catch(function(e) {
          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
      }).finally (() => {
          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
          data.reclaim();
          reply.reclaim();
      });
  ```

### writeSequenceableArray

writeSequenceableArray(sequenceableArray: Sequenceable[]): boolean

Writes a sequenceable array to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name           | Type          | Mandatory| Description                      |
  | ----------------- | -------------- | ---- | -------------------------- |
  | sequenceableArray | Sequenceable[] | Yes  | Sequenceable array to write.|

**Return value**

  | Type   | Description                             |
  | ------- | --------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  class MySequenceable {
      num: number;
      str: string;
      constructor(num, str) {
          this.num = num;
          this.str = str;
      }
      marshalling(messageParcel) {
          messageParcel.writeInt(this.num);
          messageParcel.writeString(this.str);
          return true;
      }
      unmarshalling(messageParcel) {
          this.num = messageParcel.readInt();
          this.str = messageParcel.readString();
          return true;
      }
  }
  let sequenceable = new MySequenceable(1, "aaa");
  let sequenceable2 = new MySequenceable(2, "bbb");
  let sequenceable3 = new MySequenceable(3, "ccc");
  let a = [sequenceable, sequenceable2, sequenceable3];
  let data = rpc.MessageParcel.create();
  let result = data.writeSequenceableArray(a);
  console.log("RpcClient: writeSequenceableArray is " + result);
  ```


### readSequenceableArray<sup>8+</sup>

readSequenceableArray(sequenceableArray: Sequenceable[]): void

Reads a sequenceable array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name           | Type          | Mandatory| Description                      |
  | ----------------- | -------------- | ---- | -------------------------- |
  | sequenceableArray | Sequenceable[] | Yes  | Sequenceable array to read.|

**Example**

  ```
  class MySequenceable {
      num: number;
      str: string;
      constructor(num, str) {
          this.num = num;
          this.str = str;
      }
      marshalling(messageParcel) {
          messageParcel.writeInt(this.num);
          messageParcel.writeString(this.str);
          return true;
      }
      unmarshalling(messageParcel) {
          this.num = messageParcel.readInt();
          this.str = messageParcel.readString();
          return true;
      }
  }
  let sequenceable = new MySequenceable(1, "aaa");
  let sequenceable2 = new MySequenceable(2, "bbb");
  let sequenceable3 = new MySequenceable(3, "ccc");
  let a = [sequenceable, sequenceable2, sequenceable3];
  let data = rpc.MessageParcel.create();
  let result = data.writeSequenceableArray(a);
  console.log("RpcClient: writeSequenceableArray is " + result);
  let b = [new MySequenceable(0, ""), new MySequenceable(0, ""), new MySequenceable(0, "")];
  data.readSequenceableArray(b);
  ```


### writeRemoteObjectArray<sup>8+</sup>

writeRemoteObjectArray(objectArray: IRemoteObject[]): boolean

Writes an array of **IRemoteObject** objects to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name     | Type           | Mandatory| Description|
  | ----------- | --------------- | ---- | ----- |
  | objectArray | IRemoteObject[] | Yes  | Array of **IRemoteObject** objects to write.|

**Return value**

  | Type   | Description                                                                                                                |
  | ------- | -------------------------------------------------------------------------------------------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** if the operation fails or if the **IRemoteObject** array is null.|

**Example**

  ```
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
          this.attachLocalInterface(this, descriptor);
      }
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
      asObject(): rpc.IRemoteObject {
          return this;
      }
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
  let data = rpc.MessageParcel.create();
  let result = data.writeRemoteObjectArray(a);
  console.log("RpcClient: writeRemoteObjectArray is " + result);
  ```


### readRemoteObjectArray<sup>8+</sup>

readRemoteObjectArray(objects: IRemoteObject[]): void

Reads an **IRemoteObject** array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name | Type           | Mandatory| Description|
  | ------- | --------------- | ---- | --------- |
  | objects | IRemoteObject[] | Yes  | **IRemoteObject** array to read.|

**Example**

  ```
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
          this.attachLocalInterface(this, descriptor);
      }
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
         return false;
      }
      asObject(): rpc.IRemoteObject {
          return this;
      }
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
  let data = rpc.MessageParcel.create();
  let result = data.writeRemoteObjectArray(a);
  let b = new Array(3);
  data.readRemoteObjectArray(b);
  ```


### readRemoteObjectArray<sup>8+</sup>

readRemoteObjectArray(): IRemoteObject[]

Reads the **IRemoteObject** array from this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type| Description|
  | --------------- | -------- |
  | IRemoteObject[] | **IRemoteObject** object array obtained.|

**Example**

  ```
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
          this.attachLocalInterface(this, descriptor);
      }
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
      asObject(): rpc.IRemoteObject {
          return this;
      }
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
  let data = rpc.MessageParcel.create();
  let result = data.writeRemoteObjectArray(a);
  console.log("RpcClient: readRemoteObjectArray is " + result);
  let b = data.readRemoteObjectArray();
  console.log("RpcClient: readRemoteObjectArray is " + b);
  ```


### closeFileDescriptor<sup>8+</sup>

static closeFileDescriptor(fd: number): void

Closes a file descriptor.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                |
  | ------ | ------ | ---- | -------------------- |
  | fd     | number | Yes  | File descriptor to close.|

**Example**

  ```
  import fileio from '@ohos.fileio';
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
  rpc.MessageParcel.closeFileDescriptor(fd);
  ```


### dupFileDescriptor<sup>8+</sup>

static dupFileDescriptor(fd: number) :number

Duplicates a file descriptor.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | fd     | number | Yes  | File descriptor to duplicate.|

**Return value**

  | Type  | Description                |
  | ------ | -------------------- |
  | number | New file descriptor.|

**Example**

  ```
  import fileio from '@ohos.fileio';
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
  let newFd = rpc.MessageParcel.dupFileDescriptor(fd);
  ```


### containFileDescriptors<sup>8+</sup>

containFileDescriptors(): boolean

Checks whether this **MessageParcel** object contains a file descriptor.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type   | Description                                                              |
  | ------- | ------------------------------------------------------------------ |
  | boolean | Returns **true** if the **MessageParcel** object contains a file descriptor; returns **false** otherwise.|

**Example**

  ```
  import fileio from '@ohos.fileio';
  let parcel = new rpc.MessageParcel();
  let filePath = "path/to/file";
  let r1 = parcel.containFileDescriptors();
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
  let writeResult = parcel.writeFileDescriptor(fd);
  console.log("RpcTest: parcel writeFd result is : " + writeResult);
  let containFD = parcel.containFileDescriptors();
  console.log("RpcTest: parcel after write fd containFd result is : " + containFD);
  ```


### writeFileDescriptor<sup>8+</sup>

writeFileDescriptor(fd: number): boolean

Writes a file descriptor to this **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description        |
  | ------ | ------ | ---- | ------------ |
  | fd     | number | Yes  | File descriptor to write.|

**Return value**

  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  import fileio from '@ohos.fileio';
  let parcel = new rpc.MessageParcel();
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
  let writeResult = parcel.writeFileDescriptor(fd);
  console.log("RpcTest: parcel writeFd result is : " + writeResult);
  ```


### readFileDescriptor<sup>8+</sup>
Z
zengyawen 已提交
5314 5315 5316

readFileDescriptor(): number

A
annie_wangli 已提交
5317
Reads the file descriptor from this **MessageParcel** object.
Z
zengyawen 已提交
5318

A
annie_wangli 已提交
5319
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5320

A
Annie_wang 已提交
5321
**Return value**
A
Annie_wang 已提交
5322

A
Annie_wang 已提交
5323 5324
  | Type  | Description            |
  | ------ | ---------------- |
A
annie_wangli 已提交
5325
  | number | File descriptor read.|
Z
zengyawen 已提交
5326

A
Annie_wang 已提交
5327
**Example**
A
annie_wangli 已提交
5328

Z
zengyawen 已提交
5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345
  ```
  import fileio from '@ohos.fileio';
  let parcel = new rpc.MessageParcel();
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
  let writeResult = parcel.writeFileDescriptor(fd);
  let readFD = parcel.readFileDescriptor();
  console.log("RpcTest: parcel read fd is : " + readFD);
  ```


### writeAshmem<sup>8+</sup>

writeAshmem(ashmem: Ashmem): boolean

Writes an anonymous shared object to this **MessageParcel** object.

A
annie_wangli 已提交
5346
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5347

A
Annie_wang 已提交
5348
**Parameters**
A
Annie_wang 已提交
5349

A
Annie_wang 已提交
5350 5351 5352
  | Name| Type  | Mandatory| Description                               |
  | ------ | ------ | ---- | ----------------------------------- |
  | ashmem | Ashmem | Yes  | Anonymous shared object to write.|
Z
zengyawen 已提交
5353

A
Annie_wang 已提交
5354
**Return value**
A
Annie_wang 已提交
5355

A
Annie_wang 已提交
5356 5357
  | Type   | Description                                                                |
  | ------- | -------------------------------------------------------------------- |
A
annie_wangli 已提交
5358
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
5359

A
Annie_wang 已提交
5360
**Example**
A
annie_wangli 已提交
5361

Z
zengyawen 已提交
5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375
  ```
  let parcel = new rpc.MessageParcel();
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024);
  let isWriteSuccess = parcel.writeAshmem(ashmem);
  console.log("RpcTest: write ashmem to result is : " + isWriteSuccess);
  ```


### readAshmem<sup>8+</sup>

readAshmem(): Ashmem

Reads the anonymous shared object from this **MessageParcel** object.

A
annie_wangli 已提交
5376
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5377

A
Annie_wang 已提交
5378
**Return value**
A
Annie_wang 已提交
5379

A
Annie_wang 已提交
5380 5381
  | Type  | Description              |
  | ------ | ------------------ |
A
annie_wangli 已提交
5382
  | Ashmem | Anonymous share object obtained.|
Z
zengyawen 已提交
5383

A
Annie_wang 已提交
5384
**Example**
A
annie_wangli 已提交
5385

Z
zengyawen 已提交
5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401
  ```
  let parcel = new rpc.MessageParcel();
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024);
  let isWriteSuccess = parcel.writeAshmem(ashmem);
  console.log("RpcTest: write ashmem to result is : " + isWriteSuccess);
  let readAshmem = parcel.readAshmem();
  console.log("RpcTest: read ashmem to result is : " + readAshmem);
  ```


### getRawDataCapacity<sup>8+</sup>

getRawDataCapacity(): number

Obtains the maximum amount of raw data that can be held by this **MessageParcel** object.

A
annie_wangli 已提交
5402
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5403

A
Annie_wang 已提交
5404
**Return value**
A
Annie_wang 已提交
5405

A
Annie_wang 已提交
5406 5407
  | Type  | Description                                                      |
  | ------ | ---------------------------------------------------------- |
A
annie_wangli 已提交
5408
  | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.|
Z
zengyawen 已提交
5409

A
Annie_wang 已提交
5410
**Example**
A
annie_wangli 已提交
5411

Z
zengyawen 已提交
5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424
  ```
  let parcel = new rpc.MessageParcel();
  let result = parcel.getRawDataCapacity();
  console.log("RpcTest: parcel get RawDataCapacity result is : " + result);
  ```


### writeRawData<sup>8+</sup>

writeRawData(rawData: number[], size: number): boolean

Writes raw data to this **MessageParcel** object.

A
annie_wangli 已提交
5425
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5426

A
Annie_wang 已提交
5427
**Parameters**
A
Annie_wang 已提交
5428

A
Annie_wang 已提交
5429 5430 5431 5432
  | Name | Type    | Mandatory| Description                              |
  | ------- | -------- | ---- | ---------------------------------- |
  | rawData | number[] | Yes  | Raw data to write.                |
  | size    | number   | Yes  | Size of the raw data, in bytes.|
Z
zengyawen 已提交
5433

A
Annie_wang 已提交
5434
**Return value**
A
Annie_wang 已提交
5435

A
Annie_wang 已提交
5436 5437
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
5438
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
5439

A
Annie_wang 已提交
5440
**Example**
A
annie_wangli 已提交
5441

Z
zengyawen 已提交
5442 5443
  ```
  let parcel = new rpc.MessageParcel();
A
Annie_wang 已提交
5444
  let arr = [1, 2, 3, 4, 5];
Z
zengyawen 已提交
5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455
  let isWriteSuccess = parcel.writeRawData(arr, arr.length);
  console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
  ```


### readRawData<sup>8+</sup>

readRawData(size: number): number[]

Reads raw data from this **MessageParcel** object.

A
annie_wangli 已提交
5456
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5457

A
Annie_wang 已提交
5458
**Parameters**
A
Annie_wang 已提交
5459

A
Annie_wang 已提交
5460 5461 5462
  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | size   | number | Yes  | Size of the raw data to read.|
Z
zengyawen 已提交
5463

A
Annie_wang 已提交
5464
**Return value**
A
Annie_wang 已提交
5465

A
Annie_wang 已提交
5466 5467
  | Type    | Description                          |
  | -------- | ------------------------------ |
A
annie_wangli 已提交
5468
  | number[] | Raw data obtained, in bytes.|
Z
zengyawen 已提交
5469

A
Annie_wang 已提交
5470
**Example**
A
annie_wangli 已提交
5471

Z
zengyawen 已提交
5472 5473
  ```
  let parcel = new rpc.MessageParcel();
A
Annie_wang 已提交
5474
  let arr = [1, 2, 3, 4, 5];
Z
zengyawen 已提交
5475 5476 5477 5478 5479 5480 5481
  let isWriteSuccess = parcel.writeRawData(arr, arr.length);
  console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
  let result = parcel.readRawData(5);
  console.log("RpcTest: parcel read raw data result is : " + result);
  ```


A
Annie_wang 已提交
5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586
## Parcelable<sup>9+</sup>

Writes an object to a **MessageSequence** and reads it from the **MessageSequence** during IPC.

### marshalling

marshalling(dataOut: MessageSequence): boolean

Marshals this **Parcelable** object into a **MessageSequence** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name | Type           | Mandatory| Description                                       |
  | ------- | --------------- | ---- | ------------------------------------------- |
  | dataOut | MessageSequence | Yes  | **MessageSequence** object to which the **Parcelable** object is to be marshaled.|

**Return value**

  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  class MyParcelable {
      num: number;
      str: string;
      constructor(num, str) {
          this.num = num;
          this.str = str;
      }
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
          return true;
      }
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
          return true;
      }
  }
  let parcelable = new MyParcelable(1, "aaa");
  let data = rpc.MessageSequence.create();
  let result = data.writeParcelable(parcelable);
  console.log("RpcClient: writeParcelable is " + result);
  let ret = new MyParcelable(0, "");
  let result2 = data.readParcelable(ret);
  console.log("RpcClient: readParcelable is " + result2);
  ```


### unmarshalling

unmarshalling(dataIn: MessageSequence): boolean

Unmarshals this **Parcelable** object from a **MessageSequence** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type           | Mandatory| Description                                           |
  | ------ | --------------- | ---- | ----------------------------------------------- |
  | dataIn | MessageSequence | Yes  | **MessageSequence** object from which the **Parcelable** object is to be unmarshaled.|

**Return value**

  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```
  class MyParcelable {
      num: number;
      str: string;
      constructor(num, str) {
          this.num = num;
          this.str = str;
      }
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
          return true;
      }
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
          return true;
      }
  }
  let parcelable = new MyParcelable(1, "aaa");
  let data = rpc.MessageSequence.create();
  let result = data.writeParcelable(parcelable);
  console.log("RpcClient: writeParcelable is " + result);
  let ret = new MyParcelable(0, "");
  let result2 = data.readParcelable(ret);
  console.log("RpcClient: readParcelable is " + result2);
  ```

Z
zengyawen 已提交
5587

A
Annie_wang 已提交
5588 5589 5590 5591 5592
## Sequenceable<sup>(deprecated)</sup>

>This class is no longer maintained since API version 9. You are advised to use the [Parcelable](#parcelable9).

Writes objects of classes to a **MessageParcel** and reads them from the **MessageParcel** during IPC.
Z
zengyawen 已提交
5593 5594 5595 5596 5597

### marshalling

marshalling(dataOut: MessageParcel): boolean

A
annie_wangli 已提交
5598 5599 5600
Marshals the sequenceable object into a **MessageParcel** object.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5601

A
Annie_wang 已提交
5602
**Parameters**
A
Annie_wang 已提交
5603

A
Annie_wang 已提交
5604 5605 5606
  | Name | Type                           | Mandatory| Description                                     |
  | ------- | ------------------------------- | ---- | ----------------------------------------- |
  | dataOut | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object to which the sequenceable object is to be marshaled.|
Z
zengyawen 已提交
5607

A
Annie_wang 已提交
5608
**Return value**
A
Annie_wang 已提交
5609

A
Annie_wang 已提交
5610 5611
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
5612
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
5613

A
Annie_wang 已提交
5614
**Example**
A
annie_wangli 已提交
5615

Z
zengyawen 已提交
5616 5617
  ```
  class MySequenceable {
A
Annie_wang 已提交
5618 5619 5620
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
5621
          this.num = num;
A
Annie_wang 已提交
5622
          this.str = str;
Z
zengyawen 已提交
5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646
      }
      marshalling(messageParcel) {
          messageParcel.writeInt(this.num);
          messageParcel.writeString(this.str);
          return true;
      }
      unmarshalling(messageParcel) {
          this.num = messageParcel.readInt();
          this.str = messageParcel.readString();
          return true;
      }
  }
  let sequenceable = new MySequenceable(1, "aaa");
  let data = rpc.MessageParcel.create();
  let result = data.writeSequenceable(sequenceable);
  console.log("RpcClient: writeSequenceable is " + result);
  let ret = new MySequenceable(0, "");
  let result2 = data.readSequenceable(ret);
  console.log("RpcClient: readSequenceable is " + result2);
  ```


### unmarshalling

A
Annie_wang 已提交
5647
unmarshalling(dataIn: MessageParcel): boolean
Z
zengyawen 已提交
5648 5649 5650

Unmarshals this sequenceable object from a **MessageParcel** object.

A
annie_wangli 已提交
5651 5652
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5653
**Parameters**
A
Annie_wang 已提交
5654

A
Annie_wang 已提交
5655 5656 5657
  | Name| Type                           | Mandatory| Description                                         |
  | ------ | ------------------------------- | ---- | --------------------------------------------- |
  | dataIn | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
Z
zengyawen 已提交
5658

A
Annie_wang 已提交
5659
**Return value**
A
Annie_wang 已提交
5660

A
Annie_wang 已提交
5661 5662
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
annie_wangli 已提交
5663
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
5664

A
Annie_wang 已提交
5665
**Example**
A
annie_wangli 已提交
5666

Z
zengyawen 已提交
5667 5668
  ```
  class MySequenceable {
A
Annie_wang 已提交
5669 5670 5671
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
5672
          this.num = num;
A
Annie_wang 已提交
5673
          this.str = str;
Z
zengyawen 已提交
5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697
      }
      marshalling(messageParcel) {
          messageParcel.writeInt(this.num);
          messageParcel.writeString(this.str);
          return true;
      }
      unmarshalling(messageParcel) {
          this.num = messageParcel.readInt();
          this.str = messageParcel.readString();
          return true;
      }
  }
  let sequenceable = new MySequenceable(1, "aaa");
  let data = rpc.MessageParcel.create();
  let result = data.writeSequenceable(sequenceable);
  console.log("RpcClient: writeSequenceable is " + result);
  let ret = new MySequenceable(0, "");
  let result2 = data.readSequenceable(ret);
  console.log("RpcClient: readSequenceable is " + result2);
  ```


## IRemoteBroker

A
Annie_wang 已提交
5698
Provides the holder of a remote proxy object.
Z
zengyawen 已提交
5699 5700 5701 5702 5703

### asObject

asObject(): IRemoteObject

A
Annie_wang 已提交
5704
Obtains a proxy or remote object. This API must be implemented by its derived classes.
Z
zengyawen 已提交
5705

A
annie_wangli 已提交
5706 5707
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5708
**Return value**
A
Annie_wang 已提交
5709

A
Annie_wang 已提交
5710 5711 5712
  | Type | Description|
  | ---- | ----- |
  | [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.|
Z
zengyawen 已提交
5713

A
Annie_wang 已提交
5714
**Example**
A
annie_wangli 已提交
5715

Z
zengyawen 已提交
5716 5717 5718 5719 5720 5721 5722 5723
  ```
  class TestAbility extends rpc.RemoteObject {
      asObject() {
          return this;
      }
  }
  ```

A
Annie_wang 已提交
5724
**Example**
A
annie_wangli 已提交
5725

Z
zengyawen 已提交
5726 5727
  ```
  class TestProxy {
A
Annie_wang 已提交
5728
      remote: rpc.RemoteObject;
Z
zengyawen 已提交
5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739
      constructor(remote) {
          this.remote = remote;
      }
      asObject() {
          return this.remote;
      }
  }
  ```

## DeathRecipient

A
annie_wangli 已提交
5740
Subscribes 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. 
Z
zengyawen 已提交
5741 5742 5743 5744 5745 5746 5747

### onRemoteDied

onRemoteDied(): void

Called to perform subsequent operations when a death notification of the remote object is received.

A
annie_wangli 已提交
5748 5749
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5750
**Example**
A
annie_wangli 已提交
5751

Z
zengyawen 已提交
5752 5753 5754
  ```
  class MyDeathRecipient {
      onRemoteDied() {
A
Annie_wang 已提交
5755
          console.log("server died");
Z
zengyawen 已提交
5756 5757 5758 5759
      }
  }
  ```

A
Annie_wang 已提交
5760
## RequestResult<sup>9+</sup>
Z
zengyawen 已提交
5761 5762 5763

Defines the response to the request.

A
annie_wangli 已提交
5764 5765
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779
  | Name   | Type           | Readable| Writable| Description                                 |
  | ------- | --------------- | ---- | ---- |-------------------------------------- |
  | errCode | number          | Yes  | No  | Error Code                             |
  | code    | number          | Yes  | No  | Message code.                           |
  | data    | MessageSequence | Yes  | No  | **MessageSequence** object sent to the remote process.|
  | reply   | MessageSequence | Yes  | No  | **MessageSequence** object returned by the remote process.  |

## SendRequestResult<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [RequestResult](#requestresult9).

Defines the response to the request.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5780

A
Annie_wang 已提交
5781 5782 5783 5784 5785 5786
  | Name   | Type         | Readable| Writable| Description                               |
  | ------- | ------------- | ---- | ---- | ----------------------------------- |
  | errCode | number        | Yes  | No  | Error Code                           |
  | code    | number        | Yes  | No  | Message code.                         |
  | data    | MessageParcel | Yes  | No  | **MessageParcel** object sent to the remote process.|
  | reply   | MessageParcel | Yes  | No  | **MessageParcel** object returned by the remote process.  |
Z
zengyawen 已提交
5787 5788 5789

## IRemoteObject

A
annie_wangli 已提交
5790
Provides methods to query of obtain interface descriptors, add or delete death notifications, dump object status to specific files, and send messages.
Z
zengyawen 已提交
5791

A
Annie_wang 已提交
5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810
### getLocalInterface<sup>9+</sup>

getLocalInterface(descriptor: string): IRemoteBroker

Obtains the interface.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name    | Type  | Mandatory| Description                |
  | ---------- | ------ | ---- | -------------------- |
  | descriptor | string | Yes  | Interface descriptor.|

**Return value**

  | Type         | Description                                         |
  | ------------- | --------------------------------------------- |
  | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
Z
zengyawen 已提交
5811

A
Annie_wang 已提交
5812 5813 5814
### queryLocalInterface<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).
Z
zengyawen 已提交
5815 5816 5817 5818 5819

queryLocalInterface(descriptor: string): IRemoteBroker

Obtains the interface.

A
annie_wangli 已提交
5820 5821
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5822
**Parameters**
A
Annie_wang 已提交
5823

A
Annie_wang 已提交
5824 5825 5826
  | Name    | Type  | Mandatory| Description                |
  | ---------- | ------ | ---- | -------------------- |
  | descriptor | string | Yes  | Interface descriptor.|
Z
zengyawen 已提交
5827

A
Annie_wang 已提交
5828
**Return value**
A
Annie_wang 已提交
5829

A
Annie_wang 已提交
5830 5831 5832
  | Type         | Description                                         |
  | ------------- | --------------------------------------------- |
  | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
Z
zengyawen 已提交
5833 5834


A
Annie_wang 已提交
5835
### sendRequest<sup>(deprecated)</sup>
Z
zengyawen 已提交
5836

A
Annie_wang 已提交
5837
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
A
Annie_wang 已提交
5838

A
Annie_wang 已提交
5839
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
Z
zengyawen 已提交
5840

A
annie_wangli 已提交
5841 5842 5843
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5844

A
Annie_wang 已提交
5845
**Parameters**
A
Annie_wang 已提交
5846

A
Annie_wang 已提交
5847 5848 5849 5850 5851 5852
  | Name | Type| Mandatory| Description |
  | ------- | ------------------------------- | ---- | ---- |
  | 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.|
  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
Z
zengyawen 已提交
5853

A
Annie_wang 已提交
5854
**Return value**
A
Annie_wang 已提交
5855

A
Annie_wang 已提交
5856 5857
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
5858 5859 5860
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


A
Annie_wang 已提交
5861 5862
### sendRequest<sup>8+(deprecated)</sup>

A
Annie_wang 已提交
5863
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
A
Annie_wang 已提交
5864

A
Annie_wang 已提交
5865
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
A
Annie_wang 已提交
5866

A
Annie_wang 已提交
5867 5868 5869 5870
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5871
**Parameters**
A
Annie_wang 已提交
5872

A
Annie_wang 已提交
5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972
  | Name | Type                           | Mandatory| Description                                                                                  |
  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |

**Return value**

  | Type                            | Description                                         |
  | -------------------------------- | --------------------------------------------- |
  | Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|


### sendMessageRequest<sup>9+</sup>

sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;

Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name | Type                           | Mandatory| Description                                                                                  |
  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
  | reply   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |

**Return value**

  | Type                        | Description                                     |
  | ---------------------------- | ----------------------------------------- |
  | Promise&lt;RequestResult&gt; | Promise used to return the **requestResult** object.|


### sendMessageRequest<sup>9+</sup>

sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void

Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name  | Type                              | Mandatory| Description                                                                                  |
  | -------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data     | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
  | reply    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
  | options  | [MessageOption](#messageoption)    | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
  | callback | AsyncCallback&lt;RequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |


### sendRequest<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).

sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void

Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name  | Type                                  | Mandatory| Description                                                                                  |
  | -------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data     | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply    | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options  | [MessageOption](#messageoption)        | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
  | callback | AsyncCallback&lt;SendRequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |


### registerDeathRecipient<sup>9+</sup>

registerDeathRecipient(recipient: DeathRecipient, flags: number): void

Adds 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.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.|
  | flags     | number                            | Yes  | Flag of the death notification.|

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900008 | proxy or remote object is invalid |
A
Annie_wang 已提交
5973

A
Annie_wang 已提交
5974

A
Annie_wang 已提交
5975
### addDeathrecipient<sup>(deprecated)</sup>
A
Annie_wang 已提交
5976

A
Annie_wang 已提交
5977
>This API is no longer maintained since API version 9. You are advised to use [registerDeathRecipient](#registerdeathrecipient9).
A
Annie_wang 已提交
5978

A
Annie_wang 已提交
5979
addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
A
Annie_wang 已提交
5980

A
Annie_wang 已提交
5981
Adds 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.
A
Annie_wang 已提交
5982 5983 5984

**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5985
**Parameters**
A
Annie_wang 已提交
5986

A
Annie_wang 已提交
5987 5988 5989 5990
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.|
  | flags     | number                            | Yes  | Flag of the death notification.|
Z
zengyawen 已提交
5991

A
Annie_wang 已提交
5992
**Return value**
A
Annie_wang 已提交
5993

A
Annie_wang 已提交
5994 5995 5996
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
  | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
Z
zengyawen 已提交
5997 5998


A
Annie_wang 已提交
5999
### unregisterDeathRecipient<sup>9+</sup>
Z
zengyawen 已提交
6000

A
Annie_wang 已提交
6001 6002 6003
unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void

Removes the callback used to receive death notifications of the remote object.
A
annie_wangli 已提交
6004 6005

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6006

A
Annie_wang 已提交
6007
**Parameters**
A
Annie_wang 已提交
6008

A
Annie_wang 已提交
6009 6010 6011 6012
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.|
  | flags     | number                            | Yes  | Flag of the death notification.|
Z
zengyawen 已提交
6013

A
Annie_wang 已提交
6014
**Error Code**
Z
zengyawen 已提交
6015

A
Annie_wang 已提交
6016
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
Z
zengyawen 已提交
6017

A
Annie_wang 已提交
6018 6019 6020
  | ID| Error Message|
  | ------- | -------- |
  | 1900008 | proxy or remote object is invalid |
Z
zengyawen 已提交
6021

A
Annie_wang 已提交
6022 6023 6024 6025 6026 6027 6028 6029

### removeDeathRecipient<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [unregisterDeathRecipient](#unregisterdeathrecipient9).

removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean

Removes the callback used to receive death notifications of the remote object.
Z
zengyawen 已提交
6030

A
annie_wangli 已提交
6031 6032
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
6033
**Parameters**
A
Annie_wang 已提交
6034

A
Annie_wang 已提交
6035 6036 6037 6038
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.|
  | flags     | number                            | Yes  | Flag of the death notification.|
Z
zengyawen 已提交
6039

A
Annie_wang 已提交
6040
**Return value**
A
Annie_wang 已提交
6041

A
Annie_wang 已提交
6042 6043 6044
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
  | boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
Z
zengyawen 已提交
6045 6046


A
Annie_wang 已提交
6047
### getDescriptor<sup>9+</sup>
Z
zengyawen 已提交
6048

A
Annie_wang 已提交
6049
getDescriptor(): string
Z
zengyawen 已提交
6050

A
Annie_wang 已提交
6051
Obtains the interface descriptor of this object. The interface descriptor is a string.
Z
zengyawen 已提交
6052

A
annie_wangli 已提交
6053 6054
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
6055
**Return value**
A
Annie_wang 已提交
6056

A
Annie_wang 已提交
6057 6058 6059
  | Type  | Description            |
  | ------ | ---------------- |
  | string | Interface descriptor obtained.|
Z
zengyawen 已提交
6060

A
Annie_wang 已提交
6061
**Error Code**
A
Annie_wang 已提交
6062

A
Annie_wang 已提交
6063 6064 6065 6066 6067
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900008 | proxy or remote object is invalid |
Z
zengyawen 已提交
6068 6069


A
Annie_wang 已提交
6070 6071 6072
### getInterfaceDescriptor<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
Z
zengyawen 已提交
6073 6074 6075

getInterfaceDescriptor(): string

A
annie_wangli 已提交
6076 6077 6078
Obtains the interface descriptor of this object. The interface descriptor is a string.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6079

A
Annie_wang 已提交
6080
**Return value**
A
Annie_wang 已提交
6081

A
Annie_wang 已提交
6082 6083
  | Type  | Description            |
  | ------ | ---------------- |
A
annie_wangli 已提交
6084
  | string | Interface descriptor obtained.|
Z
zengyawen 已提交
6085 6086 6087 6088 6089 6090


### isObjectDead

isObjectDead(): boolean

A
annie_wangli 已提交
6091
Checks whether this object is dead.
Z
zengyawen 已提交
6092

A
annie_wangli 已提交
6093 6094
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
6095
**Return value**
A
Annie_wang 已提交
6096

A
Annie_wang 已提交
6097 6098
  | Type   | Description                                       |
  | ------- | ------------------------------------------- |
A
annie_wangli 已提交
6099
  | boolean | Returns **true** if the object is dead; returns **false** otherwise.|
Z
zengyawen 已提交
6100 6101 6102 6103


## RemoteProxy

A
Annie_wang 已提交
6104
Provides APIs to implement **IRemoteObject**.
Z
zengyawen 已提交
6105

A
annie_wangli 已提交
6106 6107
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
6108
| Name                 | Value                     | Description                             |
A
annie_wangli 已提交
6109 6110
| --------------------- | ----------------------- | --------------------------------- |
| PING_TRANSACTION      | 1599098439 (0x5f504e47) | Internal instruction code used to test whether the IPC service is normal.|
A
Annie_wang 已提交
6111 6112
| DUMP_TRANSACTION      | 1598311760 (0x5f444d50) | Internal instruction code used to obtain the internal status of the binder. |
| INTERFACE_TRANSACTION | 1598968902 (0x5f4e5446) | Internal instruction code used to obtain the remote interface token. |
A
annie_wangli 已提交
6113 6114 6115 6116
| MIN_TRANSACTION_ID    | 1 (0x00000001)          | Minimum valid instruction code.                 |
| MAX_TRANSACTION_ID    | 16777215 (0x00FFFFFF)   | Maximum valid instruction code.                 |


A
Annie_wang 已提交
6117
### sendRequest<sup>(deprecated)</sup>
Z
zengyawen 已提交
6118

A
Annie_wang 已提交
6119
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
Z
zengyawen 已提交
6120

A
Annie_wang 已提交
6121
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
A
Annie_wang 已提交
6122

A
annie_wangli 已提交
6123 6124 6125
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6126

A
Annie_wang 已提交
6127
**Parameters**
A
Annie_wang 已提交
6128

A
Annie_wang 已提交
6129 6130 6131 6132 6133 6134
  | Name | Type                           | Mandatory| Description                                                                                  |
  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
Z
zengyawen 已提交
6135

A
Annie_wang 已提交
6136
**Return value**
A
Annie_wang 已提交
6137

A
Annie_wang 已提交
6138 6139
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
6140 6141 6142
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**
Z
zengyawen 已提交
6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159

  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
annie_wangli 已提交
6160 6161
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
6162 6163 6164 6165 6166 6167 6168
  };
  FA.connectAbility(want, connect);
  let option = new rpc.MessageOption();
  let data = rpc.MessageParcel.create();
  let reply = rpc.MessageParcel.create();
  data.writeInt(1);
  data.writeString("hello");
A
Annie_wang 已提交
6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179
  let ret: boolean = proxy.sendRequest(1, data, reply, option);
  if (ret) {
      console.log("sendRequest got result");
      let msg = reply.readString();
      console.log("RPCTest: reply msg: " + msg);
  } else {
      console.log("RPCTest: sendRequest failed");
  }
  console.log("RPCTest: sendRequest ends, reclaim parcel");
  data.reclaim();
  reply.reclaim();
Z
zengyawen 已提交
6180 6181
  ```

A
Annie_wang 已提交
6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252

### sendMessageRequest<sup>9+</sup>

sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;

Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name | Type                           | Mandatory| Description                                                                                  |
  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
  | reply   | [MessageSequence](#messagesequence9)  | Yes  | **MessageSequence** object that receives the response.                                                   |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |

**Return value**

  | Type                        | Description                                     |
  | ---------------------------- | ----------------------------------------- |
  | Promise&lt;RequestResult&gt; | Promise used to return the **requestResult** object.|

**Example**

  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
  };
  FA.connectAbility(want, connect);
  let option = new rpc.MessageOption();
  let data = rpc.MessageSequence.create();
  let reply = rpc.MessageSequence.create();
  data.writeInt(1);
  data.writeString("hello");
  proxy.sendMessageRequest(1, data, reply, option)
      .then(function(result) {
          if (result.errCode === 0) {
              console.log("sendMessageRequest got result");
              result.reply.readException();
              let msg = result.reply.readString();
              console.log("RPCTest: reply msg: " + msg);
          } else {
              console.log("RPCTest: sendMessageRequest failed, errCode: " + result.errCode);
          }
      }).catch(function(e) {
          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
      }).finally (() => {
          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
          data.reclaim();
          reply.reclaim();
      });
  ```


A
Annie_wang 已提交
6253 6254
### sendRequest<sup>8+(deprecated)</sup>

A
Annie_wang 已提交
6255
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
A
Annie_wang 已提交
6256

A
Annie_wang 已提交
6257
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
A
Annie_wang 已提交
6258

A
Annie_wang 已提交
6259 6260 6261 6262 6263
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**
A
Annie_wang 已提交
6264

A
Annie_wang 已提交
6265 6266 6267 6268 6269 6270
  | Name | Type                           | Mandatory| Description                                                                                  |
  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
A
Annie_wang 已提交
6271 6272

**Return value**
A
Annie_wang 已提交
6273

A
Annie_wang 已提交
6274 6275
  | Type                            | Description                                         |
  | -------------------------------- | --------------------------------------------- |
A
Annie_wang 已提交
6276 6277 6278
  | Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|

**Example**
A
annie_wangli 已提交
6279

Z
zengyawen 已提交
6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295
  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
annie_wangli 已提交
6296 6297
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323
  };
  FA.connectAbility(want, connect);
  let option = new rpc.MessageOption();
  let data = rpc.MessageParcel.create();
  let reply = rpc.MessageParcel.create();
  data.writeInt(1);
  data.writeString("hello");
  proxy.sendRequest(1, data, reply, option)
      .then(function(result) {
          if (result.errCode === 0) {
              console.log("sendRequest got result");
              result.reply.readException();
              let msg = result.reply.readString();
              console.log("RPCTest: reply msg: " + msg);
          } else {
              console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
          }
      }).catch(function(e) {
          console.log("RPCTest: sendRequest got exception: " + e.message);
      }).finally (() => {
          console.log("RPCTest: sendRequest ends, reclaim parcel");
          data.reclaim();
          reply.reclaim();
      });
  ```

A
Annie_wang 已提交
6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516
### sendMessageRequest<sup>9+</sup>

sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void

Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked at certain time after the response to **sendMessageRequest** is returned, and the reply contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name  | Type                              | Mandatory| Description                                                                                  |
  | -------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data     | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
  | reply    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
  | options  | [MessageOption](#messageoption)    | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
  | callback | AsyncCallback&lt;RequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |


**Example**

  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
  };
  function sendRequestCallback(result) {
      if (result.errCode === 0) {
          console.log("sendRequest got result");
          result.reply.readException();
          let msg = result.reply.readString();
          console.log("RPCTest: reply msg: " + msg);
      } else {
          console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
      }
      console.log("RPCTest: sendRequest ends, reclaim parcel");
      result.data.reclaim();
      result.reply.reclaim();
  }
  FA.connectAbility(want, connect);
  let option = new rpc.MessageOption();
  let data = rpc.MessageSequence.create();
  let reply = rpc.MessageSequence.create();
  data.writeInt(1);
  data.writeString("hello");
  try {
      proxy.sendRequest(1, data, reply, option, sendRequestCallback);
  } catch(error) {
      console.info("rpc send sequence request fail, errorCode " + error.code);
      console.info("rpc send sequence request fail, errorMessage " + error.message);
  }
  ```


### sendRequest<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).

sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void

Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name  | Type                                  | Mandatory| Description                                                                                  |
  | -------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data     | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply    | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options  | [MessageOption](#messageoption)        | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
  | callback | AsyncCallback&lt;SendRequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |

**Example**

  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
  };
  function sendRequestCallback(result) {
      if (result.errCode === 0) {
          console.log("sendRequest got result");
          result.reply.readException();
          let msg = result.reply.readString();
          console.log("RPCTest: reply msg: " + msg);
      } else {
          console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
      }
      console.log("RPCTest: sendRequest ends, reclaim parcel");
      result.data.reclaim();
      result.reply.reclaim();
  }
  FA.connectAbility(want, connect);
  let option = new rpc.MessageOption();
  let data = rpc.MessageParcel.create();
  let reply = rpc.MessageParcel.create();
  data.writeInt(1);
  data.writeString("hello");
  proxy.sendRequest(1, data, reply, option, sendRequestCallback);
  ```


### getLocalInterface<sup>9+</sup>

getLocalInterface(interface: string): IRemoteBroker

Obtains the **LocalInterface** object of an interface token.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name   | Type  | Mandatory| Description                  |
  | --------- | ------ | ---- | ---------------------- |
  | interface | string | Yes  | Interface descriptor.|

**Return value**

  | Type         | Description                                      |
  | ------------- | ------------------------------------------ |
  | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | --------  |
  | 1900006 | only remote object permitted |

**Example**

  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function (elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
      "bundleName":"com.ohos.server",
      "abilityName":"com.ohos.server.MainAbility",
  };
  FA.connectAbility(want, connect);
  try {
      let broker = proxy.getLocalInterface("testObject");
      console.log("RpcClient: getLocalInterface is " + broker);
  } catch(error) {
      console.info("rpc get local interface fail, errorCode " + error.code);
      console.info("rpc get local interface fail, errorMessage " + error.message);
  }
  ```


### queryLocalInterface<sup>(deprecated)</sup>
A
Annie_wang 已提交
6517

A
Annie_wang 已提交
6518 6519 6520
>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).

queryLocalInterface(interface: string): IRemoteBroker
A
Annie_wang 已提交
6521

A
Annie_wang 已提交
6522
Obtains the **LocalInterface** object of an interface token.
A
Annie_wang 已提交
6523 6524 6525 6526

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**
A
Annie_wang 已提交
6527

A
Annie_wang 已提交
6528 6529 6530
  | Name   | Type  | Mandatory| Description                  |
  | --------- | ------ | ---- | ---------------------- |
  | interface | string | Yes  | Interface descriptor.|
A
Annie_wang 已提交
6531 6532

**Return value**
A
Annie_wang 已提交
6533

A
Annie_wang 已提交
6534 6535 6536
  | Type         | Description                                      |
  | ------------- | ------------------------------------------ |
  | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
A
Annie_wang 已提交
6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547

**Example**

  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
A
Annie_wang 已提交
6548
      onDisconnect: function (elementName) {
A
Annie_wang 已提交
6549 6550 6551 6552 6553 6554 6555
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
Annie_wang 已提交
6556 6557
      "bundleName":"com.ohos.server",
      "abilityName":"com.ohos.server.MainAbility",
A
Annie_wang 已提交
6558 6559
  };
  FA.connectAbility(want, connect);
A
Annie_wang 已提交
6560 6561
  let broker = proxy.queryLocalInterface("testObject");
  console.log("RpcClient: queryLocalInterface is " + broker);
A
Annie_wang 已提交
6562
  ```
Z
zengyawen 已提交
6563 6564


A
Annie_wang 已提交
6565
### registerDeathRecipient<sup>9+</sup>
Z
zengyawen 已提交
6566

A
Annie_wang 已提交
6567 6568 6569
registerDeathRecipient(recipient: DeathRecipient, flags: number): void

Adds 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.
Z
zengyawen 已提交
6570

A
annie_wangli 已提交
6571
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6572

A
Annie_wang 已提交
6573
**Parameters**
A
Annie_wang 已提交
6574

A
Annie_wang 已提交
6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.|
  | flags     | number                            | Yes  | Flag of the death notification.|

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900008 | proxy or remote object is invalid |
Z
zengyawen 已提交
6587

A
Annie_wang 已提交
6588
**Example**
A
annie_wangli 已提交
6589

Z
zengyawen 已提交
6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605
  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
annie_wangli 已提交
6606 6607
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
6608
  };
A
Annie_wang 已提交
6609 6610 6611 6612
  FA.connectAbility(want, connect);
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
Z
zengyawen 已提交
6613 6614
      }
  }
A
Annie_wang 已提交
6615 6616 6617 6618 6619 6620 6621
  let deathRecipient = new MyDeathRecipient();
  try {
      proxy.registerDeathRecippient(deathRecipient, 0);
  } catch(error) {
      console.info("proxy register deathRecipient fail, errorCode " + error.code);
      console.info("proxy register deathRecipient fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
6622 6623 6624
  ```


A
Annie_wang 已提交
6625
### addDeathRecippient<sup>(deprecated)</sup>
Z
zengyawen 已提交
6626

A
Annie_wang 已提交
6627 6628 6629
>This API is no longer maintained since API version 9. You are advised to use [registerDeathRecipient](#registerdeathrecipient9).

addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
Z
zengyawen 已提交
6630

A
Annie_wang 已提交
6631
Adds a callback for receiving the death notifications of the remote object, including the death notifications of the remote proxy.
Z
zengyawen 已提交
6632

A
annie_wangli 已提交
6633
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6634

A
Annie_wang 已提交
6635
**Parameters**
A
Annie_wang 已提交
6636

A
Annie_wang 已提交
6637 6638 6639 6640
  | Name   | Type                             | Mandatory| Description                             |
  | --------- | --------------------------------- | ---- | --------------------------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.         |
  | flags     | number                            | Yes  | Flag of the death notification. This parameter is reserved. It is set to **0**.|
Z
zengyawen 已提交
6641

A
Annie_wang 已提交
6642
**Return value**
A
Annie_wang 已提交
6643

A
Annie_wang 已提交
6644 6645 6646
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
  | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
Z
zengyawen 已提交
6647

A
Annie_wang 已提交
6648
**Example**
A
annie_wangli 已提交
6649

Z
zengyawen 已提交
6650 6651 6652 6653 6654 6655 6656 6657
  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
A
Annie_wang 已提交
6658
      onDisconnect: function(elementName) {
Z
zengyawen 已提交
6659 6660 6661 6662 6663 6664 6665
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
Annie_wang 已提交
6666 6667
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
6668 6669
  };
  FA.connectAbility(want, connect);
A
Annie_wang 已提交
6670 6671 6672 6673 6674 6675 6676
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  let deathRecipient = new MyDeathRecipient();
  proxy.addDeathRecippient(deathRecipient, 0);
Z
zengyawen 已提交
6677 6678
  ```

A
Annie_wang 已提交
6679
### unregisterDeathRecipient<sup>9+</sup>
Z
zengyawen 已提交
6680

A
Annie_wang 已提交
6681
unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean
Z
zengyawen 已提交
6682

A
Annie_wang 已提交
6683
Removes the callback used to receive death notifications of the remote object.
Z
zengyawen 已提交
6684

A
annie_wangli 已提交
6685
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6686

A
Annie_wang 已提交
6687
**Parameters**
A
Annie_wang 已提交
6688

A
Annie_wang 已提交
6689 6690 6691 6692
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.|
  | flags     | number                            | Yes  | Flag of the death notification.|
Z
zengyawen 已提交
6693

A
Annie_wang 已提交
6694
**Error Code**
A
Annie_wang 已提交
6695

A
Annie_wang 已提交
6696 6697 6698 6699 6700
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900008 | proxy or remote object is invalid |
Z
zengyawen 已提交
6701

A
Annie_wang 已提交
6702
**Example**
A
annie_wangli 已提交
6703

Z
zengyawen 已提交
6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719
  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
annie_wangli 已提交
6720 6721
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
6722 6723 6724 6725
  };
  FA.connectAbility(want, connect);
  class MyDeathRecipient {
      onRemoteDied() {
A
Annie_wang 已提交
6726
          console.log("server died");
Z
zengyawen 已提交
6727 6728 6729
      }
  }
  let deathRecipient = new MyDeathRecipient();
A
Annie_wang 已提交
6730 6731 6732 6733 6734 6735 6736
  try {
      proxy.registerDeathRecippient(deathRecipient, 0);
      proxy.unregisterDeathRecippient(deathRecipient, 0);
  } catch(error) {
      console.info("proxy register deathRecipient fail, errorCode " + error.code);
      console.info("proxy register deathRecipient fail, errorMessage " + error.message);
  }
Z
zengyawen 已提交
6737 6738 6739
  ```


A
Annie_wang 已提交
6740 6741 6742
### removeDeathRecipient<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [unregisterDeathRecipient](#unregisterdeathrecipient9).
Z
zengyawen 已提交
6743

A
Annie_wang 已提交
6744
removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
Z
zengyawen 已提交
6745 6746 6747

Removes the callback used to receive death notifications of the remote object.

A
annie_wangli 已提交
6748
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6749

A
Annie_wang 已提交
6750
**Parameters**
A
Annie_wang 已提交
6751

A
Annie_wang 已提交
6752 6753 6754 6755
  | Name   | Type                             | Mandatory| Description                             |
  | --------- | --------------------------------- | ---- | --------------------------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.               |
  | flags     | number                            | Yes  | Flag of the death notification. This parameter is reserved. It is set to **0**.|
Z
zengyawen 已提交
6756

A
Annie_wang 已提交
6757
**Return value**
A
Annie_wang 已提交
6758

A
Annie_wang 已提交
6759 6760
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
annie_wangli 已提交
6761
  | boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
Z
zengyawen 已提交
6762

A
Annie_wang 已提交
6763
**Example**
A
annie_wangli 已提交
6764

Z
zengyawen 已提交
6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780
  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
annie_wangli 已提交
6781 6782
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
6783 6784 6785 6786
  };
  FA.connectAbility(want, connect);
  class MyDeathRecipient {
      onRemoteDied() {
A
Annie_wang 已提交
6787
          console.log("server died");
Z
zengyawen 已提交
6788 6789 6790 6791 6792 6793 6794 6795
      }
  }
  let deathRecipient = new MyDeathRecipient();
  proxy.addDeathRecippient(deathRecipient, 0);
  proxy.removeDeathRecipient(deathRecipient, 0);
  ```


A
Annie_wang 已提交
6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853
### getDescriptor<sup>9+</sup>

getDescriptor(): string

Obtains the interface descriptor of this object. The interface descriptor is a string.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description            |
  | ------ | ---------------- |
  | string | Interface descriptor obtained.|

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900008 | proxy or remote object is invalid |
  | 1900007 | communication failed              |

**Example**

  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
  };
  FA.connectAbility(want, connect);
  try {
      let descriptor = proxy.getDescriptor();
      console.log("RpcClient: descriptor is " + descriptor);
  } catch(error) {
      console.info("rpc get interface descriptor fail, errorCode " + error.code);
      console.info("rpc get interface descriptor fail, errorMessage " + error.message);
  }
  ```


### getInterfaceDescriptor<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
Z
zengyawen 已提交
6854 6855 6856 6857 6858

getInterfaceDescriptor(): string

Obtains the interface descriptor of this proxy object.

A
annie_wangli 已提交
6859
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6860

A
Annie_wang 已提交
6861
**Return value**
A
Annie_wang 已提交
6862

A
Annie_wang 已提交
6863 6864
  | Type  | Description              |
  | ------ | ------------------ |
A
annie_wangli 已提交
6865
  | string | Interface descriptor obtained.|
Z
zengyawen 已提交
6866

A
Annie_wang 已提交
6867
**Example**
A
annie_wangli 已提交
6868

Z
zengyawen 已提交
6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884
  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
annie_wangli 已提交
6885 6886
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899
  };
  FA.connectAbility(want, connect);
  let descriptor = proxy.getInterfaceDescriptor();
  console.log("RpcClient: descriptor is " + descriptor);
  ```


### isObjectDead

isObjectDead(): boolean

Checks whether the **RemoteObject** is dead.

A
annie_wangli 已提交
6900
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6901

A
Annie_wang 已提交
6902
**Return value**
A
Annie_wang 已提交
6903

A
Annie_wang 已提交
6904 6905
  | Type   | Description                                                     |
  | ------- | --------------------------------------------------------- |
A
annie_wangli 已提交
6906
  | boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.|
Z
zengyawen 已提交
6907

A
Annie_wang 已提交
6908
**Example**
A
annie_wangli 已提交
6909

Z
zengyawen 已提交
6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925
  ```
  import FA from "@ohos.ability.featureAbility";
  let proxy;
  let connect = {
      onConnect: function(elementName, remoteProxy) {
          console.log("RpcClient: js onConnect called.");
          proxy = remoteProxy;
      },
      onDisconnect: function(elementName) {
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
annie_wangli 已提交
6926 6927
      "bundleName": "com.ohos.server",
      "abilityName": "com.ohos.server.MainAbility",
Z
zengyawen 已提交
6928 6929 6930 6931 6932 6933 6934 6935 6936
  };
  FA.connectAbility(want, connect);
  let isDead = proxy.isObjectDead();
  console.log("RpcClient: isObjectDead is " + isDead);
  ```


## MessageOption

A
Annie_wang 已提交
6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953
Provides common message options (flag and wait time). Use the specified flag to construct the **MessageOption** object.

**System capability**: SystemCapability.Communication.IPC.Core

  | Name         | Value  | Description                                                       |
  | ------------- | ---- | ----------------------------------------------------------- |
  | TF_SYNC       | 0    | Synchronous call.                                                 |
  | TF_ASYNC      | 1    | Asynchronous call.                                                 |
  | TF_ACCEPT_FDS | 0x10 | Indication to **sendMessageRequest<sup>9+</sup>** for returning the file descriptor.|
  | TF_WAIT_TIME  | 8    | Default waiting time, in seconds.                                         |


### constructor<sup>9+</sup>

constructor(async?: boolean);

A constructor used to create a **MessageOption** object.
Z
zengyawen 已提交
6954

A
annie_wangli 已提交
6955
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6956

A
Annie_wang 已提交
6957 6958 6959 6960 6961
**Parameters**

  | Name   | Type  | Mandatory| Description                                  |
  | --------- | ------ | ---- | -------------------------------------- |
  | syncFlags | number | No  | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.|
Z
zengyawen 已提交
6962 6963 6964 6965


### constructor

A
Annie_wang 已提交
6966
constructor(syncFlags?: number, waitTime?: number)
Z
zengyawen 已提交
6967

A
annie_wangli 已提交
6968 6969 6970
A constructor used to create a **MessageOption** object.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6971

A
Annie_wang 已提交
6972
**Parameters**
A
Annie_wang 已提交
6973

A
Annie_wang 已提交
6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001
  | Name   | Type  | Mandatory| Description                                         |
  | --------- | ------ | ---- | --------------------------------------------- |
  | syncFlags | number | No  | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.       |
  | waitTime  | number | No  | Maximum wait time for an RPC call. The default value is **TF_WAIT_TIME**.|


### isAsync<sup>9+</sup>

isAsync(): boolean;

Checks whether **SendMessageRequest** is called synchronously or asynchronously.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type   | Description                                |
  | ------- | ------------------------------------ |
  | boolean | Call mode obtained.|


### setAsync<sup>9+</sup>

setAsync(async: boolean): void;

Sets whether **SendMessageRequest** is called synchronously or asynchronously.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7002 7003 7004 7005 7006 7007


### getFlags

getFlags(): number

A
annie_wangli 已提交
7008
Obtains the call flag, which can be synchronous or asynchronous.
Z
zengyawen 已提交
7009

A
annie_wangli 已提交
7010
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7011

A
Annie_wang 已提交
7012
**Return value**
A
Annie_wang 已提交
7013

A
Annie_wang 已提交
7014 7015
  | Type  | Description                                |
  | ------ | ------------------------------------ |
A
annie_wangli 已提交
7016
  | number | Call mode obtained.|
Z
zengyawen 已提交
7017 7018 7019 7020 7021 7022


### setFlags

setFlags(flags: number): void

A
annie_wangli 已提交
7023 7024 7025
Sets the call flag, which can be synchronous or asynchronous.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7026

A
Annie_wang 已提交
7027
**Parameters**
A
Annie_wang 已提交
7028

A
Annie_wang 已提交
7029 7030 7031
  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | flags  | number | Yes  | Call flag to set.|
Z
zengyawen 已提交
7032 7033 7034 7035 7036 7037 7038 7039


### getWaitTime

getWaitTime(): number

Obtains the maximum wait time for this RPC call.

A
annie_wangli 已提交
7040 7041
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7042
**Return value**
A
Annie_wang 已提交
7043

A
Annie_wang 已提交
7044 7045
  | Type  | Description             |
  | ------ | ----------------- |
A
annie_wangli 已提交
7046
  | number | Maximum wait time obtained.|
Z
zengyawen 已提交
7047 7048 7049 7050 7051 7052 7053 7054


### setWaitTime

setWaitTime(waitTime: number): void

Sets the maximum wait time for this RPC call.

A
annie_wangli 已提交
7055 7056
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7057
**Parameters**
A
Annie_wang 已提交
7058

A
Annie_wang 已提交
7059 7060 7061
  | Name  | Type  | Mandatory| Description                 |
  | -------- | ------ | ---- | --------------------- |
  | waitTime | number | Yes  | Maximum wait time to set.|
Z
zengyawen 已提交
7062 7063 7064 7065


## IPCSkeleton

A
annie_wangli 已提交
7066
Obtains IPC context information, including the UID and PID, local and remote device IDs, and whether the method is invoked on the same device.
Z
zengyawen 已提交
7067 7068 7069 7070 7071 7072 7073

### getContextObject

static getContextObject(): IRemoteObject

Obtains the system capability manager.

A
annie_wangli 已提交
7074
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7075

A
Annie_wang 已提交
7076
**Return value**
A
Annie_wang 已提交
7077

A
Annie_wang 已提交
7078 7079
  | Type                           | Description                |
  | ------------------------------- | -------------------- |
A
annie_wangli 已提交
7080
  | [IRemoteObject](#iremoteobject) | System capability manager obtained.|
Z
zengyawen 已提交
7081

A
Annie_wang 已提交
7082
**Example**
A
annie_wangli 已提交
7083

Z
zengyawen 已提交
7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095
  ```
  let samgr = rpc.IPCSkeleton.getContextObject();
  console.log("RpcServer: getContextObject result: " + samgr);
  ```


### getCallingPid

static getCallingPid(): number

Obtains the PID of the caller. This method 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.

A
annie_wangli 已提交
7096
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7097

A
Annie_wang 已提交
7098
**Return value**
A
Annie_wang 已提交
7099

A
Annie_wang 已提交
7100 7101
  | Type  | Description             |
  | ------ | ----------------- |
A
annie_wangli 已提交
7102
  | number | PID of the caller.|
Z
zengyawen 已提交
7103

A
Annie_wang 已提交
7104
**Example**
A
annie_wangli 已提交
7105

Z
zengyawen 已提交
7106 7107
  ```
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7108
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7109 7110 7111 7112
          let callerPid = rpc.IPCSkeleton.getCallingPid();
          console.log("RpcServer: getCallingPid result: " + callerPid);
          return true;
      }
A
Annie_wang 已提交
7113
 }
Z
zengyawen 已提交
7114 7115 7116 7117 7118 7119 7120 7121 7122
  ```


### getCallingUid

static getCallingUid(): number

Obtains the UID of the caller. This method 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.

A
annie_wangli 已提交
7123
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7124

A
Annie_wang 已提交
7125
**Return value**
A
Annie_wang 已提交
7126

A
Annie_wang 已提交
7127 7128
  | Type  | Description             |
  | ------ | ----------------- |
A
annie_wangli 已提交
7129
  | number | UID of the caller.|
Z
zengyawen 已提交
7130

A
Annie_wang 已提交
7131
**Example**
A
annie_wangli 已提交
7132

Z
zengyawen 已提交
7133 7134
  ```
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7135
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7136 7137 7138 7139 7140 7141 7142
          let callerUid = rpc.IPCSkeleton.getCallingUid();
          console.log("RpcServer: getCallingUid result: " + callerUid);
          return true;
      }
  }
  ```

A
Annie_wang 已提交
7143

A
Annie_wang 已提交
7144
### getCallingTokenId<sup>8+</sup>
A
annie_wangli 已提交
7145 7146 7147 7148 7149 7150 7151 7152

static getCallingTokenId(): number;

Obtains the caller's token ID, which is used to verify the caller identity.

**System capability**: SystemCapability.Communication.IPC.Core


A
Annie_wang 已提交
7153 7154 7155 7156 7157 7158 7159
**Return value**
 
   | Type  | Description                 |
   | ------ | --------------------- |
   | number | Token ID of the caller obtained.|
  
**Example**
A
annie_wangli 已提交
7160 7161 7162

  ```
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7163
      onRemoteMessageRequest(code, data, reply, option) {
A
annie_wangli 已提交
7164 7165 7166 7167 7168 7169 7170
          let callerTokenId = rpc.IPCSkeleton.getCallingTokenId();
          console.log("RpcServer: getCallingTokenId result: " + callerTokenId);
          return true;
      }
  }
  ```

Z
zengyawen 已提交
7171

A
Annie_wang 已提交
7172
### getCallingDeviceID
Z
zengyawen 已提交
7173 7174 7175 7176 7177

static getCallingDeviceID(): string

Obtains the ID of the device hosting the caller's process.

A
annie_wangli 已提交
7178
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7179

A
Annie_wang 已提交
7180
**Return value**
A
Annie_wang 已提交
7181

A
Annie_wang 已提交
7182 7183
  | Type  | Description                        |
  | ------ | ---------------------------- |
A
annie_wangli 已提交
7184
  | string | Device ID obtained.|
Z
zengyawen 已提交
7185

A
Annie_wang 已提交
7186
**Example**
A
annie_wangli 已提交
7187

Z
zengyawen 已提交
7188 7189
  ```
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7190
      onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7191
          let callerDeviceID = rpc.IPCSkeleton.getCallingDeviceID();
Z
zengyawen 已提交
7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204
          console.log("RpcServer: callerDeviceID is: " + callerDeviceID);
          return true;
      }
  }
  ```


### getLocalDeviceID

static getLocalDeviceID(): string

Obtains the local device ID.

A
annie_wangli 已提交
7205
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7206

A
Annie_wang 已提交
7207
**Return value**
A
Annie_wang 已提交
7208

A
Annie_wang 已提交
7209 7210
  | Type  | Description              |
  | ------ | ------------------ |
A
annie_wangli 已提交
7211
  | string | Local device ID obtained.|
Z
zengyawen 已提交
7212

A
Annie_wang 已提交
7213
**Example**
A
annie_wangli 已提交
7214

Z
zengyawen 已提交
7215 7216
  ```
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7217
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229
          let localDeviceID = rpc.IPCSkeleton.getLocalDeviceID();
          console.log("RpcServer: localDeviceID is: " + localDeviceID);
          return true;
      }
  }
  ```


### isLocalCalling

static isLocalCalling(): boolean

A
annie_wangli 已提交
7230
Checks whether the remote process is a process of the local device.
Z
zengyawen 已提交
7231

A
annie_wangli 已提交
7232
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7233

A
Annie_wang 已提交
7234
**Return value**
A
Annie_wang 已提交
7235

A
Annie_wang 已提交
7236 7237
  | Type   | Description                                                     |
  | ------- | --------------------------------------------------------- |
A
annie_wangli 已提交
7238
  | boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
Z
zengyawen 已提交
7239

A
Annie_wang 已提交
7240
**Example**
A
annie_wangli 已提交
7241

Z
zengyawen 已提交
7242 7243
  ```
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7244
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7245 7246 7247 7248 7249 7250 7251 7252
          let isLocalCalling = rpc.IPCSkeleton.isLocalCalling();
          console.log("RpcServer: isLocalCalling is: " + isLocalCalling);
          return true;
      }
  }
  ```


A
Annie_wang 已提交
7253
### flushCmdBuffer<sup>9+</sup>
Z
zengyawen 已提交
7254

A
Annie_wang 已提交
7255
static flushCmdBuffer(object: IRemoteObject): void
Z
zengyawen 已提交
7256 7257 7258

Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. It is recommended that this method be called before any time-sensitive operation is performed.

A
annie_wangli 已提交
7259 7260
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7261
**Parameters**
A
Annie_wang 已提交
7262

A
Annie_wang 已提交
7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290
  | Name| Type                           | Mandatory| Description               |
  | ------ | ------------------------------- | ---- | ------------------- |
  | object | [IRemoteObject](#iremoteobject) | Yes  | **RemoteProxy** specified. |


**Example**

  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
  }
  let remoteObject = new TestRemoteObject("aaa");
  try {
      rpc.IPCSkeleton.flushCmdBuffer(remoteObject);
  } catch(error) {
      console.info("proxy set calling identity fail, errorCode " + error.code);
      console.info("proxy set calling identity fail, errorMessage " + error.message);
  }
  ```


### flushCommands<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [flushCmdBuffer](#flushcmdbuffer9).

static flushCommands(object: IRemoteObject): number
Z
zengyawen 已提交
7291

A
Annie_wang 已提交
7292 7293 7294 7295 7296 7297 7298 7299 7300
Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. It is recommended that this method be called before any time-sensitive operation is performed.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type                           | Mandatory| Description               |
  | ------ | ------------------------------- | ---- | ------------------- |
  | object | [IRemoteObject](#iremoteobject) | Yes  | **RemoteProxy** specified. |
Z
zengyawen 已提交
7301

A
Annie_wang 已提交
7302
**Return value**
A
Annie_wang 已提交
7303

A
Annie_wang 已提交
7304 7305
  | Type  | Description                                                                             |
  | ------ | --------------------------------------------------------------------------------- |
A
annie_wangli 已提交
7306
  | 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.|
Z
zengyawen 已提交
7307

A
Annie_wang 已提交
7308
**Example**
A
annie_wangli 已提交
7309

Z
zengyawen 已提交
7310
  ```
A
Annie_wang 已提交
7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
  }
  let remoteObject = new TestRemoteObject("aaa");
Z
zengyawen 已提交
7331 7332 7333 7334 7335 7336
  let ret = rpc.IPCSkeleton.flushCommands(remoteObject);
  console.log("RpcServer: flushCommands result: " + ret);
  ```

### resetCallingIdentity

A
Annie_wang 已提交
7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364
static resetCallingIdentity(): string

Changes the UID and PID of the remote user to the UID and PID of the local user. This method is used in scenarios such as identity authentication.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                                |
  | ------ | ------------------------------------ |
  | string | String containing the UID and PID of the remote user.|

**Example**

  ```
  class Stub extends rpc.RemoteObject {
      onRemoteMessageRequest(code, data, reply, option) {
          let callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
          console.log("RpcServer: callingIdentity is: " + callingIdentity);
          return true;
      }
  }
  ```


### restoreCallingIdentity<sup>9+</sup>

static restoreCallingIdentity(identity: string): void
Z
zengyawen 已提交
7365 7366 7367

Changes the UID and PID of the remote user to the UID and PID of the local user. This method is used in scenarios such as identity authentication.

A
annie_wangli 已提交
7368
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7369

A
Annie_wang 已提交
7370
**Parameters**
A
Annie_wang 已提交
7371

A
Annie_wang 已提交
7372 7373 7374
  | Name  | Type  | Mandatory| Description                                                              |
  | -------- | ------ | ---- | ------------------------------------------------------------------ |
  | identity | string | Yes  | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
Z
zengyawen 已提交
7375

A
Annie_wang 已提交
7376
**Example**
A
annie_wangli 已提交
7377

Z
zengyawen 已提交
7378 7379
  ```
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7380 7381 7382 7383 7384 7385 7386 7387
      onRemoteMessageRequest(code, data, reply, option) {
          let callingIdentity = null;
          try {
              callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
              console.log("RpcServer: callingIdentity is: " + callingIdentity);
          } finally {
              rpc.IPCSkeleton.restoreCallingIdentity("callingIdentity ");
          }
Z
zengyawen 已提交
7388 7389 7390 7391 7392 7393
          return true;
      }
  }
  ```


A
Annie_wang 已提交
7394 7395 7396
### setCallingIdentity<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [restoreCallingIdentity](#restorecallingidentity9).
Z
zengyawen 已提交
7397

A
Annie_wang 已提交
7398
static setCallingIdentity(identity: string): boolean
Z
zengyawen 已提交
7399 7400 7401

Restores the UID and PID of the remote user. 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**.

A
annie_wangli 已提交
7402 7403
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7404
**Parameters**
A
Annie_wang 已提交
7405

A
Annie_wang 已提交
7406 7407 7408
  | Name  | Type  | Mandatory| Description                                                              |
  | -------- | ------ | ---- | ------------------------------------------------------------------ |
  | identity | string | Yes  | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
Z
zengyawen 已提交
7409

A
Annie_wang 已提交
7410
**Return value**
A
Annie_wang 已提交
7411

A
Annie_wang 已提交
7412 7413
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
7414
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
7415

A
Annie_wang 已提交
7416
**Example**
A
annie_wangli 已提交
7417

Z
zengyawen 已提交
7418 7419
  ```
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7420
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442
          let callingIdentity = null;
          try {
              callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
              console.log("RpcServer: callingIdentity is: " + callingIdentity);
          } finally {
              let ret = rpc.IPCSkeleton.setCallingIdentity("callingIdentity ");
              console.log("RpcServer: setCallingIdentity is: " + ret);
          }
          return true;
      }
  }
  ```


## RemoteObject

Provides methods to implement **RemoteObject**. The service provider must inherit from this class.

### constructor

constructor(descriptor: string)

A
annie_wangli 已提交
7443 7444 7445
A constructor used to create a **RemoteObject** object.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7446

A
Annie_wang 已提交
7447
**Parameters**
A
Annie_wang 已提交
7448

A
Annie_wang 已提交
7449 7450 7451
  | Name    | Type  | Mandatory| Description        |
  | ---------- | ------ | ---- | ------------ |
  | descriptor | string | Yes  | Interface descriptor.|
Z
zengyawen 已提交
7452 7453


A
Annie_wang 已提交
7454
### sendRequest<sup>(deprecated)</sup>
Z
zengyawen 已提交
7455

A
Annie_wang 已提交
7456
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
Z
zengyawen 已提交
7457

A
Annie_wang 已提交
7458
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
A
Annie_wang 已提交
7459

A
annie_wangli 已提交
7460 7461 7462
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7463

A
Annie_wang 已提交
7464
**Parameters**
A
Annie_wang 已提交
7465

A
Annie_wang 已提交
7466 7467 7468 7469 7470 7471
  | Name | Type                           | Mandatory| Description                                                                                  |
  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
Z
zengyawen 已提交
7472

A
Annie_wang 已提交
7473
**Return value**
A
Annie_wang 已提交
7474

A
Annie_wang 已提交
7475 7476
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
7477
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
7478

A
Annie_wang 已提交
7479
**Example**
A
annie_wangli 已提交
7480

Z
zengyawen 已提交
7481
  ```
A
Annie_wang 已提交
7482 7483 7484 7485 7486
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
7487 7488 7489 7490
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7491 7492 7493 7494 7495 7496 7497 7498 7499
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
7500 7501 7502 7503 7504 7505 7506
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  let option = new rpc.MessageOption();
  let data = rpc.MessageParcel.create();
  let reply = rpc.MessageParcel.create();
  data.writeInt(1);
  data.writeString("hello");
A
Annie_wang 已提交
7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517
  let ret: boolean = testRemoteObject.sendRequest(1, data, reply, option);
  if (ret) {
      console.log("sendRequest got result");
      let msg = reply.readString();
      console.log("RPCTest: reply msg: " + msg);
  } else {
      console.log("RPCTest: sendRequest failed");
  }
  console.log("RPCTest: sendRequest ends, reclaim parcel");
  data.reclaim();
  reply.reclaim();
Z
zengyawen 已提交
7518 7519 7520
  ```


A
Annie_wang 已提交
7521 7522
### sendRequest<sup>8+(deprecated)</sup>

A
Annie_wang 已提交
7523
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
A
Annie_wang 已提交
7524

A
Annie_wang 已提交
7525
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
A
Annie_wang 已提交
7526

A
Annie_wang 已提交
7527 7528 7529 7530 7531
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**
A
Annie_wang 已提交
7532

A
Annie_wang 已提交
7533 7534 7535 7536 7537 7538
  | Name | Type                           | Mandatory| Description                                                                                  |
  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data    | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
A
Annie_wang 已提交
7539 7540

**Return value**
A
Annie_wang 已提交
7541

A
Annie_wang 已提交
7542 7543
  | Type                            | Description                                         |
  | -------------------------------- | --------------------------------------------- |
A
Annie_wang 已提交
7544 7545 7546
  | Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|

**Example**
A
annie_wangli 已提交
7547

Z
zengyawen 已提交
7548
  ```
A
Annie_wang 已提交
7549 7550 7551 7552 7553
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
7554 7555 7556 7557
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7558 7559 7560 7561 7562 7563 7564 7565 7566
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  let option = new rpc.MessageOption();
  let data = rpc.MessageParcel.create();
  let reply = rpc.MessageParcel.create();
  data.writeInt(1);
  data.writeString("hello");
  testRemoteObject.sendRequest(1, data, reply, option)
      .then(function(result) {
          if (result.errCode === 0) {
              console.log("sendRequest got result");
              result.reply.readException();
              let msg = result.reply.readString();
              console.log("RPCTest: reply msg: " + msg);
          } else {
              console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
          }
      }).catch(function(e) {
          console.log("RPCTest: sendRequest got exception: " + e.message);
      }).finally (() => {
          console.log("RPCTest: sendRequest ends, reclaim parcel");
          data.reclaim();
          reply.reclaim();
      });
  ```

A
Annie_wang 已提交
7593
### sendMessageRequest<sup>9+</sup>
A
Annie_wang 已提交
7594

A
Annie_wang 已提交
7595
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
A
Annie_wang 已提交
7596

A
Annie_wang 已提交
7597
Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
A
Annie_wang 已提交
7598 7599 7600 7601

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**
A
Annie_wang 已提交
7602

A
Annie_wang 已提交
7603 7604 7605 7606 7607 7608
  | Name | Type                           | Mandatory| Description                                                                                  |
  | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data    | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
  | reply   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
  | options | [MessageOption](#messageoption) | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
A
Annie_wang 已提交
7609 7610

**Return value**
A
Annie_wang 已提交
7611

A
Annie_wang 已提交
7612 7613 7614
  | Type                        | Description                                         |
  | ---------------------------- | --------------------------------------------- |
  | Promise&lt;RequestResult&gt; | Promise used to return the **sendRequestResult** object.|
A
Annie_wang 已提交
7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625

**Example**

  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  let option = new rpc.MessageOption();
A
Annie_wang 已提交
7626 7627
  let data = rpc.MessageSequence.create();
  let reply = rpc.MessageSequence.create();
A
Annie_wang 已提交
7628 7629
  data.writeInt(1);
  data.writeString("hello");
A
Annie_wang 已提交
7630
  testRemoteObject.sendMessageRequest(1, data, reply, option)
A
Annie_wang 已提交
7631 7632
      .then(function(result) {
          if (result.errCode === 0) {
A
Annie_wang 已提交
7633
              console.log("sendMessageRequest got result");
A
Annie_wang 已提交
7634 7635 7636 7637
              result.reply.readException();
              let msg = result.reply.readString();
              console.log("RPCTest: reply msg: " + msg);
          } else {
A
Annie_wang 已提交
7638
              console.log("RPCTest: sendMessageRequest failed, errCode: " + result.errCode);
A
Annie_wang 已提交
7639 7640
          }
      }).catch(function(e) {
A
Annie_wang 已提交
7641
          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
A
Annie_wang 已提交
7642
      }).finally (() => {
A
Annie_wang 已提交
7643
          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
A
Annie_wang 已提交
7644 7645 7646 7647
          data.reclaim();
          reply.reclaim();
      });
  ```
Z
zengyawen 已提交
7648

A
Annie_wang 已提交
7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701

### sendMessageRequest<sup>9+</sup>

sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void

Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name       | Type                              | Mandatory| Description                                                                                  |
  | ------------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data          | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object holding the data to send.                                           |
  | reply         | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that receives the response.                                                   |
  | options       | [MessageOption](#messageoption)    | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
  | AsyncCallback | AsyncCallback&lt;RequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |

**Example**

  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
  }
  function sendRequestCallback(result) {
      if (result.errCode === 0) {
          console.log("sendRequest got result");
          result.reply.readException();
          let msg = result.reply.readString();
          console.log("RPCTest: reply msg: " + msg);
      } else {
          console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
      }
      console.log("RPCTest: sendRequest ends, reclaim parcel");
      result.data.reclaim();
      result.reply.reclaim();
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  let option = new rpc.MessageOption();
  let data = rpc.MessageSequence.create();
  let reply = rpc.MessageSequence.create();
  data.writeInt(1);
  data.writeString("hello");
  testRemoteObject.sendMessageRequest(1, data, reply, option, sendRequestCallback);
  ```


### sendRequest<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
Z
zengyawen 已提交
7702 7703 7704

sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void

A
annie_wangli 已提交
7705 7706 7707
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
7708

A
Annie_wang 已提交
7709
**Parameters**
A
Annie_wang 已提交
7710

A
Annie_wang 已提交
7711 7712 7713 7714 7715 7716 7717
  | Name       | Type                                  | Mandatory| Description                                                                                  |
  | ------------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
  | 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.|
  | data          | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object holding the data to send.                                             |
  | reply         | [MessageParcel](#messageparceldeprecated)        | Yes  | **MessageParcel** object that receives the response.                                                     |
  | options       | [MessageOption](#messageoption)        | Yes  | Request sending mode, which can be synchronous (default) or asynchronous.                                                  |
  | AsyncCallback | AsyncCallback&lt;SendRequestResult&gt; | Yes  | Callback for receiving the sending result.                                                                  |
Z
zengyawen 已提交
7718

A
Annie_wang 已提交
7719
**Example**
A
annie_wangli 已提交
7720

Z
zengyawen 已提交
7721
  ```
A
Annie_wang 已提交
7722 7723 7724 7725 7726
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
7727 7728 7729 7730
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7731 7732 7733 7734 7735 7736 7737 7738 7739
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763
  }
  function sendRequestCallback(result) {
      if (result.errCode === 0) {
          console.log("sendRequest got result");
          result.reply.readException();
          let msg = result.reply.readString();
          console.log("RPCTest: reply msg: " + msg);
      } else {
          console.log("RPCTest: sendRequest failed, errCode: " + result.errCode);
      }
      console.log("RPCTest: sendRequest ends, reclaim parcel");
      result.data.reclaim();
      result.reply.reclaim();
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  let option = new rpc.MessageOption();
  let data = rpc.MessageParcel.create();
  let reply = rpc.MessageParcel.create();
  data.writeInt(1);
  data.writeString("hello");
  testRemoteObject.sendRequest(1, data, reply, option, sendRequestCallback);
  ```


A
Annie_wang 已提交
7764 7765
### onRemoteRequest<sup>8+(deprecated)</sup>

A
Annie_wang 已提交
7766
>This API is no longer maintained since API version 9. You are advised to use [onRemoteMessageRequest](#onremotemessagerequest9).
Z
zengyawen 已提交
7767

A
Annie_wang 已提交
7768
onRemoteRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
A
Annie_wang 已提交
7769

A
Annie_wang 已提交
7770
Provides a response to **sendMessageRequest()**. The server processes the request and returns a response in this API.
Z
zengyawen 已提交
7771

A
annie_wangli 已提交
7772 7773
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7774
**Parameters**
A
Annie_wang 已提交
7775

A
Annie_wang 已提交
7776 7777 7778 7779 7780 7781
  | Name| Type                           | Mandatory| Description                                   |
  | ------ | ------------------------------- | ---- | --------------------------------------- |
  | code   | number                          | Yes  | Service request code sent by the remote end.                 |
  | data   | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object that holds the parameters called by the client.|
  | reply  | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object carrying the result.          |
  | option | [MessageOption](#messageoption) | Yes  | Whether the operation is synchronous or asynchronous.               |
Z
zengyawen 已提交
7782

A
Annie_wang 已提交
7783
**Return value**
A
Annie_wang 已提交
7784

A
Annie_wang 已提交
7785 7786
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
7787
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
7788

A
Annie_wang 已提交
7789
**Example**
A
annie_wangli 已提交
7790

A
Annie_wang 已提交
7791
  ```ets
A
Annie_wang 已提交
7792 7793 7794 7795 7796
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
7797 7798 7799 7800
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7801 7802 7803 7804 7805 7806 7807 7808 7809
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820
      onRemoteRequest(code, data, reply, option) {
          if (code === 1) {
              console.log("RpcServer: onRemoteRequest called");
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
  }
  ```
A
Annie_wang 已提交
7821

A
Annie_wang 已提交
7822 7823 7824
### onRemoteMessageRequest<sup>9+</sup>

onRemoteMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): boolean | Promise\<boolean>
A
Annie_wang 已提交
7825 7826

> **NOTE**<br/>
A
Annie_wang 已提交
7827 7828 7829
>
>* You are advised to overload **onRemoteMessageRequest** preferentially, which implements synchronous and asynchronous message processing.
>* If both onRemoteRequest() and onRemoteMessageRequest() are overloaded, only the onRemoteMessageRequest() takes effect.
A
Annie_wang 已提交
7830

A
Annie_wang 已提交
7831
Provides a response to **sendMessageRequest()**. The server processes the request synchronously or asynchronously and returns the result in this API.
A
Annie_wang 已提交
7832 7833 7834 7835 7836

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

A
Annie_wang 已提交
7837 7838 7839 7840 7841 7842
  | Name| Type                           | Mandatory| Description                                     |
  | ------ | ------------------------------- | ---- | ----------------------------------------- |
  | code   | number                          | Yes  | Service request code sent by the remote end.                   |
  | data   | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object that holds the parameters called by the client.|
  | reply  | [MessageSequence](#messagesequence9) | Yes  | **MessageSequence** object to which the result is written.          |
  | option | [MessageOption](#messageoption) | Yes  | Whether the operation is synchronous or asynchronous.                 |
A
Annie_wang 已提交
7843 7844 7845

**Return value**

A
Annie_wang 已提交
7846 7847 7848 7849
  | Type             | Description                                                                                          |
  | ----------------- | ---------------------------------------------------------------------------------------------- |
  | boolean           | Returns a Boolean value if the request is processed synchronously in **onRemoteMessageRequest**. If the operation is successful, **true** is returned. Otherwise, **false** is returned.|
  | Promise\<boolean> | Returns a promise object if the request is processed asynchronously in **onRemoteMessageRequest**.                                |
A
Annie_wang 已提交
7850

A
Annie_wang 已提交
7851
**Example**: Overload **onRemoteMessageRequest** to process requests synchronously.
A
Annie_wang 已提交
7852 7853 7854 7855 7856 7857

  ```ets
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7858 7859

      onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7860
          if (code === 1) {
A
Annie_wang 已提交
7861
              console.log("RpcServer: sync onRemoteMessageRequest is called");
A
Annie_wang 已提交
7862 7863 7864 7865 7866 7867 7868 7869
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
  }
  ```
A
Annie_wang 已提交
7870 7871

  **Example**: Overload **onRemoteMessageRequest** to process requests asynchronously.
Z
zengyawen 已提交
7872

A
Annie_wang 已提交
7873 7874 7875 7876 7877
  ```ets
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7878 7879

      async onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7880
          if (code === 1) {
A
Annie_wang 已提交
7881
              console.log("RpcServer: async onRemoteMessageRequest is called");
A
Annie_wang 已提交
7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
          await new Promise((resolve) => {
            setTimeout(resolve, 100);
          })
          return true;
      }
  }
  ```
A
Annie_wang 已提交
7893 7894

**Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests synchronously.
Z
zengyawen 已提交
7895

A
Annie_wang 已提交
7896 7897 7898 7899 7900
  ```ets
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7901

A
Annie_wang 已提交
7902 7903
      onRemoteRequest(code, data, reply, option) {
          if (code === 1) {
A
Annie_wang 已提交
7904
              console.log("RpcServer: sync onRemoteMessageRequest is called");
A
Annie_wang 已提交
7905 7906 7907 7908 7909 7910
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
A
Annie_wang 已提交
7911 7912
      // Only onRemoteMessageRequest is executed.
      onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7913
          if (code === 1) {
A
Annie_wang 已提交
7914
              console.log("RpcServer: async onRemoteMessageRequest is called");
A
Annie_wang 已提交
7915 7916 7917 7918
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
A
Annie_wang 已提交
7919
         
A
Annie_wang 已提交
7920 7921 7922 7923
          return true;
      }
  }
  ```
A
Annie_wang 已提交
7924 7925

  **Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests asynchronously.
A
Annie_wang 已提交
7926 7927 7928 7929 7930 7931

  ```ets
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7932

A
Annie_wang 已提交
7933 7934
      onRemoteRequest(code, data, reply, option) {
          if (code === 1) {
A
Annie_wang 已提交
7935
              console.log("RpcServer: sync onRemoteRequest is called");
A
Annie_wang 已提交
7936 7937 7938 7939 7940 7941
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
A
Annie_wang 已提交
7942 7943
      // Only onRemoteMessageRequest is executed.
      async onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7944
          if (code === 1) {
A
Annie_wang 已提交
7945
              console.log("RpcServer: async onRemoteMessageRequest is called");
A
Annie_wang 已提交
7946 7947 7948 7949
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
A
Annie_wang 已提交
7950
         await new Promise((resolve) => {
A
Annie_wang 已提交
7951 7952 7953 7954 7955 7956
            setTimeout(resolve, 100);
          })
          return true;
      }
  }
  ```
A
Annie_wang 已提交
7957 7958


Z
zengyawen 已提交
7959 7960 7961 7962
### getCallingUid

getCallingUid(): number

A
annie_wangli 已提交
7963
Obtains the UID of the remote process.
Z
zengyawen 已提交
7964

A
annie_wangli 已提交
7965 7966
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7967
**Return value**
A
Annie_wang 已提交
7968 7969
  | Type  | Description                   |
  | ------ | ----------------------- |
A
annie_wangli 已提交
7970
  | number | UID of the remote process obtained.|
Z
zengyawen 已提交
7971

A
Annie_wang 已提交
7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079
**Example**

  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  console.log("RpcServer: getCallingUid: " + testRemoteObject.getCallingUid());
  ```

### getCallingPid

getCallingPid(): number

Obtains the PID of the remote process.

**System capability**: SystemCapability.Communication.IPC.Core

**Return value**

  | Type  | Description                   |
  | ------ | ----------------------- |
  | number | PID of the remote process obtained.|

**Example**

  ```
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  console.log("RpcServer: getCallingPid: " + testRemoteObject.getCallingPid());
  ```

### getLocalInterface<sup>9+</sup>

getLocalInterface(descriptor: string): IRemoteBroker

Obtains the interface.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name    | Type  | Mandatory| Description                |
  | ---------- | ------ | ---- | -------------------- |
  | descriptor | string | Yes  | Interface descriptor.|

**Return value**

  | Type         | Description                                         |
  | ------------- | --------------------------------------------- |
  | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|


**Example**

  ```
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
      registerDeathRecipient(recipient: MyDeathRecipient, flags: number);
      unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number);
      isObjectDead(): boolean {
          return false;
      }
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  try {
      let broker = testRemoteObject.getLocalInterface("testObject");
  } catch(error) {
      console.info(rpc get local interface fail, errorCode " + error.code);
      console.info(rpc get local interface fail, errorMessage " + error.message);
  }
  ```


### queryLocalInterface<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).

queryLocalInterface(descriptor: string): IRemoteBroker

Checks whether the remote object corresponding to the specified interface token exists.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name    | Type  | Mandatory| Description                  |
  | ---------- | ------ | ---- | ---------------------- |
  | descriptor | string | Yes  | Interface descriptor.|

**Return value**

  | Type         | Description                                                              |
  | ------------- | ------------------------------------------------------------------ |
  | IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.|
Z
zengyawen 已提交
8080

A
Annie_wang 已提交
8081
**Example**
A
annie_wangli 已提交
8082

Z
zengyawen 已提交
8083
  ```
A
Annie_wang 已提交
8084 8085 8086 8087 8088
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8089 8090 8091 8092
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
8093 8094 8095 8096 8097 8098 8099 8100 8101
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
8102 8103
  }
  let testRemoteObject = new TestRemoteObject("testObject");
A
Annie_wang 已提交
8104
  let broker = testRemoteObject.queryLocalInterface("testObject");
Z
zengyawen 已提交
8105 8106 8107
  ```


A
Annie_wang 已提交
8108
### getDescriptor<sup>9+</sup>
Z
zengyawen 已提交
8109

A
Annie_wang 已提交
8110
getDescriptor(): string
Z
zengyawen 已提交
8111

A
Annie_wang 已提交
8112
Obtains the interface descriptor of this object. The interface descriptor is a string.
Z
zengyawen 已提交
8113

A
annie_wangli 已提交
8114 8115
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8116
**Return value**
A
Annie_wang 已提交
8117

A
Annie_wang 已提交
8118 8119 8120 8121 8122
  | Type  | Description            |
  | ------ | ---------------- |
  | string | Interface descriptor obtained.|

**Error Code**
Z
zengyawen 已提交
8123

A
Annie_wang 已提交
8124 8125 8126 8127 8128
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900008 | proxy or remote object is invalid |
Z
zengyawen 已提交
8129

A
Annie_wang 已提交
8130
**Example**
A
annie_wangli 已提交
8131

Z
zengyawen 已提交
8132
  ```
A
Annie_wang 已提交
8133 8134 8135 8136 8137
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8138 8139 8140 8141
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
8142 8143
      addDeathRecipient(recipient: MyDeathRecipient, flags: number);
      unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number);
A
Annie_wang 已提交
8144 8145 8146
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
8147 8148
  }
  let testRemoteObject = new TestRemoteObject("testObject");
A
Annie_wang 已提交
8149 8150 8151 8152 8153 8154 8155
  try {
      let descriptor = testRemoteObject.getDescriptor();
  } catch(error) {
      console.info(rpc get local interface fail, errorCode " + error.code);
      console.info(rpc get local interface fail, errorMessage " + error.message);
  }
  console.log("RpcServer: descriptor is: " + descriptor);
Z
zengyawen 已提交
8156 8157 8158
  ```


A
Annie_wang 已提交
8159
### getInterfaceDescriptor<sup>(deprecated)</sup>
Z
zengyawen 已提交
8160

A
Annie_wang 已提交
8161
>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
Z
zengyawen 已提交
8162

A
Annie_wang 已提交
8163
getInterfaceDescriptor(): string
A
annie_wangli 已提交
8164

A
Annie_wang 已提交
8165
Obtains the interface descriptor.
A
Annie_wang 已提交
8166

A
Annie_wang 已提交
8167
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8168

A
Annie_wang 已提交
8169
**Return value**
A
Annie_wang 已提交
8170

A
Annie_wang 已提交
8171 8172 8173
  | Type  | Description            |
  | ------ | ---------------- |
  | string | Interface descriptor obtained.|
Z
zengyawen 已提交
8174

A
Annie_wang 已提交
8175
**Example**
A
annie_wangli 已提交
8176

Z
zengyawen 已提交
8177
  ```
A
Annie_wang 已提交
8178 8179 8180 8181 8182
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8183 8184 8185 8186
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
8187 8188 8189 8190 8191 8192 8193 8194 8195
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
8196 8197
  }
  let testRemoteObject = new TestRemoteObject("testObject");
A
Annie_wang 已提交
8198 8199
  let descriptor = testRemoteObject.getInterfaceDescriptor();
  console.log("RpcServer: descriptor is: " + descriptor);
Z
zengyawen 已提交
8200 8201 8202
  ```


A
Annie_wang 已提交
8203
### modifyLocalInterface<sup>9+</sup>
Z
zengyawen 已提交
8204

A
Annie_wang 已提交
8205
modifyLocalInterface(localInterface: IRemoteBroker, descriptor: string): void
Z
zengyawen 已提交
8206

A
Annie_wang 已提交
8207
Binds an interface descriptor to an **IRemoteBroker** object.
Z
zengyawen 已提交
8208

A
annie_wangli 已提交
8209 8210
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8211
**Parameters**
A
Annie_wang 已提交
8212

A
Annie_wang 已提交
8213 8214 8215 8216
  | Name        | Type         | Mandatory| Description                                 |
  | -------------- | ------------- | ---- | ------------------------------------- |
  | localInterface | IRemoteBroker | Yes  | **IRemoteBroker** object.  |
  | descriptor     | string        | Yes  | Interface descriptor.|
Z
zengyawen 已提交
8217 8218


A
Annie_wang 已提交
8219
**Example**
A
annie_wangli 已提交
8220

Z
zengyawen 已提交
8221
  ```
A
Annie_wang 已提交
8222 8223 8224 8225 8226
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8227 8228 8229
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
A
Annie_wang 已提交
8230 8231 8232 8233 8234 8235
          try {
              this.modifyLocalInterface(this, descriptor);
          } catch(error) {
              console.info(rpc attach local interface fail, errorCode " + error.code);
              console.info(rpc attach local interface fail, errorMessage " + error.message);
          }
Z
zengyawen 已提交
8236
      }
A
Annie_wang 已提交
8237 8238
      registerDeathRecipient(recipient: MyDeathRecipient, flags: number);
      unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number);
A
Annie_wang 已提交
8239 8240 8241
      isObjectDead(): boolean {
          return false;
      }
A
Annie_wang 已提交
8242 8243 8244
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
8245 8246 8247 8248
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  ```

A
Annie_wang 已提交
8249
### attachLocalInterface<sup>(deprecated)</sup>
Z
zengyawen 已提交
8250

A
Annie_wang 已提交
8251
>This API is no longer maintained since API version 9. You are advised to use [modifyLocalInterface](#modifylocalinterface9).
Z
zengyawen 已提交
8252 8253 8254 8255 8256

attachLocalInterface(localInterface: IRemoteBroker, descriptor: string): void

Binds an interface descriptor to an **IRemoteBroker** object.

A
annie_wangli 已提交
8257 8258
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8259
**Parameters**
A
Annie_wang 已提交
8260

A
Annie_wang 已提交
8261 8262 8263 8264
  | Name        | Type         | Mandatory| Description                                 |
  | -------------- | ------------- | ---- | ------------------------------------- |
  | localInterface | IRemoteBroker | Yes  | **IRemoteBroker** object.  |
  | descriptor     | string        | Yes  | Interface descriptor.|
Z
zengyawen 已提交
8265

A
Annie_wang 已提交
8266
**Example**
A
annie_wangli 已提交
8267

Z
zengyawen 已提交
8268
  ```
A
Annie_wang 已提交
8269 8270 8271 8272 8273
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8274 8275 8276 8277 8278
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
          this.attachLocalInterface(this, descriptor);
      }
A
Annie_wang 已提交
8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
8291 8292 8293 8294 8295 8296 8297 8298 8299
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  ```


## Ashmem<sup>8+</sup>

Provides 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.

A
annie_wangli 已提交
8300 8301 8302
The table below describes the protection types of the mapped memory.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8303

A
Annie_wang 已提交
8304 8305 8306 8307 8308 8309
  | Name      | Value | Description              |
  | ---------- | --- | ------------------ |
  | PROT_EXEC  | 4   | The mapped memory is executable.  |
  | PROT_NONE  | 0   | The mapped memory is inaccessible.|
  | PROT_READ  | 1   | The mapped memory is readable.    |
  | PROT_WRITE | 2   | The mapped memory is writeable.    |
Z
zengyawen 已提交
8310 8311


A
Annie_wang 已提交
8312
### create<sup>9+</sup>
Z
zengyawen 已提交
8313

A
Annie_wang 已提交
8314
static create(name: string, size: number): Ashmem
Z
zengyawen 已提交
8315 8316 8317

Creates an **Ashmem** object with the specified name and size.

A
annie_wangli 已提交
8318 8319
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8320
**Parameters**
A
Annie_wang 已提交
8321

A
Annie_wang 已提交
8322 8323 8324 8325
  | Name| Type  | Mandatory| Description                        |
  | ------ | ------ | ---- | ---------------------------- |
  | name   | string | Yes  | Name of the **Ashmem** object to create.  |
  | size   | number | Yes  | Size (in bytes) of the **Ashmem** object to create.|
Z
zengyawen 已提交
8326

A
Annie_wang 已提交
8327
**Return value**
A
Annie_wang 已提交
8328

A
Annie_wang 已提交
8329 8330
  | Type  | Description                                          |
  | ------ | ---------------------------------------------- |
A
annie_wangli 已提交
8331
  | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
Z
zengyawen 已提交
8332 8333


A
Annie_wang 已提交
8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371
**Example**

  ```
  let ashmem;
  try {
      ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
  } catch(error) {
      console.info("Rpc creat ashmem fail, errorCode " + error.code);
      console.info("Rpc creat ashmem  fail, errorMessage " + error.message);
  }
  let size = ashmem.getAshmemSize();
  console.log("RpcTest: get ashemm by create : " + ashmem + " size is : " + size);
  ```


### createAshmem<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [create](#create9).

static createAshmem(name: string, size: number): Ashmem

Creates an **Ashmem** object with the specified name and size.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                        |
  | ------ | ------ | ---- | ---------------------------- |
  | name   | string | Yes  | Name of the **Ashmem** object to create.  |
  | size   | number | Yes  | Size (in bytes) of the **Ashmem** object to create.|

**Return value**

  | Type  | Description                                          |
  | ------ | ---------------------------------------------- |
  | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|

A
Annie_wang 已提交
8372
**Example**
A
annie_wangli 已提交
8373

Z
zengyawen 已提交
8374 8375 8376 8377 8378 8379 8380
  ```
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
  let size = ashmem.getAshmemSize();
  console.log("RpcTest: get ashemm by createAshmem : " + ashmem + " size is : " + size);
  ```


A
Annie_wang 已提交
8381
### create<sup>9+</sup>
Z
zengyawen 已提交
8382

A
Annie_wang 已提交
8383
static create(ashmem: Ashmem): Ashmem
Z
zengyawen 已提交
8384

A
annie_wangli 已提交
8385 8386 8387
Creates an **Ashmem** object by copying the file descriptor (FD) of an existing Ashmem object. The two **Ashmem** objects point to the same shared memory region.

**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8388

A
Annie_wang 已提交
8389
**Parameters**
A
Annie_wang 已提交
8390

A
Annie_wang 已提交
8391 8392 8393
  | Name| Type  | Mandatory| Description                |
  | ------ | ------ | ---- | -------------------- |
  | ashmem | Ashmem | Yes  | Existing **Ashmem** object.|
Z
zengyawen 已提交
8394

A
Annie_wang 已提交
8395
**Return value**
A
Annie_wang 已提交
8396

A
Annie_wang 已提交
8397 8398
  | Type  | Description                  |
  | ------ | ---------------------- |
A
annie_wangli 已提交
8399
  | Ashmem | **Ashmem** object created.|
Z
zengyawen 已提交
8400 8401


A
Annie_wang 已提交
8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439
**Example**

  ```
  let ashmem2;
  try {
      let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
      let ashmem2 = rpc.Ashmem.create(ashmem);
  } catch(error) {
      console.info("Rpc creat ashmem from existing fail, errorCode " + error.code);
      console.info("Rpc creat ashmem from existing  fail, errorMessage " + error.message);
  }
  let size = ashmem2.getAshmemSize();
  console.log("RpcTest: get ashemm by create : " + ashmem2 + " size is : " + size);
  ```


### createAshmemFromExisting<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [create](#create9).

static createAshmemFromExisting(ashmem: Ashmem): Ashmem

Creates an **Ashmem** object by copying the file descriptor (FD) of an existing Ashmem object. The two **Ashmem** objects point to the same shared memory region.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                |
  | ------ | ------ | ---- | -------------------- |
  | ashmem | Ashmem | Yes  | Existing **Ashmem** object.|

**Return value**

  | Type  | Description                  |
  | ------ | ---------------------- |
  | Ashmem | **Ashmem** object created.|

A
Annie_wang 已提交
8440
**Example**
A
annie_wangli 已提交
8441

Z
zengyawen 已提交
8442 8443 8444 8445 8446 8447 8448 8449
  ```
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
  let ashmem2 = rpc.Ashmem.createAshmemFromExisting(ashmem);
  let size = ashmem2.getAshmemSize();
  console.log("RpcTest: get ashemm by createAshmemFromExisting : " + ashmem2 + " size is : " + size);
  ```


A
annie_wangli 已提交
8450
### closeAshmem<sup>8+</sup>
Z
zengyawen 已提交
8451 8452 8453 8454 8455

closeAshmem(): void

Closes this **Ashmem** object.

A
annie_wangli 已提交
8456
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8457

A
Annie_wang 已提交
8458
**Example**
A
annie_wangli 已提交
8459

Z
zengyawen 已提交
8460
  ```
A
Annie_wang 已提交
8461
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
Z
zengyawen 已提交
8462 8463 8464 8465
  ashmem.closeAshmem();
  ```


A
annie_wangli 已提交
8466
### unmapAshmem<sup>8+</sup>
Z
zengyawen 已提交
8467 8468 8469 8470 8471

unmapAshmem(): void

Deletes the mappings for the specified address range of this **Ashmem** object.

A
annie_wangli 已提交
8472
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8473

A
Annie_wang 已提交
8474
**Example**
A
annie_wangli 已提交
8475

Z
zengyawen 已提交
8476
  ```
A
Annie_wang 已提交
8477
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
Z
zengyawen 已提交
8478 8479 8480 8481
  ashmem.unmapAshmem();
  ```


A
annie_wangli 已提交
8482
### getAshmemSize<sup>8+</sup>
Z
zengyawen 已提交
8483 8484 8485 8486 8487

getAshmemSize(): number

Obtains the memory size of this **Ashmem** object.

A
annie_wangli 已提交
8488
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8489

A
Annie_wang 已提交
8490
**Return value**
A
Annie_wang 已提交
8491

A
Annie_wang 已提交
8492 8493
  | Type  | Description                      |
  | ------ | -------------------------- |
A
annie_wangli 已提交
8494
  | number | **Ashmem** size obtained.|
Z
zengyawen 已提交
8495

A
Annie_wang 已提交
8496
**Example**
A
annie_wangli 已提交
8497

Z
zengyawen 已提交
8498 8499 8500 8501 8502 8503 8504
  ```
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
  let size = ashmem.getAshmemSize();
  console.log("RpcTest: get ashmem is " + ashmem + " size is : " + size);
  ```


A
Annie_wang 已提交
8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542
### mapTypedAshmem<sup>9+</sup>

mapTypedAshmem(mapType: number): void

Creates the shared file mapping on the virtual address space of this process. The size of the mapping region is specified by this **Ashmem** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name | Type  | Mandatory| Description                          |
  | ------- | ------ | ---- | ------------------------------ |
  | mapType | number | Yes  | Protection level of the memory region to which the shared file is mapped.|

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | ------ |
  | 1900001     | call mmap function failed |

**Example**

  ```
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
  try {
      ashmem.mapTypedAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
  } catch(error) {
      console.info("Rpc map ashmem fail, errorCode " + error.code);
      console.info("Rpc map ashmem fail, errorMessage " + error.message);
  }
  ```


### mapAshmem<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [mapTypedAshmem](#maptypedashmem9).
Z
zengyawen 已提交
8543 8544 8545 8546 8547

mapAshmem(mapType: number): boolean

Creates the shared file mapping on the virtual address space of this process. The size of the mapping region is specified by this **Ashmem** object.

A
annie_wangli 已提交
8548
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8549

A
Annie_wang 已提交
8550
**Parameters**
A
Annie_wang 已提交
8551

A
Annie_wang 已提交
8552 8553 8554
  | Name | Type  | Mandatory| Description                          |
  | ------- | ------ | ---- | ------------------------------ |
  | mapType | number | Yes  | Protection level of the memory region to which the shared file is mapped.|
Z
zengyawen 已提交
8555

A
Annie_wang 已提交
8556
**Return value**
A
Annie_wang 已提交
8557

A
Annie_wang 已提交
8558 8559
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
8560
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
8561

A
Annie_wang 已提交
8562
**Example**
A
annie_wangli 已提交
8563

Z
zengyawen 已提交
8564 8565
  ```
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
A
Annie_wang 已提交
8566
  let mapReadAndWrite = ashmem.mapAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
Z
zengyawen 已提交
8567 8568 8569 8570
  console.log("RpcTest: map ashmem result is  : " + mapReadAndWrite);
  ```


A
Annie_wang 已提交
8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602
### mapReadWriteAshmem<sup>9+</sup>

mapReadWriteAshmem(): void

Maps the shared file to the readable and writable virtual address space of the process.

**System capability**: SystemCapability.Communication.IPC.Core

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900001 | call mmap function failed |

**Example**

  ```
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
  try {
      ashmem.mapReadWriteAshmem();
  } catch(error) {
      console.info("Rpc map read and write ashmem fail, errorCode " + error.code);
      console.info("Rpc map read and write ashmem fail, errorMessage " + error.message);
  }
  ```


### mapReadAndWriteAshmem<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [mapReadWriteAshmem](#mapreadwriteashmem9).
Z
zengyawen 已提交
8603 8604 8605 8606 8607

mapReadAndWriteAshmem(): boolean

Maps the shared file to the readable and writable virtual address space of the process.

A
annie_wangli 已提交
8608
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8609

A
Annie_wang 已提交
8610
**Return value**
A
Annie_wang 已提交
8611

A
Annie_wang 已提交
8612 8613
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
8614
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
8615

A
Annie_wang 已提交
8616
**Example**
A
annie_wangli 已提交
8617

Z
zengyawen 已提交
8618 8619 8620 8621 8622 8623 8624
  ```
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
  let mapResult = ashmem.mapReadAndWriteAshmem();
  console.log("RpcTest: map ashmem result is  : " + mapResult);
  ```


A
Annie_wang 已提交
8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656
### mapReadonlyAshmem<sup>9+</sup>

mapReadonlyAshmem(): void

Maps the shared file to the read-only virtual address space of the process.

**System capability**: SystemCapability.Communication.IPC.Core

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900001 | call mmap function failed |

**Example**

  ```
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
  try {
      ashmem.mapReadonlyAshmem();
  } catch(error) {
      console.info("Rpc map read and write ashmem fail, errorCode " + error.code);
      console.info("Rpc map read and write ashmem fail, errorMessage " + error.message);
  }
  ```


### mapReadOnlyAshmem<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [mapReadonlyAshmem](#mapreadonlyashmem9).
Z
zengyawen 已提交
8657 8658 8659 8660 8661

mapReadOnlyAshmem(): boolean

Maps the shared file to the read-only virtual address space of the process.

A
annie_wangli 已提交
8662
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8663

A
Annie_wang 已提交
8664
**Return value**
A
Annie_wang 已提交
8665

A
Annie_wang 已提交
8666 8667
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
8668
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
8669

A
Annie_wang 已提交
8670
**Example**
A
annie_wangli 已提交
8671

Z
zengyawen 已提交
8672 8673 8674 8675 8676 8677 8678
  ```
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
  let mapResult = ashmem.mapReadOnlyAshmem();
  console.log("RpcTest: Ashmem mapReadOnlyAshmem result is : " + mapResult);
  ```


A
Annie_wang 已提交
8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716
### setProtectionType<sup>9+</sup>

setProtectionType(protectionType: number): void

Sets the protection level of the memory region to which the shared file is mapped.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name        | Type  | Mandatory| Description              |
  | -------------- | ------ | ---- | ------------------ |
  | protectionType | number | Yes  | Protection type to set.|

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | -------- | ------- |
  | 1900002 | call os ioctl function failed |

**Example**

  ```
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
  try {
      ashmem.setProtection(ashmem.PROT_READ);
  } catch(error) {
      console.info("Rpc set protection type fail, errorCode " + error.code);
      console.info("Rpc set protection type fail, errorMessage " + error.message);
  }
  ```


### setProtection<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [setProtectionType](#setprotectiontype9).
Z
zengyawen 已提交
8717 8718 8719 8720 8721

setProtection(protectionType: number): boolean

Sets the protection level of the memory region to which the shared file is mapped.

A
annie_wangli 已提交
8722
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8723

A
Annie_wang 已提交
8724
**Parameters**
A
Annie_wang 已提交
8725

A
Annie_wang 已提交
8726 8727 8728
  | Name        | Type  | Mandatory| Description              |
  | -------------- | ------ | ---- | ------------------ |
  | protectionType | number | Yes  | Protection type to set.|
Z
zengyawen 已提交
8729

A
Annie_wang 已提交
8730
**Return value**
A
Annie_wang 已提交
8731

A
Annie_wang 已提交
8732 8733
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
8734
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
8735

A
Annie_wang 已提交
8736
**Example**
A
annie_wangli 已提交
8737

Z
zengyawen 已提交
8738 8739
  ```
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
A
Annie_wang 已提交
8740
  let result = ashmem.setProtection(ashmem.PROT_READ);
Z
zengyawen 已提交
8741 8742 8743 8744
  console.log("RpcTest: Ashmem setProtection result is : " + result);
  ```


A
Annie_wang 已提交
8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786
### writeAshmem<sup>9+</sup>

writeAshmem(buf: number[], size: number, offset: number): void

Writes data to the shared file associated with this **Ashmem** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type    | Mandatory| Description                                              |
  | ------ | -------- | ---- | -------------------------------------------------- |
  | buf    | number[] | Yes  | Data to write.                            |
  | size   | number   | Yes  | Size of the data to write.                                |
  | offset | number   | Yes  | Start position of the data to write in the memory region associated with this **Ashmem** object.|

**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID| Error Message|
  | ------- | -------- |
  | 1900003 | write to ashmem failed |

**Example**

  ```
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
  ashmem.mapReadWriteAshmem();
  var ByteArrayVar = [1, 2, 3, 4, 5];
  try {
      ashmem.writeAshmem(ByteArrayVar, 5, 0);
  } catch(error) {
      console.info("Rpc write to ashmem fail, errorCode " + error.code);
      console.info("Rpc write to ashmem fail, errorMessage " + error.message);
  }
  ```


### writeToAshmem<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [writeAshmem](#writeashmem9).
Z
zengyawen 已提交
8787 8788 8789 8790 8791

writeToAshmem(buf: number[], size: number, offset: number): boolean

Writes data to the shared file associated with this **Ashmem** object.

A
annie_wangli 已提交
8792
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8793

A
Annie_wang 已提交
8794
**Parameters**
A
Annie_wang 已提交
8795

A
Annie_wang 已提交
8796 8797 8798 8799 8800
  | Name| Type    | Mandatory| Description                                              |
  | ------ | -------- | ---- | -------------------------------------------------- |
  | buf    | number[] | Yes  | Data to write.                            |
  | size   | number   | Yes  | Size of the data to write.                                |
  | offset | number   | Yes  | Start position of the data to write in the memory region associated with this **Ashmem** object.|
Z
zengyawen 已提交
8801

A
Annie_wang 已提交
8802
**Return value**
A
Annie_wang 已提交
8803

A
Annie_wang 已提交
8804 8805
  | Type   | Description                                                                                     |
  | ------- | ----------------------------------------------------------------------------------------- |
A
annie_wangli 已提交
8806
  | boolean | Returns **true** is the data is written successfully; returns **false** otherwise.|
Z
zengyawen 已提交
8807

A
Annie_wang 已提交
8808
**Example**
A
annie_wangli 已提交
8809

Z
zengyawen 已提交
8810 8811
  ```
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
A
Annie_wang 已提交
8812 8813 8814
  let mapResult = ashmem.mapReadAndWriteAshmem();
  console.info("RpcTest map ashmem result is " + mapResult);
  var ByteArrayVar = [1, 2, 3, 4, 5];
Z
zengyawen 已提交
8815 8816 8817 8818 8819
  let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
  console.log("RpcTest: write to Ashmem result is  : " + writeResult);
  ```


A
Annie_wang 已提交
8820
### readAshmem<sup>9+</sup>
Z
zengyawen 已提交
8821

A
Annie_wang 已提交
8822
readAshmem(size: number, offset: number): number[]
Z
zengyawen 已提交
8823 8824 8825

Reads data from the shared file associated with this **Ashmem** object.

A
annie_wangli 已提交
8826 8827
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8828
**Parameters**
A
Annie_wang 已提交
8829

A
Annie_wang 已提交
8830 8831 8832 8833
  | Name| Type  | Mandatory| Description                                              |
  | ------ | ------ | ---- | -------------------------------------------------- |
  | size   | number | Yes  | Size of the data to read.                              |
  | offset | number | Yes  | Start position of the data to read in the memory region associated with this **Ashmem** object.|
Z
zengyawen 已提交
8834

A
Annie_wang 已提交
8835
**Return value**
A
Annie_wang 已提交
8836

A
Annie_wang 已提交
8837 8838
  | Type    | Description            |
  | -------- | ---------------- |
A
annie_wangli 已提交
8839
  | number[] | Data read.|
Z
zengyawen 已提交
8840

A
Annie_wang 已提交
8841 8842 8843 8844 8845 8846 8847
**Error Code**

For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).

  | ID | Error Message|
  | -------- | -------- |
  | 1900004 | read from ashmem failed |
Z
zengyawen 已提交
8848

A
Annie_wang 已提交
8849
**Example**
A
annie_wangli 已提交
8850

Z
zengyawen 已提交
8851
  ```
A
Annie_wang 已提交
8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
  ashmem.mapReadWriteAshmem();
  var ByteArrayVar = [1, 2, 3, 4, 5];
  ashmem.writeAshmem(ByteArrayVar, 5, 0);
  try {
      let readResult = ashmem.readAshmem(5, 0);
      console.log("RpcTest: read from Ashmem result is  : " + readResult);
  } catch(error) {
      console.info("Rpc read from ashmem fail, errorCode " + error.code);
      console.info("Rpc read from ashmem fail, errorMessage " + error.message);
  }
  ```


### readFromAshmem<sup>8+(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [readAshmem](#readashmem9).

readFromAshmem(size: number, offset: number): number[]

Reads data from the shared file associated with this **Ashmem** object.

**System capability**: SystemCapability.Communication.IPC.Core

**Parameters**

  | Name| Type  | Mandatory| Description                                              |
  | ------ | ------ | ---- | -------------------------------------------------- |
  | size   | number | Yes  | Size of the data to read.                              |
  | offset | number | Yes  | Start position of the data to read in the memory region associated with this **Ashmem** object.|

**Return value**

  | Type    | Description            |
  | -------- | ---------------- |
  | number[] | Data read.|

**Example**

 ```
Z
zengyawen 已提交
8892
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
A
Annie_wang 已提交
8893 8894 8895
  let mapResult = ashmem.mapReadAndWriteAshmem();
  console.info("RpcTest map ashmem result is " + mapResult);
  var ByteArrayVar = [1, 2, 3, 4, 5];
Z
zengyawen 已提交
8896 8897 8898 8899 8900
  let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
  console.log("RpcTest: write to Ashmem result is  : " + writeResult);
  let readResult = ashmem.readFromAshmem(5, 0);
  console.log("RpcTest: read to Ashmem result is  : " + readResult);
  ```