js-apis-rpc.md 273.7 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.rpc (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 6
> **NOTE**
>
A
Annie_wang 已提交
7
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
A
Annie_wang 已提交
8
>
A
Annie_wang 已提交
9
> - This module supports return of error codes since API version 9.
Z
zengyawen 已提交
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
## 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.                       |
A
Annie_wang 已提交
27
  | OS_IOCTL_ERROR                        | 1900002 | Failed to call **ioctl** with the shared memory file descriptor.|
A
Annie_wang 已提交
28 29 30 31 32 33 34 35 36 37 38 39
  | 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 or IPC, the sender can use the **write()** method provided by **MessageSequence** to write data in specific format to a **MessageSequence** object. The receiver can use the **read()** method provided by **MessageSequence** to read data in specific format from a **MessageSequence** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.
Z
zengyawen 已提交
44 45 46

### create

A
Annie_wang 已提交
47
  static 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

A
Annie_wang 已提交
61
  ```ts
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

A
Annie_wang 已提交
76
  ```ts
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

A
Annie_wang 已提交
106
  ```ts
Z
zengyawen 已提交
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 the remote object from **MessageSequence**. You can use this API to deserialize the **MessageSequence** object to generate an **IRemoteObject**. The remote object is read in the order in which it is written to this **MessageSequence** object.
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

A
Annie_wang 已提交
147
  ```ts
Z
zengyawen 已提交
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

A
Annie_wang 已提交
188
  ```ts
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
**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 已提交
220
**Example**
A
annie_wangli 已提交
221

A
Annie_wang 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235
```ts
class Stub extends rpc.RemoteObject {
    onRemoteRequest(code, data, reply, option) {
        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);
        }
        return true;
    }
}
```
Z
zengyawen 已提交
236 237 238 239 240

### getSize

getSize(): number

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

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

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

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

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

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

### getCapacity

getCapacity(): number

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

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

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

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

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

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

### setSize

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

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

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

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

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

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

A
Annie_wang 已提交
297
  ```ts
A
Annie_wang 已提交
298 299 300 301 302 303 304 305
  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 已提交
306 307 308 309
  ```

### setCapacity

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

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

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

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

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

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

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

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

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

A
Annie_wang 已提交
332
  ```ts
A
Annie_wang 已提交
333 334 335 336 337 338 339 340
  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 已提交
341 342 343 344 345 346
  ```

### getWritableBytes

getWritableBytes(): number

A
Annie_wang 已提交
347
Obtains the writable capacity (in bytes) of this **MessageSequence** object.
Z
zengyawen 已提交
348

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

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

  | Type| Description|
A
Annie_wang 已提交
354
  | ------ | ------ |
A
Annie_wang 已提交
355
  | number | Writable capacity of the **MessageSequence** instance, in bytes.|
Z
zengyawen 已提交
356

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

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

### getReadableBytes

getReadableBytes(): number

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

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

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

  | Type| Description|
A
Annie_wang 已提交
380
  | ------ | ------- |
A
Annie_wang 已提交
381
  | number | Readable capacity of the **MessageSequence** instance, in bytes.|
Z
zengyawen 已提交
382

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

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

### getReadPosition

getReadPosition(): number

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

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

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

  | Type| Description|
A
Annie_wang 已提交
406
  | ------ | ------ |
A
Annie_wang 已提交
407
  | number | Read position obtained.|
Z
zengyawen 已提交
408

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

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

### getWritePosition

getWritePosition(): number

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

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

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

  | Type| Description|
A
Annie_wang 已提交
428
  | ------ | ----- |
A
Annie_wang 已提交
429
  | number | Write position obtained.|
Z
zengyawen 已提交
430

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

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

### rewindRead

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

Moves the read pointer to the specified position.

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

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

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

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

A
Annie_wang 已提交
456
  ```ts
A
Annie_wang 已提交
457
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
458
  data.writeInt(12);
A
Annie_wang 已提交
459
  data.writeString("sequence");
Z
zengyawen 已提交
460 461
  let number = data.readInt();
  console.log("RpcClient: number is " + number);
A
Annie_wang 已提交
462 463 464 465 466 467
  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 已提交
468 469 470 471 472 473
  let number2 = data.readInt();
  console.log("RpcClient: rewindRead is " + number2);
  ```

### rewindWrite

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

Moves the write pointer to the specified position.

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

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

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

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

A
Annie_wang 已提交
488
  ```ts
A
Annie_wang 已提交
489
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
490
  data.writeInt(4);
A
Annie_wang 已提交
491 492 493 494 495 496
  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 已提交
497 498 499 500 501 502 503
  data.writeInt(5);
  let number = data.readInt();
  console.log("RpcClient: rewindWrite is: " + number);
  ```

### writeByte

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

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

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

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

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

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

A
Annie_wang 已提交
518 519 520 521 522
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 已提交
523

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

A
Annie_wang 已提交
526
  ```ts
A
Annie_wang 已提交
527 528 529 530 531 532 533
  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 已提交
534 535 536 537 538 539
  ```

### readByte

readByte(): number

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

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

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

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

A
Annie_wang 已提交
550 551 552 553 554 555 556 557
**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 已提交
558
**Example**
A
annie_wangli 已提交
559

A
Annie_wang 已提交
560
  ```ts
A
Annie_wang 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573 574
  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 已提交
575 576 577 578
  ```

### writeShort

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

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

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

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

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

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

A
Annie_wang 已提交
593 594 595 596 597
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 已提交
598

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

A
Annie_wang 已提交
601
  ```ts
A
Annie_wang 已提交
602 603 604 605 606 607 608
  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 已提交
609 610 611 612 613 614
  ```

### readShort

readShort(): number

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

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

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

A
Annie_wang 已提交
621 622 623 624 625 626 627 628 629 630 631
  | 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 已提交
632

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

A
Annie_wang 已提交
635
  ```ts
A
Annie_wang 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649
  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 已提交
650 651 652 653
  ```

### writeInt

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

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

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

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

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

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

A
Annie_wang 已提交
668 669 670 671 672
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 已提交
673

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

A
Annie_wang 已提交
676
  ```ts
A
Annie_wang 已提交
677 678 679 680 681 682 683
  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 已提交
684 685 686 687 688 689
  ```

### readInt

readInt(): number

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

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

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

A
Annie_wang 已提交
696 697 698 699 700 701 702 703 704 705 706
  | 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 已提交
707

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

A
Annie_wang 已提交
710
  ```ts
A
Annie_wang 已提交
711 712 713 714 715 716 717 718 719 720 721 722 723 724
  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 已提交
725 726 727 728
  ```

### writeLong

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

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

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

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

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

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

A
Annie_wang 已提交
743 744 745 746 747
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 已提交
748

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

A
Annie_wang 已提交
751
  ```ts
A
Annie_wang 已提交
752 753 754 755 756 757 758
  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 已提交
759 760 761 762 763 764
  ```

### readLong

readLong(): number

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

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

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

A
Annie_wang 已提交
771 772 773 774 775 776 777 778 779 780 781
  | 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 已提交
782

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

A
Annie_wang 已提交
785
  ```ts
A
Annie_wang 已提交
786 787 788 789 790 791 792 793 794 795 796 797 798 799
  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 已提交
800 801 802 803
  ```

### writeFloat

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

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

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

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

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

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

A
Annie_wang 已提交
818 819 820 821 822
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 已提交
823

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

A
Annie_wang 已提交
826
  ```ts
A
Annie_wang 已提交
827 828 829 830 831 832 833
  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 已提交
834 835 836 837 838 839
  ```

### readFloat

readFloat(): number

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

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

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

A
Annie_wang 已提交
846 847 848 849 850 851 852 853 854 855 856
  | 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 已提交
857

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

A
Annie_wang 已提交
860
  ```ts
A
Annie_wang 已提交
861 862 863 864 865 866 867 868 869 870 871 872 873 874
  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 已提交
875 876 877 878
  ```

### writeDouble

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

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

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

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

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

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

A
Annie_wang 已提交
893 894 895 896 897
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 已提交
898

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

A
Annie_wang 已提交
901
  ```ts
A
Annie_wang 已提交
902 903 904 905 906 907 908
  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 已提交
909 910 911 912 913 914
  ```

### readDouble

readDouble(): number

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

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

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

A
Annie_wang 已提交
921 922 923 924 925 926 927 928 929 930 931
  | 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 已提交
932

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

A
Annie_wang 已提交
935
  ```ts
A
Annie_wang 已提交
936 937 938 939 940 941 942 943 944 945 946 947 948 949
  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 已提交
950 951 952 953
  ```

### writeBoolean

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

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

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

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

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

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

A
Annie_wang 已提交
968 969 970 971 972
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 已提交
973

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

A
Annie_wang 已提交
976
  ```ts
A
Annie_wang 已提交
977 978 979 980 981 982 983
  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 已提交
984 985 986 987 988 989
  ```

### readBoolean

readBoolean(): boolean

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

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

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

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

A
Annie_wang 已提交
1000 1001 1002 1003 1004 1005 1006 1007
**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 已提交
1008
**Example**
A
annie_wangli 已提交
1009

A
Annie_wang 已提交
1010
  ```ts
A
Annie_wang 已提交
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
  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 已提交
1025 1026 1027 1028
  ```

### writeChar

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

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

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

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

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

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

A
Annie_wang 已提交
1043 1044 1045 1046 1047
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 已提交
1048

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

A
Annie_wang 已提交
1051
  ```ts
A
Annie_wang 已提交
1052 1053 1054 1055 1056 1057 1058
  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 已提交
1059 1060 1061 1062 1063 1064
  ```

### readChar

readChar(): number

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

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

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

A
Annie_wang 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
  | 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 已提交
1082

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

A
Annie_wang 已提交
1085
  ```ts
A
Annie_wang 已提交
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
  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 已提交
1100 1101 1102 1103
  ```

### writeString

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

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

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

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

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

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

A
Annie_wang 已提交
1118 1119 1120 1121 1122
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 已提交
1123

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

A
Annie_wang 已提交
1126
  ```ts
A
Annie_wang 已提交
1127 1128 1129 1130 1131 1132 1133
  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 已提交
1134 1135 1136 1137 1138 1139
  ```

### readString

readString(): string

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

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

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

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

A
Annie_wang 已提交
1150 1151 1152 1153 1154 1155 1156 1157
**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 已提交
1158
**Example**
A
annie_wangli 已提交
1159

A
Annie_wang 已提交
1160
  ```ts
A
Annie_wang 已提交
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
  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 已提交
1175 1176
  ```

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

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

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

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

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

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

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

A
Annie_wang 已提交
1193 1194 1195 1196 1197
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 已提交
1198

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

A
Annie_wang 已提交
1201
  ```ts
Z
zengyawen 已提交
1202
  class MySequenceable {
A
Annie_wang 已提交
1203 1204 1205
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
1206
          this.num = num;
A
Annie_wang 已提交
1207
          this.str = str;
Z
zengyawen 已提交
1208
      }
A
Annie_wang 已提交
1209 1210 1211
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
Z
zengyawen 已提交
1212 1213
          return true;
      }
A
Annie_wang 已提交
1214 1215 1216
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
Z
zengyawen 已提交
1217 1218 1219
          return true;
      }
  }
A
Annie_wang 已提交
1220 1221 1222 1223 1224 1225 1226 1227
  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 已提交
1228 1229
  ```

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

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

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

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

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

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

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

A
Annie_wang 已提交
1246 1247 1248 1249 1250 1251
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 已提交
1252

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

A
Annie_wang 已提交
1255
  ```ts
Z
zengyawen 已提交
1256
  class MySequenceable {
A
Annie_wang 已提交
1257 1258 1259
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
1260
          this.num = num;
A
Annie_wang 已提交
1261
          this.str = str;
Z
zengyawen 已提交
1262
      }
A
Annie_wang 已提交
1263 1264 1265
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
Z
zengyawen 已提交
1266 1267
          return true;
      }
A
Annie_wang 已提交
1268 1269 1270
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
Z
zengyawen 已提交
1271 1272 1273
          return true;
      }
  }
A
Annie_wang 已提交
1274 1275 1276
  let parcelable = new MySequenceable(1, "aaa");
  let data = rpc.MessageSequence.create();
  data.writeParcelable(parcelable);
Z
zengyawen 已提交
1277
  let ret = new MySequenceable(0, "");
A
Annie_wang 已提交
1278 1279 1280 1281 1282 1283
  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 已提交
1284 1285 1286 1287
  ```

### writeByteArray

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

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

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

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

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

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

A
Annie_wang 已提交
1302 1303 1304 1305 1306
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 已提交
1307

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

A
Annie_wang 已提交
1310
  ```ts
A
Annie_wang 已提交
1311
  let data = rpc.MessageSequence.create();
A
Annie_wang 已提交
1312
  let ByteArrayVar = [1, 2, 3, 4, 5];
A
Annie_wang 已提交
1313 1314 1315 1316 1317 1318
  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 已提交
1319 1320 1321 1322
  ```

### readByteArray

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

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

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

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

A
Annie_wang 已提交
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
  | 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 已提交
1342

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

A
Annie_wang 已提交
1345
  ```ts
A
Annie_wang 已提交
1346
  let data = rpc.MessageSequence.create();
A
Annie_wang 已提交
1347
  let ByteArrayVar = [1, 2, 3, 4, 5];
A
Annie_wang 已提交
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
  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 已提交
1361 1362 1363 1364 1365 1366
  ```

### readByteArray

readByteArray(): number[]

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

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

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

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

A
Annie_wang 已提交
1377 1378 1379 1380 1381 1382 1383 1384
**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 已提交
1385
**Example**
A
annie_wangli 已提交
1386

A
Annie_wang 已提交
1387
  ```ts
A
Annie_wang 已提交
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
  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 已提交
1403 1404 1405 1406
  ```

### writeShortArray

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

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

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

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

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

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

A
Annie_wang 已提交
1421 1422 1423 1424 1425
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 已提交
1426

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

A
Annie_wang 已提交
1429
  ```ts
A
Annie_wang 已提交
1430 1431 1432 1433 1434 1435 1436
  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 已提交
1437 1438 1439 1440
  ```

### readShortArray

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

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

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

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

A
Annie_wang 已提交
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
  | 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 已提交
1460

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

A
Annie_wang 已提交
1463
  ```ts
A
Annie_wang 已提交
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477
  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 已提交
1478 1479 1480 1481 1482 1483
  ```

### readShortArray

readShortArray(): number[]

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

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

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

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

A
Annie_wang 已提交
1494 1495 1496 1497 1498 1499 1500 1501
**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 已提交
1502
**Example**
A
annie_wangli 已提交
1503

A
Annie_wang 已提交
1504
  ```ts
A
Annie_wang 已提交
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
  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 已提交
1519 1520 1521 1522
  ```

### writeIntArray

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

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

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

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

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

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

A
Annie_wang 已提交
1537 1538 1539 1540 1541
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 已提交
1542

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

A
Annie_wang 已提交
1545
  ```ts
A
Annie_wang 已提交
1546 1547 1548 1549 1550 1551 1552
  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 已提交
1553 1554 1555 1556
  ```

### readIntArray

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

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

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

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

A
Annie_wang 已提交
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575
  | 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 已提交
1576

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

A
Annie_wang 已提交
1579
  ```ts
A
Annie_wang 已提交
1580 1581 1582 1583 1584 1585 1586
  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 已提交
1587
  let array = new Array(3);
A
Annie_wang 已提交
1588 1589 1590 1591 1592 1593
  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 已提交
1594 1595 1596 1597 1598 1599
  ```

### readIntArray

readIntArray(): number[]

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

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

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

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

A
Annie_wang 已提交
1610 1611 1612 1613 1614 1615 1616 1617
**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 已提交
1618
**Example**
A
annie_wangli 已提交
1619

A
Annie_wang 已提交
1620
  ```ts
A
Annie_wang 已提交
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634
  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 已提交
1635 1636 1637 1638
  ```

### writeLongArray

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

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

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

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

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

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

A
Annie_wang 已提交
1653 1654 1655 1656 1657
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 已提交
1658

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

A
Annie_wang 已提交
1661
  ```ts
A
Annie_wang 已提交
1662 1663 1664 1665 1666 1667 1668
  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 已提交
1669 1670 1671 1672
  ```

### readLongArray

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

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

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

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

A
Annie_wang 已提交
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
  | 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 已提交
1692

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

A
Annie_wang 已提交
1695
  ```ts
A
Annie_wang 已提交
1696 1697 1698 1699 1700 1701 1702
  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 已提交
1703
  let array = new Array(3);
A
Annie_wang 已提交
1704 1705 1706 1707 1708 1709
  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 已提交
1710 1711 1712 1713 1714 1715
  ```

### readLongArray

readLongArray(): number[]

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

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

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

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

A
Annie_wang 已提交
1726 1727 1728 1729 1730 1731 1732 1733
**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 已提交
1734
**Example**
A
annie_wangli 已提交
1735

A
Annie_wang 已提交
1736
  ```ts
A
Annie_wang 已提交
1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
  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 已提交
1751 1752 1753 1754
  ```

### writeFloatArray

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

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

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

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

A
Annie_wang 已提交
1763 1764 1765
  | 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 已提交
1766

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

A
Annie_wang 已提交
1769 1770 1771 1772 1773
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 已提交
1774

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

A
Annie_wang 已提交
1777
  ```ts
A
Annie_wang 已提交
1778 1779 1780 1781 1782 1783 1784
  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 已提交
1785 1786 1787 1788
  ```

### readFloatArray

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

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

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

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

A
Annie_wang 已提交
1797 1798 1799 1800 1801 1802 1803
  | 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 已提交
1804

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

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

A
Annie_wang 已提交
1811
  ```ts
A
Annie_wang 已提交
1812 1813 1814 1815 1816 1817 1818
  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 已提交
1819
  let array = new Array(3);
A
Annie_wang 已提交
1820 1821 1822 1823 1824 1825
  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 已提交
1826 1827 1828 1829 1830 1831
  ```

### readFloatArray

readFloatArray(): number[]

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

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

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

A
Annie_wang 已提交
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848
  | 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 已提交
1849

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

A
Annie_wang 已提交
1852
  ```ts
A
Annie_wang 已提交
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
  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 已提交
1867 1868 1869 1870
  ```

### writeDoubleArray

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

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

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

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

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

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

A
Annie_wang 已提交
1885 1886 1887 1888 1889
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 已提交
1890

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

A
Annie_wang 已提交
1893
  ```ts
A
Annie_wang 已提交
1894 1895 1896 1897 1898 1899 1900
  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 已提交
1901 1902 1903 1904
  ```

### readDoubleArray

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

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

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

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

A
Annie_wang 已提交
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923
  | 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 已提交
1924

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

A
Annie_wang 已提交
1927
  ```ts
A
Annie_wang 已提交
1928 1929 1930 1931 1932 1933 1934
  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 已提交
1935
  let array = new Array(3);
A
Annie_wang 已提交
1936 1937 1938 1939 1940 1941
  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 已提交
1942 1943 1944 1945 1946 1947
  ```

### readDoubleArray

readDoubleArray(): number[]

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

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

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

A
Annie_wang 已提交
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964
  | 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 已提交
1965

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

A
Annie_wang 已提交
1968
  ```ts
A
Annie_wang 已提交
1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982
  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 已提交
1983 1984 1985 1986
  ```

### writeBooleanArray

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

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

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

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

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

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

A
Annie_wang 已提交
2001 2002 2003 2004 2005
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 已提交
2006

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

A
Annie_wang 已提交
2009
  ```ts
A
Annie_wang 已提交
2010 2011 2012 2013 2014 2015 2016
  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 已提交
2017 2018 2019 2020
  ```

### readBooleanArray

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

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

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

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

A
Annie_wang 已提交
2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039
  | 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 已提交
2040

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

A
Annie_wang 已提交
2043
  ```ts
A
Annie_wang 已提交
2044 2045 2046 2047 2048 2049 2050
  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 已提交
2051
  let array = new Array(3);
A
Annie_wang 已提交
2052 2053 2054 2055 2056 2057
  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 已提交
2058 2059 2060 2061 2062 2063
  ```

### readBooleanArray

readBooleanArray(): boolean[]

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

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

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

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

A
Annie_wang 已提交
2074 2075 2076 2077 2078 2079 2080 2081 2082
**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 已提交
2083

A
Annie_wang 已提交
2084
  ```ts
A
Annie_wang 已提交
2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098
  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 已提交
2099 2100 2101 2102
  ```

### writeCharArray

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

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

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

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

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

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

A
Annie_wang 已提交
2117 2118 2119 2120 2121
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 已提交
2122

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

A
Annie_wang 已提交
2125
  ```ts
A
Annie_wang 已提交
2126 2127 2128 2129 2130 2131 2132
  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 已提交
2133 2134 2135 2136
  ```

### readCharArray

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

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

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

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

A
Annie_wang 已提交
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155
  | 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 已提交
2156

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

A
Annie_wang 已提交
2159
  ```ts
A
Annie_wang 已提交
2160 2161 2162 2163 2164 2165 2166
  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 已提交
2167
  let array = new Array(3);
A
Annie_wang 已提交
2168 2169 2170 2171 2172 2173
  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 已提交
2174 2175 2176 2177
  ```

### readCharArray

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

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

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

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

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

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

A
Annie_wang 已提交
2192 2193 2194 2195 2196 2197 2198
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 已提交
2199

A
Annie_wang 已提交
2200
  ```ts
A
Annie_wang 已提交
2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216
  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 已提交
2217 2218 2219

### writeStringArray

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

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

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

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

A
Annie_wang 已提交
2228 2229 2230
  | 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 已提交
2231

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

A
Annie_wang 已提交
2234 2235 2236 2237 2238
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 已提交
2239

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

A
Annie_wang 已提交
2242
  ```ts
A
Annie_wang 已提交
2243 2244 2245 2246 2247 2248 2249
  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 已提交
2250 2251 2252 2253
  ```

### readStringArray

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

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

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

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

A
Annie_wang 已提交
2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272
  | 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 已提交
2273

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

A
Annie_wang 已提交
2276
  ```ts
A
Annie_wang 已提交
2277 2278 2279 2280 2281 2282 2283
  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 已提交
2284
  let array = new Array(2);
A
Annie_wang 已提交
2285 2286 2287 2288 2289 2290
  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 已提交
2291 2292 2293 2294 2295 2296
  ```

### readStringArray

readStringArray(): string[]

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

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

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

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

A
Annie_wang 已提交
2307 2308 2309 2310 2311 2312 2313 2314
**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 已提交
2315
**Example**
A
annie_wangli 已提交
2316

A
Annie_wang 已提交
2317
  ```ts
A
Annie_wang 已提交
2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331
  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 已提交
2332 2333
  ```

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

writeNoException(): void

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

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

A
Annie_wang 已提交
2342 2343 2344 2345 2346 2347 2348 2349
**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 已提交
2350
**Example**
A
annie_wangli 已提交
2351

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

Z
zengyawen 已提交
2358 2359 2360
      onRemoteRequest(code, data, reply, option) {
          if (code === 1) {
              console.log("RpcServer: onRemoteRequest called");
A
Annie_wang 已提交
2361 2362 2363 2364 2365 2366
              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 已提交
2367 2368 2369 2370 2371 2372 2373 2374 2375
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
  }
  ```

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

readException(): void

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

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

A
Annie_wang 已提交
2384 2385 2386 2387 2388 2389 2390 2391
**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 已提交
2392
**Example**
A
annie_wangli 已提交
2393

A
Annie_wang 已提交
2394
  ```ts
Z
zengyawen 已提交
2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
  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 已提交
2410
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
2411
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
2412 2413 2414
  };
  FA.connectAbility(want, connect);
  let option = new rpc.MessageOption();
A
Annie_wang 已提交
2415 2416
  let data = rpc.MessageSequence.create();
  let reply = rpc.MessageSequence.create();
Z
zengyawen 已提交
2417 2418
  data.writeInt(1);
  data.writeString("hello");
A
Annie_wang 已提交
2419
  proxy.sendMessageRequest(1, data, reply, option)
Z
zengyawen 已提交
2420 2421
      .then(function(errCode) {
          if (errCode === 0) {
A
Annie_wang 已提交
2422 2423 2424 2425 2426 2427 2428
              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 已提交
2429 2430 2431
              let msg = reply.readString();
              console.log("RPCTest: reply msg: " + msg);
          } else {
A
Annie_wang 已提交
2432
              console.log("RPCTest: sendMessageRequest failed, errCode: " + errCode);
Z
zengyawen 已提交
2433 2434
          }
      }).catch(function(e) {
A
Annie_wang 已提交
2435
          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
Z
zengyawen 已提交
2436
      }).finally (() => {
A
Annie_wang 已提交
2437
          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
Z
zengyawen 已提交
2438 2439 2440 2441 2442
          data.reclaim();
          reply.reclaim();
      });
  ```

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

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

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

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

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

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

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

A
Annie_wang 已提交
2459 2460 2461 2462 2463
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 已提交
2464

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

A
Annie_wang 已提交
2467
  ```ts
A
Annie_wang 已提交
2468
  class MyParcelable {
A
Annie_wang 已提交
2469 2470 2471
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
2472
          this.num = num;
A
Annie_wang 已提交
2473
          this.str = str;
Z
zengyawen 已提交
2474
      }
A
Annie_wang 已提交
2475 2476 2477
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
Z
zengyawen 已提交
2478 2479
          return true;
      }
A
Annie_wang 已提交
2480 2481 2482
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
Z
zengyawen 已提交
2483 2484 2485
          return true;
      }
  }
A
Annie_wang 已提交
2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496
  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 已提交
2497 2498
  ```

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

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

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

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

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

A
Annie_wang 已提交
2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520
  | 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 已提交
2521

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

A
Annie_wang 已提交
2524
  ```ts
A
Annie_wang 已提交
2525
  class MyParcelable {
A
Annie_wang 已提交
2526 2527 2528
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
2529
          this.num = num;
A
Annie_wang 已提交
2530
          this.str = str;
Z
zengyawen 已提交
2531
      }
A
Annie_wang 已提交
2532 2533 2534
      marshalling(messageSequence) {
          messageSequence.writeInt(this.num);
          messageSequence.writeString(this.str);
Z
zengyawen 已提交
2535 2536
          return true;
      }
A
Annie_wang 已提交
2537 2538 2539
      unmarshalling(messageSequence) {
          this.num = messageSequence.readInt();
          this.str = messageSequence.readString();
Z
zengyawen 已提交
2540 2541 2542
          return true;
      }
  }
A
Annie_wang 已提交
2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557
  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 已提交
2558 2559
  ```

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

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

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

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

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

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

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

A
Annie_wang 已提交
2576 2577 2578 2579 2580
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 已提交
2581

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

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

A
Annie_wang 已提交
2591 2592 2593
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
2594 2595
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
A
Annie_wang 已提交
2596
  let data = rpc.MessageSequence.create();
Z
zengyawen 已提交
2597
  let result = data.writeRemoteObjectArray(a);
A
Annie_wang 已提交
2598 2599 2600 2601 2602 2603
  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 已提交
2604 2605 2606
  console.log("RpcClient: writeRemoteObjectArray is " + result);
  ```

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

readRemoteObjectArray(objects: IRemoteObject[]): void

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

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

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

A
Annie_wang 已提交
2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627
  | 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 已提交
2628

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

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

A
Annie_wang 已提交
2643 2644 2645
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
2646 2647
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
A
Annie_wang 已提交
2648 2649
  let data = rpc.MessageSequence.create();
  data.writeRemoteObjectArray(a);
Z
zengyawen 已提交
2650
  let b = new Array(3);
A
Annie_wang 已提交
2651 2652 2653 2654 2655 2656
  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 已提交
2657 2658 2659
  data.readRemoteObjectArray(b);
  ```

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

readRemoteObjectArray(): IRemoteObject[]

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

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

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

A
Annie_wang 已提交
2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680
  | 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 已提交
2681

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

A
Annie_wang 已提交
2684
  ```ts
Z
zengyawen 已提交
2685 2686 2687
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
A
Annie_wang 已提交
2688
          this.modifyLocalInterface(this, descriptor);
A
Annie_wang 已提交
2689
      }
A
Annie_wang 已提交
2690
 
A
Annie_wang 已提交
2691 2692 2693
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
2694 2695
  }
  let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
A
Annie_wang 已提交
2696 2697 2698 2699 2700 2701 2702 2703 2704
  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 已提交
2705 2706 2707
  ```


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

static closeFileDescriptor(fd: number): void

A
Annie_wang 已提交
2712
Closes a file descriptor. This API is a static method.
Z
zengyawen 已提交
2713

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

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

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

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

A
Annie_wang 已提交
2724
  ```ts
Z
zengyawen 已提交
2725 2726 2727
  import fileio from '@ohos.fileio';
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
A
Annie_wang 已提交
2728 2729 2730 2731 2732 2733
  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 已提交
2734 2735
  ```

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

static dupFileDescriptor(fd: number) :number

A
Annie_wang 已提交
2740
Duplicates a file descriptor. This API is a static method.
Z
zengyawen 已提交
2741

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

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

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

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

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

A
Annie_wang 已提交
2756 2757 2758 2759 2760 2761 2762 2763
**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 已提交
2764
**Example**
A
annie_wangli 已提交
2765

A
Annie_wang 已提交
2766
  ```ts
Z
zengyawen 已提交
2767 2768 2769
  import fileio from '@ohos.fileio';
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
A
Annie_wang 已提交
2770 2771 2772 2773 2774 2775
  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 已提交
2776 2777
  ```

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

containFileDescriptors(): boolean

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

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

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

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

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

A
Annie_wang 已提交
2794

A
Annie_wang 已提交
2795
  ```ts
Z
zengyawen 已提交
2796
  import fileio from '@ohos.fileio';
A
Annie_wang 已提交
2797
  let sequence = new rpc.MessageSequence();
Z
zengyawen 已提交
2798
  let filePath = "path/to/file";
A
Annie_wang 已提交
2799
  let r1 = sequence.containFileDescriptors();
Z
zengyawen 已提交
2800
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
A
Annie_wang 已提交
2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813
  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 已提交
2814 2815
  ```

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

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

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

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

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

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

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

A
Annie_wang 已提交
2832 2833 2834 2835 2836
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 已提交
2837

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

A
Annie_wang 已提交
2840
  ```ts
Z
zengyawen 已提交
2841
  import fileio from '@ohos.fileio';
A
Annie_wang 已提交
2842
  let sequence = new rpc.MessageSequence();
Z
zengyawen 已提交
2843 2844
  let filePath = "path/to/file";
  let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
A
Annie_wang 已提交
2845 2846 2847 2848 2849 2850
  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 已提交
2851 2852
  ```

A
Annie_wang 已提交
2853 2854 2855 2856
### readFileDescriptor

readFileDescriptor(): number

A
Annie_wang 已提交
2857
Reads the file descriptor from this **MessageSequence** object.
A
Annie_wang 已提交
2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876

**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**

A
Annie_wang 已提交
2877
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
2920
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
2962
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3002
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3033
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3074
  ```ts
A
Annie_wang 已提交
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
  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

A
Annie_wang 已提交
3100
static create(): MessageParcel
A
Annie_wang 已提交
3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113

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**

A
Annie_wang 已提交
3114
  ```ts
A
Annie_wang 已提交
3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128
  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**

A
Annie_wang 已提交
3129
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3156
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3197
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3245
  ```ts
A
Annie_wang 已提交
3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267
  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**

A
Annie_wang 已提交
3268
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3294
  ```ts
A
Annie_wang 已提交
3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315
  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**

A
Annie_wang 已提交
3316
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3344
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3372
  ```ts
A
Annie_wang 已提交
3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393
  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**

A
Annie_wang 已提交
3394
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3420
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3446
  ```ts
A
Annie_wang 已提交
3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467
  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**

A
Annie_wang 已提交
3468
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3497
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3530
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3561
  ```ts
A
Annie_wang 已提交
3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582
  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**

A
Annie_wang 已提交
3583
  ```ts
A
Annie_wang 已提交
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
  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                         |
  | ------- | ----------------------------- |
A
Annie_wang 已提交
3609
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
3610 3611 3612

**Example**

A
Annie_wang 已提交
3613
  ```ts
A
Annie_wang 已提交
3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634
  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**

A
Annie_wang 已提交
3635
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
3665
  ```ts
A
Annie_wang 已提交
3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686
  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**

A
Annie_wang 已提交
3687
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
3713
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
3714 3715 3716

**Example**

A
Annie_wang 已提交
3717
  ```ts
A
Annie_wang 已提交
3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738
  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**

A
Annie_wang 已提交
3739
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
3765
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
3766 3767 3768

**Example**

A
Annie_wang 已提交
3769
  ```ts
A
Annie_wang 已提交
3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790
  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**

A
Annie_wang 已提交
3791
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
3817
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
3818 3819 3820

**Example**

A
Annie_wang 已提交
3821
  ```ts
A
Annie_wang 已提交
3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842
  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**

A
Annie_wang 已提交
3843
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
3869
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
3870 3871 3872

**Example**

A
Annie_wang 已提交
3873
  ```ts
A
Annie_wang 已提交
3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894
  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**

A
Annie_wang 已提交
3895
  ```ts
A
Annie_wang 已提交
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
  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                         |
  | ------- | ----------------------------- |
A
Annie_wang 已提交
3921
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
3922 3923 3924

**Example**

A
Annie_wang 已提交
3925
  ```ts
A
Annie_wang 已提交
3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946
  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**

A
Annie_wang 已提交
3947
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
3973
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
3974 3975 3976

**Example**

A
Annie_wang 已提交
3977
  ```ts
A
Annie_wang 已提交
3978 3979 3980 3981 3982 3983 3984 3985 3986
  let data = rpc.MessageParcel.create();
  let result = data.writeString('abc');
  console.log("RpcClient: writeString  is " + result);
  ```

### readString

readString(): string

A
Annie_wang 已提交
3987
Reads the string from this **MessageParcel** object.
A
Annie_wang 已提交
3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998

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

**Return value**

  | Type  | Description          |
  | ------ | -------------- |
  | string | String read.|

**Example**

A
Annie_wang 已提交
3999
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
4025
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4026 4027 4028

**Example**

A
Annie_wang 已提交
4029
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
4076
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
4122
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4123 4124 4125

**Example**

A
Annie_wang 已提交
4126
  ```ts
A
Annie_wang 已提交
4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148
  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**

A
Annie_wang 已提交
4149
  ```ts
A
Annie_wang 已提交
4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173
  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**

A
Annie_wang 已提交
4174
  ```ts
A
Annie_wang 已提交
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
  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                         |
  | ------- | ----------------------------- |
A
Annie_wang 已提交
4201
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4202 4203 4204

**Example**

A
Annie_wang 已提交
4205
  ```ts
A
Annie_wang 已提交
4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226
  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**

A
Annie_wang 已提交
4227
  ```ts
A
Annie_wang 已提交
4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250
  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**

A
Annie_wang 已提交
4251
  ```ts
A
Annie_wang 已提交
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
  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                         |
  | ------- | ----------------------------- |
A
Annie_wang 已提交
4277
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4278 4279 4280

**Example**

A
Annie_wang 已提交
4281
  ```ts
A
Annie_wang 已提交
4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302
  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**

A
Annie_wang 已提交
4303
  ```ts
A
Annie_wang 已提交
4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326
  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**

A
Annie_wang 已提交
4327
  ```ts
A
Annie_wang 已提交
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
  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                         |
  | ------- | ----------------------------- |
A
Annie_wang 已提交
4353
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4354 4355 4356

**Example**

A
Annie_wang 已提交
4357
  ```ts
A
Annie_wang 已提交
4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378
  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**

A
Annie_wang 已提交
4379
  ```ts
A
Annie_wang 已提交
4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402
  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**

A
Annie_wang 已提交
4403
  ```ts
A
Annie_wang 已提交
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
  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                         |
  | ------- | ----------------------------- |
A
Annie_wang 已提交
4429
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4430 4431 4432

**Example**

A
Annie_wang 已提交
4433
  ```ts
A
Annie_wang 已提交
4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454
  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**

A
Annie_wang 已提交
4455
  ```ts
A
Annie_wang 已提交
4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478
  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**

A
Annie_wang 已提交
4479
  ```ts
A
Annie_wang 已提交
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
  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                         |
  | ------- | ----------------------------- |
A
Annie_wang 已提交
4505
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4506 4507 4508

**Example**

A
Annie_wang 已提交
4509
  ```ts
A
Annie_wang 已提交
4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530
  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**

A
Annie_wang 已提交
4531
  ```ts
A
Annie_wang 已提交
4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554
  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**

A
Annie_wang 已提交
4555
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
4581
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4582 4583 4584

**Example**

A
Annie_wang 已提交
4585
  ```ts
A
Annie_wang 已提交
4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606
  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**

A
Annie_wang 已提交
4607
  ```ts
A
Annie_wang 已提交
4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630
  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**

A
Annie_wang 已提交
4631
  ```ts
A
Annie_wang 已提交
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
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
4657
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4658 4659 4660

**Example**

A
Annie_wang 已提交
4661
  ```ts
A
Annie_wang 已提交
4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682
  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**

A
Annie_wang 已提交
4683
  ```ts
A
Annie_wang 已提交
4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706
  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**

A
Annie_wang 已提交
4707
  ```ts
A
Annie_wang 已提交
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
  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|
  | ------- | --------------------------------- |
A
Annie_wang 已提交
4733
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4734 4735 4736

**Example**

A
Annie_wang 已提交
4737
  ```ts
A
Annie_wang 已提交
4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758
  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**

A
Annie_wang 已提交
4759
  ```ts
A
Annie_wang 已提交
4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782
  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**

A
Annie_wang 已提交
4783
  ```ts
A
Annie_wang 已提交
4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800
  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**

A
Annie_wang 已提交
4801
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
4843
  ```ts
A
Annie_wang 已提交
4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859
  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",
A
Annie_wang 已提交
4860
      "abilityName": "com.ohos.server.EntryAbility",
A
Annie_wang 已提交
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
  };
  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                             |
  | ------- | --------------------------------- |
A
Annie_wang 已提交
4905
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
4906 4907 4908

**Example**

A
Annie_wang 已提交
4909
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
4953
  ```ts
A
Annie_wang 已提交
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
  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                                                                                                                |
  | ------- | -------------------------------------------------------------------------------------------------------------------- |
A
Annie_wang 已提交
5001
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
A
Annie_wang 已提交
5002 5003 5004

**Example**

A
Annie_wang 已提交
5005
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
5051
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
5098
  ```ts
A
Annie_wang 已提交
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
  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

A
Annie_wang 已提交
5134
Closes a file descriptor. This API is a static method.
A
Annie_wang 已提交
5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145

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

**Parameters**

  | Name| Type  | Mandatory| Description                |
  | ------ | ------ | ---- | -------------------- |
  | fd     | number | Yes  | File descriptor to close.|

**Example**

A
Annie_wang 已提交
5146
  ```ts
A
Annie_wang 已提交
5147 5148 5149 5150 5151 5152 5153 5154 5155 5156
  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

A
Annie_wang 已提交
5157
Duplicates a file descriptor. This API is a static method.
A
Annie_wang 已提交
5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174

**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**

A
Annie_wang 已提交
5175
  ```ts
A
Annie_wang 已提交
5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193
  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                                                              |
  | ------- | ------------------------------------------------------------------ |
A
Annie_wang 已提交
5194
  | boolean |Returns **true** if the **MessageSequence** object contains a file descriptor; returns **false** otherwise.|
A
Annie_wang 已提交
5195 5196 5197

**Example**

A
Annie_wang 已提交
5198
  ```ts
A
Annie_wang 已提交
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
  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**

A
Annie_wang 已提交
5232
  ```ts
A
Annie_wang 已提交
5233 5234 5235 5236 5237 5238 5239 5240 5241
  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 已提交
5242 5243 5244

readFileDescriptor(): number

A
annie_wangli 已提交
5245
Reads the file descriptor from this **MessageParcel** object.
Z
zengyawen 已提交
5246

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

A
Annie_wang 已提交
5249
**Return value**
A
Annie_wang 已提交
5250

A
Annie_wang 已提交
5251 5252
  | Type  | Description            |
  | ------ | ---------------- |
A
annie_wangli 已提交
5253
  | number | File descriptor read.|
Z
zengyawen 已提交
5254

A
Annie_wang 已提交
5255
**Example**
A
annie_wangli 已提交
5256

A
Annie_wang 已提交
5257
  ```ts
Z
zengyawen 已提交
5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272
  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 已提交
5273
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5274

A
Annie_wang 已提交
5275
**Parameters**
A
Annie_wang 已提交
5276

A
Annie_wang 已提交
5277 5278 5279
  | Name| Type  | Mandatory| Description                               |
  | ------ | ------ | ---- | ----------------------------------- |
  | ashmem | Ashmem | Yes  | Anonymous shared object to write.|
Z
zengyawen 已提交
5280

A
Annie_wang 已提交
5281
**Return value**
A
Annie_wang 已提交
5282

A
Annie_wang 已提交
5283 5284
  | Type   | Description                                                                |
  | ------- | -------------------------------------------------------------------- |
A
Annie_wang 已提交
5285
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
Z
zengyawen 已提交
5286

A
Annie_wang 已提交
5287
**Example**
A
annie_wangli 已提交
5288

A
Annie_wang 已提交
5289
  ```ts
Z
zengyawen 已提交
5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301
  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 已提交
5302
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5303

A
Annie_wang 已提交
5304
**Return value**
A
Annie_wang 已提交
5305

A
Annie_wang 已提交
5306 5307
  | Type  | Description              |
  | ------ | ------------------ |
A
annie_wangli 已提交
5308
  | Ashmem | Anonymous share object obtained.|
Z
zengyawen 已提交
5309

A
Annie_wang 已提交
5310
**Example**
A
annie_wangli 已提交
5311

A
Annie_wang 已提交
5312
  ```ts
Z
zengyawen 已提交
5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326
  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 已提交
5327
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5328

A
Annie_wang 已提交
5329
**Return value**
A
Annie_wang 已提交
5330

A
Annie_wang 已提交
5331 5332
  | Type  | Description                                                      |
  | ------ | ---------------------------------------------------------- |
A
annie_wangli 已提交
5333
  | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.|
Z
zengyawen 已提交
5334

A
Annie_wang 已提交
5335
**Example**
A
annie_wangli 已提交
5336

A
Annie_wang 已提交
5337
  ```ts
Z
zengyawen 已提交
5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348
  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 已提交
5349
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5350

A
Annie_wang 已提交
5351
**Parameters**
A
Annie_wang 已提交
5352

A
Annie_wang 已提交
5353 5354 5355 5356
  | Name | Type    | Mandatory| Description                              |
  | ------- | -------- | ---- | ---------------------------------- |
  | rawData | number[] | Yes  | Raw data to write.                |
  | size    | number   | Yes  | Size of the raw data, in bytes.|
Z
zengyawen 已提交
5357

A
Annie_wang 已提交
5358
**Return value**
A
Annie_wang 已提交
5359

A
Annie_wang 已提交
5360 5361
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
Annie_wang 已提交
5362
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
Z
zengyawen 已提交
5363

A
Annie_wang 已提交
5364
**Example**
A
annie_wangli 已提交
5365

A
Annie_wang 已提交
5366
  ```ts
Z
zengyawen 已提交
5367
  let parcel = new rpc.MessageParcel();
A
Annie_wang 已提交
5368
  let arr = [1, 2, 3, 4, 5];
Z
zengyawen 已提交
5369 5370 5371 5372 5373 5374 5375 5376 5377 5378
  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 已提交
5379
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
5380

A
Annie_wang 已提交
5381
**Parameters**
A
Annie_wang 已提交
5382

A
Annie_wang 已提交
5383 5384 5385
  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | size   | number | Yes  | Size of the raw data to read.|
Z
zengyawen 已提交
5386

A
Annie_wang 已提交
5387
**Return value**
A
Annie_wang 已提交
5388

A
Annie_wang 已提交
5389 5390
  | Type    | Description                          |
  | -------- | ------------------------------ |
A
annie_wangli 已提交
5391
  | number[] | Raw data obtained, in bytes.|
Z
zengyawen 已提交
5392

A
Annie_wang 已提交
5393
**Example**
A
annie_wangli 已提交
5394

A
Annie_wang 已提交
5395
  ```ts
Z
zengyawen 已提交
5396
  let parcel = new rpc.MessageParcel();
A
Annie_wang 已提交
5397
  let arr = [1, 2, 3, 4, 5];
Z
zengyawen 已提交
5398 5399 5400 5401 5402 5403
  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 已提交
5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428
## 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**

A
Annie_wang 已提交
5429
  ```ts
A
Annie_wang 已提交
5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478
  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**

A
Annie_wang 已提交
5479
  ```ts
A
Annie_wang 已提交
5480 5481 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
  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);
  ```

## 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 已提交
5512 5513 5514 5515 5516

### marshalling

marshalling(dataOut: MessageParcel): boolean

A
annie_wangli 已提交
5517 5518 5519
Marshals the sequenceable object into a **MessageParcel** object.

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

A
Annie_wang 已提交
5521
**Parameters**
A
Annie_wang 已提交
5522

A
Annie_wang 已提交
5523 5524 5525
  | Name | Type                           | Mandatory| Description                                     |
  | ------- | ------------------------------- | ---- | ----------------------------------------- |
  | dataOut | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object to which the sequenceable object is to be marshaled.|
Z
zengyawen 已提交
5526

A
Annie_wang 已提交
5527
**Return value**
A
Annie_wang 已提交
5528

A
Annie_wang 已提交
5529 5530
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
5531
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
5532
**Example**
A
annie_wangli 已提交
5533

A
Annie_wang 已提交
5534
  ```ts
Z
zengyawen 已提交
5535
  class MySequenceable {
A
Annie_wang 已提交
5536 5537 5538
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
5539
          this.num = num;
A
Annie_wang 已提交
5540
          this.str = str;
Z
zengyawen 已提交
5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563
      }
      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 已提交
5564
unmarshalling(dataIn: MessageParcel): boolean
Z
zengyawen 已提交
5565 5566 5567

Unmarshals this sequenceable object from a **MessageParcel** object.

A
annie_wangli 已提交
5568 5569
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5570
**Parameters**
A
Annie_wang 已提交
5571

A
Annie_wang 已提交
5572 5573 5574
  | Name| Type                           | Mandatory| Description                                         |
  | ------ | ------------------------------- | ---- | --------------------------------------------- |
  | dataIn | [MessageParcel](#messageparceldeprecated) | Yes  | **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
Z
zengyawen 已提交
5575

A
Annie_wang 已提交
5576
**Return value**
A
Annie_wang 已提交
5577

A
Annie_wang 已提交
5578 5579
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
annie_wangli 已提交
5580
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
5581

A
Annie_wang 已提交
5582
**Example**
A
annie_wangli 已提交
5583

A
Annie_wang 已提交
5584
  ```ts
Z
zengyawen 已提交
5585
  class MySequenceable {
A
Annie_wang 已提交
5586 5587 5588
      num: number;
      str: string;
      constructor(num, str) {
Z
zengyawen 已提交
5589
          this.num = num;
A
Annie_wang 已提交
5590
          this.str = str;
Z
zengyawen 已提交
5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613
      }
      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 已提交
5614
Provides the holder of a remote proxy object.
Z
zengyawen 已提交
5615 5616 5617 5618 5619

### asObject

asObject(): IRemoteObject

A
Annie_wang 已提交
5620
Obtains a proxy or remote object. This API must be implemented by its derived classes.
Z
zengyawen 已提交
5621

A
annie_wangli 已提交
5622 5623
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5624
**Return value**
A
Annie_wang 已提交
5625

A
Annie_wang 已提交
5626 5627 5628
  | 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 已提交
5629

A
Annie_wang 已提交
5630
**Example**
A
annie_wangli 已提交
5631

A
Annie_wang 已提交
5632
  ```ts
Z
zengyawen 已提交
5633 5634 5635 5636 5637
  class TestAbility extends rpc.RemoteObject {
      asObject() {
          return this;
      }
  }
A
Annie_wang 已提交
5638
  let remoteObject = new TestAbility().asObject();
Z
zengyawen 已提交
5639 5640
  ```

A
Annie_wang 已提交
5641
**Example**
A
annie_wangli 已提交
5642

A
Annie_wang 已提交
5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663
  ```ts
  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.EntryAbility",
  };
  FA.connectAbility(want, connect);

Z
zengyawen 已提交
5664
  class TestProxy {
A
Annie_wang 已提交
5665
      remote: rpc.RemoteObject;
Z
zengyawen 已提交
5666 5667 5668 5669 5670 5671 5672
      constructor(remote) {
          this.remote = remote;
      }
      asObject() {
          return this.remote;
      }
  }
A
Annie_wang 已提交
5673 5674
  let iRemoteObject = new TestProxy(proxy).asObject();

Z
zengyawen 已提交
5675 5676 5677 5678
  ```

## DeathRecipient

A
annie_wangli 已提交
5679
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 已提交
5680 5681 5682 5683 5684 5685 5686

### onRemoteDied

onRemoteDied(): void

Called to perform subsequent operations when a death notification of the remote object is received.

A
annie_wangli 已提交
5687 5688
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5689
**Example**
A
annie_wangli 已提交
5690

A
Annie_wang 已提交
5691
  ```ts
Z
zengyawen 已提交
5692 5693
  class MyDeathRecipient {
      onRemoteDied() {
A
Annie_wang 已提交
5694
          console.log("server died");
Z
zengyawen 已提交
5695 5696 5697 5698
      }
  }
  ```

A
Annie_wang 已提交
5699
## RequestResult<sup>9+</sup>
Z
zengyawen 已提交
5700 5701 5702

Defines the response to the request.

A
annie_wangli 已提交
5703 5704
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718
  | 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 已提交
5719

A
Annie_wang 已提交
5720 5721 5722 5723 5724 5725
  | 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 已提交
5726 5727 5728

## IRemoteObject

A
annie_wangli 已提交
5729
Provides methods to query of obtain interface descriptors, add or delete death notifications, dump object status to specific files, and send messages.
Z
zengyawen 已提交
5730

A
Annie_wang 已提交
5731 5732 5733 5734
### getLocalInterface<sup>9+</sup>

getLocalInterface(descriptor: string): IRemoteBroker

A
Annie_wang 已提交
5735
Obtains the interface descriptor.
A
Annie_wang 已提交
5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749

**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 已提交
5750

A
Annie_wang 已提交
5751 5752 5753
### queryLocalInterface<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).
Z
zengyawen 已提交
5754 5755 5756

queryLocalInterface(descriptor: string): IRemoteBroker

A
Annie_wang 已提交
5757
Queries the interface descriptor.
Z
zengyawen 已提交
5758

A
annie_wangli 已提交
5759 5760
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5761
**Parameters**
A
Annie_wang 已提交
5762

A
Annie_wang 已提交
5763 5764 5765
  | Name    | Type  | Mandatory| Description                |
  | ---------- | ------ | ---- | -------------------- |
  | descriptor | string | Yes  | Interface descriptor.|
Z
zengyawen 已提交
5766

A
Annie_wang 已提交
5767
**Return value**
A
Annie_wang 已提交
5768

A
Annie_wang 已提交
5769 5770 5771
  | Type         | Description                                         |
  | ------------- | --------------------------------------------- |
  | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
Z
zengyawen 已提交
5772

A
Annie_wang 已提交
5773
### sendRequest<sup>(deprecated)</sup>
Z
zengyawen 已提交
5774

A
Annie_wang 已提交
5775
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
A
Annie_wang 已提交
5776

A
Annie_wang 已提交
5777
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
Z
zengyawen 已提交
5778

A
annie_wangli 已提交
5779 5780 5781
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 已提交
5782

A
Annie_wang 已提交
5783
**Parameters**
A
Annie_wang 已提交
5784

A
Annie_wang 已提交
5785 5786 5787 5788 5789 5790
  | 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 已提交
5791

A
Annie_wang 已提交
5792
**Return value**
A
Annie_wang 已提交
5793

A
Annie_wang 已提交
5794 5795
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
5796
  | boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
A
Annie_wang 已提交
5797 5798


A
Annie_wang 已提交
5799 5800
### sendRequest<sup>8+(deprecated)</sup>

A
Annie_wang 已提交
5801
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
A
Annie_wang 已提交
5802

A
Annie_wang 已提交
5803
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
A
Annie_wang 已提交
5804

A
Annie_wang 已提交
5805 5806 5807 5808
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 已提交
5809
**Parameters**
A
Annie_wang 已提交
5810

A
Annie_wang 已提交
5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890
  | 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

A
Annie_wang 已提交
5891
Registers 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 已提交
5892 5893 5894 5895 5896 5897 5898

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

**Parameters**

  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
A
Annie_wang 已提交
5899
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to register.|
A
Annie_wang 已提交
5900 5901 5902 5903 5904 5905 5906 5907 5908
  | 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 已提交
5909

A
Annie_wang 已提交
5910
### addDeathrecipient<sup>(deprecated)</sup>
A
Annie_wang 已提交
5911

A
Annie_wang 已提交
5912
>This API is no longer maintained since API version 9. You are advised to use [registerDeathRecipient](#registerdeathrecipient9).
A
Annie_wang 已提交
5913

A
Annie_wang 已提交
5914
addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
A
Annie_wang 已提交
5915

A
Annie_wang 已提交
5916
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 已提交
5917 5918 5919

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

A
Annie_wang 已提交
5920
**Parameters**
A
Annie_wang 已提交
5921

A
Annie_wang 已提交
5922 5923 5924 5925
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to add.|
  | flags     | number                            | Yes  | Flag of the death notification.|
Z
zengyawen 已提交
5926

A
Annie_wang 已提交
5927
**Return value**
A
Annie_wang 已提交
5928

A
Annie_wang 已提交
5929 5930
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
5931
  | boolean | Returns **true** if the callback is added successfully; return **false** otherwise.|
Z
zengyawen 已提交
5932 5933


A
Annie_wang 已提交
5934
### unregisterDeathRecipient<sup>9+</sup>
Z
zengyawen 已提交
5935

A
Annie_wang 已提交
5936 5937
unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void

A
Annie_wang 已提交
5938
Unregisters the callback used to receive death notifications of the remote object.
A
annie_wangli 已提交
5939 5940

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

A
Annie_wang 已提交
5942
**Parameters**
A
Annie_wang 已提交
5943

A
Annie_wang 已提交
5944 5945
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
A
Annie_wang 已提交
5946
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to unregister.|
A
Annie_wang 已提交
5947
  | flags     | number                            | Yes  | Flag of the death notification.|
Z
zengyawen 已提交
5948

A
Annie_wang 已提交
5949
**Error Code**
Z
zengyawen 已提交
5950

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

A
Annie_wang 已提交
5953 5954 5955
  | ID| Error Message|
  | ------- | -------- |
  | 1900008 | proxy or remote object is invalid |
Z
zengyawen 已提交
5956

A
Annie_wang 已提交
5957 5958 5959 5960 5961 5962 5963
### 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 已提交
5964

A
annie_wangli 已提交
5965 5966
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5967
**Parameters**
A
Annie_wang 已提交
5968

A
Annie_wang 已提交
5969 5970 5971 5972
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to remove.|
  | flags     | number                            | Yes  | Flag of the death notification.|
Z
zengyawen 已提交
5973

A
Annie_wang 已提交
5974
**Return value**
A
Annie_wang 已提交
5975

A
Annie_wang 已提交
5976 5977
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
5978
  | boolean | Returns **true** if the callback is removed; returns **false** otherwise.|
Z
zengyawen 已提交
5979

A
Annie_wang 已提交
5980
### getDescriptor<sup>9+</sup>
Z
zengyawen 已提交
5981

A
Annie_wang 已提交
5982
getDescriptor(): string
Z
zengyawen 已提交
5983

A
Annie_wang 已提交
5984
Obtains the interface descriptor of this object. The interface descriptor is a string.
Z
zengyawen 已提交
5985

A
annie_wangli 已提交
5986 5987
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
5988
**Return value**
A
Annie_wang 已提交
5989

A
Annie_wang 已提交
5990 5991 5992
  | Type  | Description            |
  | ------ | ---------------- |
  | string | Interface descriptor obtained.|
Z
zengyawen 已提交
5993

A
Annie_wang 已提交
5994
**Error Code**
A
Annie_wang 已提交
5995

A
Annie_wang 已提交
5996 5997 5998 5999 6000
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 已提交
6001 6002


A
Annie_wang 已提交
6003 6004 6005
### getInterfaceDescriptor<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
Z
zengyawen 已提交
6006 6007 6008

getInterfaceDescriptor(): string

A
annie_wangli 已提交
6009 6010 6011
Obtains the interface descriptor of this object. The interface descriptor is a string.

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

A
Annie_wang 已提交
6013
**Return value**
A
Annie_wang 已提交
6014

A
Annie_wang 已提交
6015 6016
  | Type  | Description            |
  | ------ | ---------------- |
A
annie_wangli 已提交
6017
  | string | Interface descriptor obtained.|
Z
zengyawen 已提交
6018 6019 6020 6021 6022 6023


### isObjectDead

isObjectDead(): boolean

A
annie_wangli 已提交
6024
Checks whether this object is dead.
Z
zengyawen 已提交
6025

A
annie_wangli 已提交
6026 6027
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
6028
**Return value**
A
Annie_wang 已提交
6029

A
Annie_wang 已提交
6030 6031
  | Type   | Description                                       |
  | ------- | ------------------------------------------- |
A
annie_wangli 已提交
6032
  | boolean | Returns **true** if the object is dead; returns **false** otherwise.|
Z
zengyawen 已提交
6033 6034 6035 6036


## RemoteProxy

A
Annie_wang 已提交
6037
Provides APIs to implement **IRemoteObject**.
Z
zengyawen 已提交
6038

A
annie_wangli 已提交
6039 6040
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
6041
| Name                 | Value                     | Description                             |
A
annie_wangli 已提交
6042 6043
| --------------------- | ----------------------- | --------------------------------- |
| PING_TRANSACTION      | 1599098439 (0x5f504e47) | Internal instruction code used to test whether the IPC service is normal.|
A
Annie_wang 已提交
6044 6045
| 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 已提交
6046 6047 6048
| MIN_TRANSACTION_ID    | 1 (0x00000001)          | Minimum valid instruction code.                 |
| MAX_TRANSACTION_ID    | 16777215 (0x00FFFFFF)   | Maximum valid instruction code.                 |

A
Annie_wang 已提交
6049
### sendRequest<sup>(deprecated)</sup>
Z
zengyawen 已提交
6050

A
Annie_wang 已提交
6051
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
Z
zengyawen 已提交
6052

A
Annie_wang 已提交
6053
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
A
Annie_wang 已提交
6054

A
annie_wangli 已提交
6055 6056 6057
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 已提交
6058

A
Annie_wang 已提交
6059
**Parameters**
A
Annie_wang 已提交
6060

A
Annie_wang 已提交
6061 6062 6063 6064 6065 6066
  | 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 已提交
6067

A
Annie_wang 已提交
6068
**Return value**
A
Annie_wang 已提交
6069

A
Annie_wang 已提交
6070 6071
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
6072
  | boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
A
Annie_wang 已提交
6073 6074

**Example**
Z
zengyawen 已提交
6075

A
Annie_wang 已提交
6076
  ```ts
Z
zengyawen 已提交
6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091
  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 已提交
6092
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
6093
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
6094 6095 6096 6097 6098 6099 6100
  };
  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 已提交
6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111
  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 已提交
6112 6113
  ```

A
Annie_wang 已提交
6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138
### 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**

A
Annie_wang 已提交
6139
  ```ts
A
Annie_wang 已提交
6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155
  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",
A
Annie_wang 已提交
6156
      "abilityName": "com.ohos.server.EntryAbility",
A
Annie_wang 已提交
6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182
  };
  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 已提交
6183 6184
### sendRequest<sup>8+(deprecated)</sup>

A
Annie_wang 已提交
6185
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
A
Annie_wang 已提交
6186

A
Annie_wang 已提交
6187
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
A
Annie_wang 已提交
6188

A
Annie_wang 已提交
6189 6190 6191 6192 6193
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 已提交
6194

A
Annie_wang 已提交
6195 6196 6197 6198 6199 6200
  | 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 已提交
6201 6202

**Return value**
A
Annie_wang 已提交
6203

A
Annie_wang 已提交
6204 6205
  | Type                            | Description                                         |
  | -------------------------------- | --------------------------------------------- |
A
Annie_wang 已提交
6206 6207 6208
  | Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|

**Example**
A
annie_wangli 已提交
6209

A
Annie_wang 已提交
6210
  ```ts
Z
zengyawen 已提交
6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225
  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 已提交
6226
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
6227
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
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 6253
  };
  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 已提交
6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273
### 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**

A
Annie_wang 已提交
6274
  ```ts
A
Annie_wang 已提交
6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290
  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",
A
Annie_wang 已提交
6291
      "abilityName": "com.ohos.server.EntryAbility",
A
Annie_wang 已提交
6292 6293 6294 6295 6296 6297 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 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341
  };
  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**

A
Annie_wang 已提交
6342
  ```ts
A
Annie_wang 已提交
6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358
  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",
A
Annie_wang 已提交
6359
      "abilityName": "com.ohos.server.EntryAbility",
A
Annie_wang 已提交
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
  };
  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**

A
Annie_wang 已提交
6413
  ```ts
A
Annie_wang 已提交
6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429
  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",
A
Annie_wang 已提交
6430
      "abilityName":"com.ohos.server.EntryAbility",
A
Annie_wang 已提交
6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442
  };
  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 已提交
6443

A
Annie_wang 已提交
6444 6445 6446
>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).

queryLocalInterface(interface: string): IRemoteBroker
A
Annie_wang 已提交
6447

A
Annie_wang 已提交
6448
Obtains the **LocalInterface** object of an interface token.
A
Annie_wang 已提交
6449 6450 6451 6452

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

**Parameters**
A
Annie_wang 已提交
6453

A
Annie_wang 已提交
6454 6455 6456
  | Name   | Type  | Mandatory| Description                  |
  | --------- | ------ | ---- | ---------------------- |
  | interface | string | Yes  | Interface descriptor.|
A
Annie_wang 已提交
6457 6458

**Return value**
A
Annie_wang 已提交
6459

A
Annie_wang 已提交
6460 6461 6462
  | Type         | Description                                      |
  | ------------- | ------------------------------------------ |
  | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
A
Annie_wang 已提交
6463 6464 6465

**Example**

A
Annie_wang 已提交
6466
  ```ts
A
Annie_wang 已提交
6467 6468 6469 6470 6471 6472 6473
  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 已提交
6474
      onDisconnect: function (elementName) {
A
Annie_wang 已提交
6475 6476 6477 6478 6479 6480 6481
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
Annie_wang 已提交
6482
      "bundleName":"com.ohos.server",
A
Annie_wang 已提交
6483
      "abilityName":"com.ohos.server.EntryAbility",
A
Annie_wang 已提交
6484 6485
  };
  FA.connectAbility(want, connect);
A
Annie_wang 已提交
6486 6487
  let broker = proxy.queryLocalInterface("testObject");
  console.log("RpcClient: queryLocalInterface is " + broker);
A
Annie_wang 已提交
6488
  ```
Z
zengyawen 已提交
6489

A
Annie_wang 已提交
6490
### registerDeathRecipient<sup>9+</sup>
Z
zengyawen 已提交
6491

A
Annie_wang 已提交
6492 6493
registerDeathRecipient(recipient: DeathRecipient, flags: number): void

A
Annie_wang 已提交
6494
Registers 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 已提交
6495

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

A
Annie_wang 已提交
6498
**Parameters**
A
Annie_wang 已提交
6499

A
Annie_wang 已提交
6500 6501
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
A
Annie_wang 已提交
6502
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to register.|
A
Annie_wang 已提交
6503 6504 6505 6506 6507 6508 6509 6510 6511
  | 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 已提交
6512

A
Annie_wang 已提交
6513
**Example**
A
annie_wangli 已提交
6514

A
Annie_wang 已提交
6515
  ```ts
Z
zengyawen 已提交
6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530
  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 已提交
6531
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
6532
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
6533
  };
A
Annie_wang 已提交
6534 6535 6536 6537
  FA.connectAbility(want, connect);
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
Z
zengyawen 已提交
6538 6539
      }
  }
A
Annie_wang 已提交
6540 6541 6542 6543 6544 6545 6546
  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 已提交
6547 6548
  ```

A
Annie_wang 已提交
6549
### addDeathRecippient<sup>(deprecated)</sup>
Z
zengyawen 已提交
6550

A
Annie_wang 已提交
6551 6552 6553
>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 已提交
6554

A
Annie_wang 已提交
6555
Adds a callback for receiving the death notifications of the remote object, including the death notifications of the remote proxy.
Z
zengyawen 已提交
6556

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

A
Annie_wang 已提交
6559
**Parameters**
A
Annie_wang 已提交
6560

A
Annie_wang 已提交
6561 6562 6563 6564
  | 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 已提交
6565

A
Annie_wang 已提交
6566
**Return value**
A
Annie_wang 已提交
6567

A
Annie_wang 已提交
6568 6569
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
6570
  | boolean | Returns **true** if the callback is added successfully; return **false** otherwise.|
Z
zengyawen 已提交
6571

A
Annie_wang 已提交
6572
**Example**
A
annie_wangli 已提交
6573

A
Annie_wang 已提交
6574
  ```ts
Z
zengyawen 已提交
6575 6576 6577 6578 6579 6580 6581
  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 已提交
6582
      onDisconnect: function(elementName) {
Z
zengyawen 已提交
6583 6584 6585 6586 6587 6588 6589
          console.log("RpcClient: onDisconnect");
      },
      onFailed: function() {
          console.log("RpcClient: onFailed");
      }
  };
  let want = {
A
Annie_wang 已提交
6590
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
6591
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
6592 6593
  };
  FA.connectAbility(want, connect);
A
Annie_wang 已提交
6594 6595 6596 6597 6598 6599 6600
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
  let deathRecipient = new MyDeathRecipient();
  proxy.addDeathRecippient(deathRecipient, 0);
Z
zengyawen 已提交
6601 6602
  ```

A
Annie_wang 已提交
6603
### unregisterDeathRecipient<sup>9+</sup>
Z
zengyawen 已提交
6604

A
Annie_wang 已提交
6605
unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean
Z
zengyawen 已提交
6606

A
Annie_wang 已提交
6607
Unregisters the callback used to receive death notifications of the remote object.
Z
zengyawen 已提交
6608

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

A
Annie_wang 已提交
6611
**Parameters**
A
Annie_wang 已提交
6612

A
Annie_wang 已提交
6613 6614
  | Name   | Type                             | Mandatory| Description          |
  | --------- | --------------------------------- | ---- | -------------- |
A
Annie_wang 已提交
6615
  | recipient | [DeathRecipient](#deathrecipient) | Yes  | Callback to unregister.|
A
Annie_wang 已提交
6616
  | flags     | number                            | Yes  | Flag of the death notification.|
Z
zengyawen 已提交
6617

A
Annie_wang 已提交
6618
**Error Code**
A
Annie_wang 已提交
6619

A
Annie_wang 已提交
6620 6621 6622 6623 6624
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 已提交
6625

A
Annie_wang 已提交
6626
**Example**
A
annie_wangli 已提交
6627

A
Annie_wang 已提交
6628
  ```ts
Z
zengyawen 已提交
6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643
  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 已提交
6644
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
6645
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
6646 6647 6648 6649
  };
  FA.connectAbility(want, connect);
  class MyDeathRecipient {
      onRemoteDied() {
A
Annie_wang 已提交
6650
          console.log("server died");
Z
zengyawen 已提交
6651 6652 6653
      }
  }
  let deathRecipient = new MyDeathRecipient();
A
Annie_wang 已提交
6654 6655 6656 6657 6658 6659 6660
  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 已提交
6661 6662
  ```

A
Annie_wang 已提交
6663 6664 6665
### removeDeathRecipient<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [unregisterDeathRecipient](#unregisterdeathrecipient9).
Z
zengyawen 已提交
6666

A
Annie_wang 已提交
6667
removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
Z
zengyawen 已提交
6668 6669 6670

Removes the callback used to receive death notifications of the remote object.

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

A
Annie_wang 已提交
6673
**Parameters**
A
Annie_wang 已提交
6674

A
Annie_wang 已提交
6675 6676 6677 6678
  | 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 已提交
6679

A
Annie_wang 已提交
6680
**Return value**
A
Annie_wang 已提交
6681

A
Annie_wang 已提交
6682 6683
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
6684
  | boolean | Returns **true** if the callback is removed; returns **false** otherwise.|
Z
zengyawen 已提交
6685

A
Annie_wang 已提交
6686
**Example**
A
annie_wangli 已提交
6687

A
Annie_wang 已提交
6688
  ```ts
Z
zengyawen 已提交
6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703
  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 已提交
6704
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
6705
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
6706 6707 6708 6709
  };
  FA.connectAbility(want, connect);
  class MyDeathRecipient {
      onRemoteDied() {
A
Annie_wang 已提交
6710
          console.log("server died");
Z
zengyawen 已提交
6711 6712 6713 6714 6715 6716 6717
      }
  }
  let deathRecipient = new MyDeathRecipient();
  proxy.addDeathRecippient(deathRecipient, 0);
  proxy.removeDeathRecipient(deathRecipient, 0);
  ```

A
Annie_wang 已提交
6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742
### 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**

A
Annie_wang 已提交
6743
  ```ts
A
Annie_wang 已提交
6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759
  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",
A
Annie_wang 已提交
6760
      "abilityName": "com.ohos.server.EntryAbility",
A
Annie_wang 已提交
6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774
  };
  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 已提交
6775 6776 6777 6778 6779

getInterfaceDescriptor(): string

Obtains the interface descriptor of this proxy object.

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

A
Annie_wang 已提交
6782
**Return value**
A
Annie_wang 已提交
6783

A
Annie_wang 已提交
6784 6785
  | Type  | Description              |
  | ------ | ------------------ |
A
annie_wangli 已提交
6786
  | string | Interface descriptor obtained.|
Z
zengyawen 已提交
6787

A
Annie_wang 已提交
6788
**Example**
A
annie_wangli 已提交
6789

A
Annie_wang 已提交
6790
  ```ts
Z
zengyawen 已提交
6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805
  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 已提交
6806
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
6807
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819
  };
  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 已提交
6820
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
6821

A
Annie_wang 已提交
6822
**Return value**
A
Annie_wang 已提交
6823

A
Annie_wang 已提交
6824 6825
  | Type   | Description                                                     |
  | ------- | --------------------------------------------------------- |
A
annie_wangli 已提交
6826
  | boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.|
Z
zengyawen 已提交
6827

A
Annie_wang 已提交
6828
**Example**
A
annie_wangli 已提交
6829

A
Annie_wang 已提交
6830
  ```ts
Z
zengyawen 已提交
6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845
  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 已提交
6846
      "bundleName": "com.ohos.server",
A
Annie_wang 已提交
6847
      "abilityName": "com.ohos.server.EntryAbility",
Z
zengyawen 已提交
6848 6849 6850 6851 6852 6853 6854 6855
  };
  FA.connectAbility(want, connect);
  let isDead = proxy.isObjectDead();
  console.log("RpcClient: isObjectDead is " + isDead);
  ```

## MessageOption

A
Annie_wang 已提交
6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872
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 已提交
6873

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

A
Annie_wang 已提交
6876 6877 6878 6879 6880
**Parameters**

  | Name   | Type  | Mandatory| Description                                  |
  | --------- | ------ | ---- | -------------------------------------- |
  | syncFlags | number | No  | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.|
Z
zengyawen 已提交
6881 6882


A
Annie_wang 已提交
6883 6884 6885 6886 6887 6888 6889 6890 6891 6892
**Example**

  ```ts
  class TestRemoteObject extends rpc.MessageOption {
    constructor(async) {
        super(async);
    }
  }
  ```

Z
zengyawen 已提交
6893 6894
### constructor

A
Annie_wang 已提交
6895
constructor(syncFlags?: number, waitTime?: number)
Z
zengyawen 已提交
6896

A
annie_wangli 已提交
6897 6898 6899
A constructor used to create a **MessageOption** object.

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

A
Annie_wang 已提交
6901
**Parameters**
A
Annie_wang 已提交
6902

A
Annie_wang 已提交
6903 6904 6905 6906 6907
  | 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**.|

A
Annie_wang 已提交
6908
**Example**
A
Annie_wang 已提交
6909

A
Annie_wang 已提交
6910 6911 6912 6913 6914 6915 6916
  ```ts
  class TestRemoteObject extends rpc.MessageOption {
    constructor(syncFlags,waitTime) {
        super(syncFlags,waitTime);
    }
  }
  ```
A
Annie_wang 已提交
6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928
### isAsync<sup>9+</sup>

isAsync(): boolean;

Checks whether **SendMessageRequest** is called synchronously or asynchronously.

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

**Return value**

  | Type   | Description                                |
  | ------- | ------------------------------------ |
A
Annie_wang 已提交
6929
  | boolean | Returns **true** if **SendMessageRequest** is called synchronously; returns **false** if **SendMessageRequest** is called asynchronously.|
A
Annie_wang 已提交
6930

A
Annie_wang 已提交
6931 6932 6933 6934 6935 6936
**Example**

  ```ts
  let option = new rpc.MessageOption();
  let isAsync = option.isAsync();
  ```
A
Annie_wang 已提交
6937 6938 6939 6940 6941 6942 6943 6944

### setAsync<sup>9+</sup>

setAsync(async: boolean): void;

Sets whether **SendMessageRequest** is called synchronously or asynchronously.

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

A
Annie_wang 已提交
6946 6947 6948 6949 6950 6951 6952
**Example**

  ```ts
  let option = new rpc.MessageOption();
  let setAsync = option.setAsync(true);
  console.log("Set synchronization flag");
  ```
Z
zengyawen 已提交
6953 6954 6955 6956 6957

### getFlags

getFlags(): number

A
annie_wangli 已提交
6958
Obtains the call flag, which can be synchronous or asynchronous.
Z
zengyawen 已提交
6959

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

A
Annie_wang 已提交
6962
**Return value**
A
Annie_wang 已提交
6963

A
Annie_wang 已提交
6964 6965
  | Type  | Description                                |
  | ------ | ------------------------------------ |
A
annie_wangli 已提交
6966
  | number | Call mode obtained.|
Z
zengyawen 已提交
6967

A
Annie_wang 已提交
6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983
**Example**

  ```ts
  try {
      let option = new rpc.MessageOption();
      console.info("create object successfully.");
      let flog = option.getFlags();
      console.info("run getFlags success, flog is " + flog);
      option.setFlags(1)
      console.info("run setFlags success");
      let flog2 = option.getFlags();
      console.info("run getFlags success, flog2 is " + flog2);
  } catch (error) {
      console.info("error " + error);
  }
  ```
Z
zengyawen 已提交
6984 6985 6986 6987 6988

### setFlags

setFlags(flags: number): void

A
annie_wangli 已提交
6989 6990 6991
Sets the call flag, which can be synchronous or asynchronous.

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

A
Annie_wang 已提交
6993
**Parameters**
A
Annie_wang 已提交
6994

A
Annie_wang 已提交
6995 6996 6997
  | Name| Type  | Mandatory| Description                    |
  | ------ | ------ | ---- | ------------------------ |
  | flags  | number | Yes  | Call flag to set.|
Z
zengyawen 已提交
6998

A
Annie_wang 已提交
6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011
**Example**

  ```ts
  try {
      let option = new rpc.MessageOption();
      option.setFlags(1)
      console.info("run setFlags success");
      let flog = option.getFlags();
      console.info("run getFlags success, flog is " + flog);
  } catch (error) {
      console.info("error " + error);
  }
  ```
Z
zengyawen 已提交
7012 7013 7014 7015 7016 7017 7018

### getWaitTime

getWaitTime(): number

Obtains the maximum wait time for this RPC call.

A
annie_wangli 已提交
7019 7020
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7021
**Return value**
A
Annie_wang 已提交
7022

A
Annie_wang 已提交
7023 7024
  | Type  | Description             |
  | ------ | ----------------- |
A
annie_wangli 已提交
7025
  | number | Maximum wait time obtained.|
Z
zengyawen 已提交
7026

A
Annie_wang 已提交
7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040
**Example**

  ```ts
  try {
      let option = new rpc.MessageOption();
      let time = option.getWaitTime();
      console.info("run getWaitTime success");
      option.setWaitTime(16);
      let time2 = option.getWaitTime();
      console.info("run getWaitTime success, time is " + time);
  } catch (error) {
      console.info("error " + error);
  }
  ```
Z
zengyawen 已提交
7041 7042 7043 7044 7045 7046 7047

### setWaitTime

setWaitTime(waitTime: number): void

Sets the maximum wait time for this RPC call.

A
annie_wangli 已提交
7048 7049
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7050
**Parameters**
A
Annie_wang 已提交
7051

A
Annie_wang 已提交
7052 7053 7054
  | Name  | Type  | Mandatory| Description                 |
  | -------- | ------ | ---- | --------------------- |
  | waitTime | number | Yes  | Maximum wait time to set.|
Z
zengyawen 已提交
7055

A
Annie_wang 已提交
7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067
**Example**

  ```ts
  try {
      let option = new rpc.MessageOption();
      option.setWaitTime(16);
      let time = option.getWaitTime();
      console.info("run getWaitTime success, time is " + time);
  } catch (error) {
      console.info("error " + error);
  }
  ```
Z
zengyawen 已提交
7068 7069 7070

## IPCSkeleton

A
annie_wangli 已提交
7071
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 已提交
7072 7073 7074 7075 7076

### getContextObject

static getContextObject(): IRemoteObject

A
Annie_wang 已提交
7077
Obtains the system capability manager. This API is a static method.
Z
zengyawen 已提交
7078

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

A
Annie_wang 已提交
7081
**Return value**
A
Annie_wang 已提交
7082

A
Annie_wang 已提交
7083 7084
  | Type                           | Description                |
  | ------------------------------- | -------------------- |
A
annie_wangli 已提交
7085
  | [IRemoteObject](#iremoteobject) | System capability manager obtained.|
Z
zengyawen 已提交
7086

A
Annie_wang 已提交
7087
**Example**
A
annie_wangli 已提交
7088

A
Annie_wang 已提交
7089
  ```ts
Z
zengyawen 已提交
7090 7091 7092 7093 7094 7095 7096 7097
  let samgr = rpc.IPCSkeleton.getContextObject();
  console.log("RpcServer: getContextObject result: " + samgr);
  ```

### getCallingPid

static getCallingPid(): number

A
Annie_wang 已提交
7098
Obtains the PID of the caller. This API is a static method, which is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the PID of the process will be returned.
Z
zengyawen 已提交
7099

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

A
Annie_wang 已提交
7102
**Return value**
A
Annie_wang 已提交
7103

A
Annie_wang 已提交
7104 7105
  | Type  | Description             |
  | ------ | ----------------- |
A
annie_wangli 已提交
7106
  | number | PID of the caller.|
Z
zengyawen 已提交
7107

A
Annie_wang 已提交
7108
**Example**
A
annie_wangli 已提交
7109

A
Annie_wang 已提交
7110
  ```ts
Z
zengyawen 已提交
7111
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7112
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7113 7114 7115 7116
          let callerPid = rpc.IPCSkeleton.getCallingPid();
          console.log("RpcServer: getCallingPid result: " + callerPid);
          return true;
      }
A
Annie_wang 已提交
7117
 }
Z
zengyawen 已提交
7118 7119 7120 7121 7122 7123
  ```

### getCallingUid

static getCallingUid(): number

A
Annie_wang 已提交
7124
Obtains the UID of the caller. This API is a static method, which is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the UID of the process will be returned.
Z
zengyawen 已提交
7125

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

A
Annie_wang 已提交
7128
**Return value**
A
Annie_wang 已提交
7129

A
Annie_wang 已提交
7130 7131
  | Type  | Description             |
  | ------ | ----------------- |
A
annie_wangli 已提交
7132
  | number | UID of the caller.|
Z
zengyawen 已提交
7133

A
Annie_wang 已提交
7134
**Example**
A
annie_wangli 已提交
7135

A
Annie_wang 已提交
7136
  ```ts
Z
zengyawen 已提交
7137
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7138
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7139 7140 7141 7142 7143 7144 7145
          let callerUid = rpc.IPCSkeleton.getCallingUid();
          console.log("RpcServer: getCallingUid result: " + callerUid);
          return true;
      }
  }
  ```

A
Annie_wang 已提交
7146
### getCallingTokenId<sup>8+</sup>
A
annie_wangli 已提交
7147 7148 7149 7150 7151 7152 7153

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 已提交
7154
**Return value**
A
Annie_wang 已提交
7155

A
Annie_wang 已提交
7156 7157 7158
   | Type  | Description                 |
   | ------ | --------------------- |
   | number | Token ID of the caller obtained.|
A
Annie_wang 已提交
7159

A
Annie_wang 已提交
7160
**Example**
A
annie_wangli 已提交
7161

A
Annie_wang 已提交
7162
  ```ts
A
annie_wangli 已提交
7163
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7164
      onRemoteMessageRequest(code, data, reply, option) {
A
annie_wangli 已提交
7165 7166 7167 7168 7169 7170 7171
          let callerTokenId = rpc.IPCSkeleton.getCallingTokenId();
          console.log("RpcServer: getCallingTokenId result: " + callerTokenId);
          return true;
      }
  }
  ```

Z
zengyawen 已提交
7172

A
Annie_wang 已提交
7173
### getCallingDeviceID
Z
zengyawen 已提交
7174 7175 7176 7177 7178

static getCallingDeviceID(): string

Obtains the ID of the device hosting the caller's process.

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

A
Annie_wang 已提交
7181
**Return value**
A
Annie_wang 已提交
7182

A
Annie_wang 已提交
7183 7184
  | Type  | Description                        |
  | ------ | ---------------------------- |
A
annie_wangli 已提交
7185
  | string | Device ID obtained.|
Z
zengyawen 已提交
7186

A
Annie_wang 已提交
7187
**Example**
A
annie_wangli 已提交
7188

A
Annie_wang 已提交
7189
  ```ts
Z
zengyawen 已提交
7190
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7191
      onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7192
          let callerDeviceID = rpc.IPCSkeleton.getCallingDeviceID();
Z
zengyawen 已提交
7193 7194 7195 7196 7197 7198 7199 7200 7201 7202
          console.log("RpcServer: callerDeviceID is: " + callerDeviceID);
          return true;
      }
  }
  ```

### getLocalDeviceID

static getLocalDeviceID(): string

A
Annie_wang 已提交
7203
Obtains the local device ID. This API is a static method.
Z
zengyawen 已提交
7204

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

A
Annie_wang 已提交
7215
  ```ts
Z
zengyawen 已提交
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
          let localDeviceID = rpc.IPCSkeleton.getLocalDeviceID();
          console.log("RpcServer: localDeviceID is: " + localDeviceID);
          return true;
      }
  }
  ```

### isLocalCalling

static isLocalCalling(): boolean

A
Annie_wang 已提交
7229
Checks whether the remote process is a process of the local device. This API is a static method.
Z
zengyawen 已提交
7230

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

A
Annie_wang 已提交
7233
**Return value**
A
Annie_wang 已提交
7234

A
Annie_wang 已提交
7235 7236
  | Type   | Description                                                     |
  | ------- | --------------------------------------------------------- |
A
annie_wangli 已提交
7237
  | boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
Z
zengyawen 已提交
7238

A
Annie_wang 已提交
7239
**Example**
A
annie_wangli 已提交
7240

A
Annie_wang 已提交
7241
  ```ts
Z
zengyawen 已提交
7242
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7243
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7244 7245 7246 7247 7248 7249 7250
          let isLocalCalling = rpc.IPCSkeleton.isLocalCalling();
          console.log("RpcServer: isLocalCalling is: " + isLocalCalling);
          return true;
      }
  }
  ```

A
Annie_wang 已提交
7251
### flushCmdBuffer<sup>9+</sup>
Z
zengyawen 已提交
7252

A
Annie_wang 已提交
7253
static flushCmdBuffer(object: IRemoteObject): void
Z
zengyawen 已提交
7254

A
Annie_wang 已提交
7255
Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. This API is a static method. It is recommended that this method be called before any time-sensitive operation is performed.
Z
zengyawen 已提交
7256

A
annie_wangli 已提交
7257 7258
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7259
**Parameters**
A
Annie_wang 已提交
7260

A
Annie_wang 已提交
7261 7262 7263 7264 7265 7266 7267
  | Name| Type                           | Mandatory| Description               |
  | ------ | ------------------------------- | ---- | ------------------- |
  | object | [IRemoteObject](#iremoteobject) | Yes  | **RemoteProxy** specified. |


**Example**

A
Annie_wang 已提交
7268
  ```ts
A
Annie_wang 已提交
7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287
  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 已提交
7288

A
Annie_wang 已提交
7289
Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. This API is a static method. It is recommended that this method be called before any time-sensitive operation is performed.
A
Annie_wang 已提交
7290 7291 7292 7293 7294 7295 7296 7297

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

**Parameters**

  | Name| Type                           | Mandatory| Description               |
  | ------ | ------------------------------- | ---- | ------------------- |
  | object | [IRemoteObject](#iremoteobject) | Yes  | **RemoteProxy** specified. |
Z
zengyawen 已提交
7298

A
Annie_wang 已提交
7299
**Return value**
A
Annie_wang 已提交
7300

A
Annie_wang 已提交
7301 7302
  | Type  | Description                                                                             |
  | ------ | --------------------------------------------------------------------------------- |
A
annie_wangli 已提交
7303
  | 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 已提交
7304

A
Annie_wang 已提交
7305
**Example**
A
annie_wangli 已提交
7306

A
Annie_wang 已提交
7307
  ```ts
A
Annie_wang 已提交
7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327
  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 已提交
7328 7329 7330 7331 7332 7333
  let ret = rpc.IPCSkeleton.flushCommands(remoteObject);
  console.log("RpcServer: flushCommands result: " + ret);
  ```

### resetCallingIdentity

A
Annie_wang 已提交
7334 7335
static resetCallingIdentity(): string

A
Annie_wang 已提交
7336
Changes the UID and PID of the remote user to the UID and PID of the local user. This API is a static method. You can use it in scenarios such as identity authentication.
A
Annie_wang 已提交
7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347

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

**Return value**

  | Type  | Description                                |
  | ------ | ------------------------------------ |
  | string | String containing the UID and PID of the remote user.|

**Example**

A
Annie_wang 已提交
7348
  ```ts
A
Annie_wang 已提交
7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361
  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 已提交
7362

A
Annie_wang 已提交
7363
Changes the UID and PID of the remote user to the UID and PID of the local user. This API is a static method. You can use it in scenarios such as identity authentication.
Z
zengyawen 已提交
7364

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

A
Annie_wang 已提交
7367
**Parameters**
A
Annie_wang 已提交
7368

A
Annie_wang 已提交
7369 7370 7371
  | Name  | Type  | Mandatory| Description                                                              |
  | -------- | ------ | ---- | ------------------------------------------------------------------ |
  | identity | string | Yes  | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
Z
zengyawen 已提交
7372

A
Annie_wang 已提交
7373
**Example**
A
annie_wangli 已提交
7374

A
Annie_wang 已提交
7375
  ```ts
Z
zengyawen 已提交
7376
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7377 7378 7379 7380 7381 7382 7383 7384
      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 已提交
7385 7386 7387 7388 7389
          return true;
      }
  }
  ```

A
Annie_wang 已提交
7390 7391 7392
### setCallingIdentity<sup>(deprecated)</sup>

>This API is no longer maintained since API version 9. You are advised to use [restoreCallingIdentity](#restorecallingidentity9).
Z
zengyawen 已提交
7393

A
Annie_wang 已提交
7394
static setCallingIdentity(identity: string): boolean
Z
zengyawen 已提交
7395

A
Annie_wang 已提交
7396
Restores the UID and PID of the remote user. This API is a static method. It is usually called when the UID and PID of the remote user are required. The UID and PID of the remote user are returned by **resetCallingIdentity**.
Z
zengyawen 已提交
7397

A
annie_wangli 已提交
7398 7399
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7400
**Parameters**
A
Annie_wang 已提交
7401

A
Annie_wang 已提交
7402 7403 7404
  | Name  | Type  | Mandatory| Description                                                              |
  | -------- | ------ | ---- | ------------------------------------------------------------------ |
  | identity | string | Yes  | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
Z
zengyawen 已提交
7405

A
Annie_wang 已提交
7406
**Return value**
A
Annie_wang 已提交
7407

A
Annie_wang 已提交
7408 7409
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
7410
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
7411

A
Annie_wang 已提交
7412
**Example**
A
annie_wangli 已提交
7413

A
Annie_wang 已提交
7414
  ```ts
Z
zengyawen 已提交
7415
  class Stub extends rpc.RemoteObject {
A
Annie_wang 已提交
7416
      onRemoteMessageRequest(code, data, reply, option) {
Z
zengyawen 已提交
7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437
          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 已提交
7438 7439 7440
A constructor used to create a **RemoteObject** object.

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

A
Annie_wang 已提交
7442
**Parameters**
A
Annie_wang 已提交
7443

A
Annie_wang 已提交
7444 7445 7446
  | Name    | Type  | Mandatory| Description        |
  | ---------- | ------ | ---- | ------------ |
  | descriptor | string | Yes  | Interface descriptor.|
Z
zengyawen 已提交
7447 7448


A
Annie_wang 已提交
7449
### sendRequest<sup>(deprecated)</sup>
Z
zengyawen 已提交
7450

A
Annie_wang 已提交
7451
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
Z
zengyawen 已提交
7452

A
Annie_wang 已提交
7453
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
A
Annie_wang 已提交
7454

A
annie_wangli 已提交
7455 7456 7457
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 已提交
7458

A
Annie_wang 已提交
7459
**Parameters**
A
Annie_wang 已提交
7460

A
Annie_wang 已提交
7461 7462 7463 7464 7465 7466
  | 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 已提交
7467

A
Annie_wang 已提交
7468
**Return value**
A
Annie_wang 已提交
7469

A
Annie_wang 已提交
7470 7471
  | Type   | Description                                         |
  | ------- | --------------------------------------------- |
A
Annie_wang 已提交
7472
  | boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
Z
zengyawen 已提交
7473

A
Annie_wang 已提交
7474
**Example**
A
annie_wangli 已提交
7475

A
Annie_wang 已提交
7476
  ```ts
A
Annie_wang 已提交
7477 7478 7479 7480 7481
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
7482 7483 7484 7485
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7486 7487 7488 7489 7490 7491 7492 7493 7494
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
7495 7496 7497 7498 7499 7500 7501
  }
  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 已提交
7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512
  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 已提交
7513 7514
  ```

A
Annie_wang 已提交
7515 7516
### sendRequest<sup>8+(deprecated)</sup>

A
Annie_wang 已提交
7517
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
A
Annie_wang 已提交
7518

A
Annie_wang 已提交
7519
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
A
Annie_wang 已提交
7520

A
Annie_wang 已提交
7521 7522 7523 7524 7525
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 已提交
7526

A
Annie_wang 已提交
7527 7528 7529 7530 7531 7532
  | 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 已提交
7533 7534

**Return value**
A
Annie_wang 已提交
7535

A
Annie_wang 已提交
7536 7537
  | Type                            | Description                                         |
  | -------------------------------- | --------------------------------------------- |
A
Annie_wang 已提交
7538 7539 7540
  | Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|

**Example**
A
annie_wangli 已提交
7541

A
Annie_wang 已提交
7542
  ```ts
A
Annie_wang 已提交
7543 7544 7545 7546 7547
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
7548 7549 7550 7551
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7552 7553 7554 7555 7556 7557 7558 7559 7560
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586
  }
  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 已提交
7587
### sendMessageRequest<sup>9+</sup>
A
Annie_wang 已提交
7588

A
Annie_wang 已提交
7589
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
A
Annie_wang 已提交
7590

A
Annie_wang 已提交
7591
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 已提交
7592 7593 7594 7595

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

**Parameters**
A
Annie_wang 已提交
7596

A
Annie_wang 已提交
7597 7598 7599 7600 7601 7602
  | 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 已提交
7603 7604

**Return value**
A
Annie_wang 已提交
7605

A
Annie_wang 已提交
7606 7607 7608
  | Type                        | Description                                         |
  | ---------------------------- | --------------------------------------------- |
  | Promise&lt;RequestResult&gt; | Promise used to return the **sendRequestResult** object.|
A
Annie_wang 已提交
7609 7610 7611

**Example**

A
Annie_wang 已提交
7612
  ```ts
A
Annie_wang 已提交
7613 7614 7615 7616 7617 7618 7619
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  let option = new rpc.MessageOption();
A
Annie_wang 已提交
7620 7621
  let data = rpc.MessageSequence.create();
  let reply = rpc.MessageSequence.create();
A
Annie_wang 已提交
7622 7623
  data.writeInt(1);
  data.writeString("hello");
A
Annie_wang 已提交
7624
  testRemoteObject.sendMessageRequest(1, data, reply, option)
A
Annie_wang 已提交
7625 7626
      .then(function(result) {
          if (result.errCode === 0) {
A
Annie_wang 已提交
7627
              console.log("sendMessageRequest got result");
A
Annie_wang 已提交
7628 7629 7630 7631
              result.reply.readException();
              let msg = result.reply.readString();
              console.log("RPCTest: reply msg: " + msg);
          } else {
A
Annie_wang 已提交
7632
              console.log("RPCTest: sendMessageRequest failed, errCode: " + result.errCode);
A
Annie_wang 已提交
7633 7634
          }
      }).catch(function(e) {
A
Annie_wang 已提交
7635
          console.log("RPCTest: sendMessageRequest got exception: " + e.message);
A
Annie_wang 已提交
7636
      }).finally (() => {
A
Annie_wang 已提交
7637
          console.log("RPCTest: sendMessageRequest ends, reclaim parcel");
A
Annie_wang 已提交
7638 7639 7640 7641
          data.reclaim();
          reply.reclaim();
      });
  ```
Z
zengyawen 已提交
7642

A
Annie_wang 已提交
7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662
### 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**

A
Annie_wang 已提交
7663
  ```ts
A
Annie_wang 已提交
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
  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 已提交
7694 7695 7696

sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void

A
annie_wangli 已提交
7697 7698 7699
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 已提交
7700

A
Annie_wang 已提交
7701
**Parameters**
A
Annie_wang 已提交
7702

A
Annie_wang 已提交
7703 7704 7705 7706 7707 7708 7709
  | 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 已提交
7710

A
Annie_wang 已提交
7711
**Example**
A
annie_wangli 已提交
7712

A
Annie_wang 已提交
7713
  ```ts
A
Annie_wang 已提交
7714 7715 7716 7717 7718
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
7719 7720 7721 7722
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7723 7724 7725 7726 7727 7728 7729 7730 7731
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754
  }
  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 已提交
7755 7756
### onRemoteRequest<sup>8+(deprecated)</sup>

A
Annie_wang 已提交
7757
>This API is no longer maintained since API version 9. You are advised to use [onRemoteMessageRequest](#onremotemessagerequest9).
Z
zengyawen 已提交
7758

A
Annie_wang 已提交
7759
onRemoteRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
A
Annie_wang 已提交
7760

A
Annie_wang 已提交
7761
Provides a response to **sendMessageRequest()**. The server processes the request and returns a response in this API.
Z
zengyawen 已提交
7762

A
annie_wangli 已提交
7763 7764
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7765
**Parameters**
A
Annie_wang 已提交
7766

A
Annie_wang 已提交
7767 7768 7769 7770 7771 7772
  | 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 已提交
7773

A
Annie_wang 已提交
7774
**Return value**
A
Annie_wang 已提交
7775

A
Annie_wang 已提交
7776 7777
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
7778
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
7779

A
Annie_wang 已提交
7780
**Example**
A
annie_wangli 已提交
7781

A
Annie_wang 已提交
7782
  ```ts
A
Annie_wang 已提交
7783 7784 7785 7786 7787
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
7788 7789 7790 7791
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7792 7793 7794 7795 7796 7797 7798 7799 7800
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811
      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 已提交
7812

A
Annie_wang 已提交
7813 7814 7815
### onRemoteMessageRequest<sup>9+</sup>

onRemoteMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): boolean | Promise\<boolean>
A
Annie_wang 已提交
7816 7817

> **NOTE**<br/>
A
Annie_wang 已提交
7818 7819 7820
>
>* 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 已提交
7821

A
Annie_wang 已提交
7822
Provides a response to **sendMessageRequest()**. The server processes the request synchronously or asynchronously and returns the result in this API.
A
Annie_wang 已提交
7823 7824 7825 7826 7827

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

**Parameters**

A
Annie_wang 已提交
7828 7829 7830 7831 7832 7833
  | 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 已提交
7834 7835 7836

**Return value**

A
Annie_wang 已提交
7837 7838
  | Type             | Description                                                                                          |
  | ----------------- | ---------------------------------------------------------------------------------------------- |
A
Annie_wang 已提交
7839
  | boolean           | Returns a Boolean value if the request is processed synchronously in **onRemoteMessageRequest**. The value **true** means the operation is successful; the value **false** means the opposite.|
A
Annie_wang 已提交
7840
  | Promise\<boolean> | Returns a promise object if the request is processed asynchronously in **onRemoteMessageRequest**.                                |
A
Annie_wang 已提交
7841

A
Annie_wang 已提交
7842
**Example**: Overload **onRemoteMessageRequest** to process requests synchronously.
A
Annie_wang 已提交
7843

A
Annie_wang 已提交
7844
  ```ts
A
Annie_wang 已提交
7845 7846 7847 7848
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7849 7850

      onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7851
          if (code === 1) {
A
Annie_wang 已提交
7852
              console.log("RpcServer: sync onRemoteMessageRequest is called");
A
Annie_wang 已提交
7853 7854 7855 7856 7857 7858 7859 7860
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
  }
  ```
A
Annie_wang 已提交
7861 7862

  **Example**: Overload **onRemoteMessageRequest** to process requests asynchronously.
Z
zengyawen 已提交
7863

A
Annie_wang 已提交
7864
  ```ts
A
Annie_wang 已提交
7865 7866 7867 7868
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7869 7870

      async onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7871
          if (code === 1) {
A
Annie_wang 已提交
7872
              console.log("RpcServer: async onRemoteMessageRequest is called");
A
Annie_wang 已提交
7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
          await new Promise((resolve) => {
            setTimeout(resolve, 100);
          })
          return true;
      }
  }
  ```
A
Annie_wang 已提交
7884 7885

**Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests synchronously.
Z
zengyawen 已提交
7886

A
Annie_wang 已提交
7887
  ```ts
A
Annie_wang 已提交
7888 7889 7890 7891
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7892

A
Annie_wang 已提交
7893 7894
      onRemoteRequest(code, data, reply, option) {
          if (code === 1) {
A
Annie_wang 已提交
7895
              console.log("RpcServer: sync onRemoteMessageRequest is called");
A
Annie_wang 已提交
7896 7897 7898 7899 7900 7901
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
A
Annie_wang 已提交
7902 7903
      // Only onRemoteMessageRequest is executed.
      onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7904
          if (code === 1) {
A
Annie_wang 已提交
7905
              console.log("RpcServer: async onRemoteMessageRequest is called");
A
Annie_wang 已提交
7906 7907 7908 7909
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
A
Annie_wang 已提交
7910
         
A
Annie_wang 已提交
7911 7912 7913 7914
          return true;
      }
  }
  ```
A
Annie_wang 已提交
7915 7916

  **Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests asynchronously.
A
Annie_wang 已提交
7917

A
Annie_wang 已提交
7918
  ```ts
A
Annie_wang 已提交
7919 7920 7921 7922
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
7923

A
Annie_wang 已提交
7924 7925
      onRemoteRequest(code, data, reply, option) {
          if (code === 1) {
A
Annie_wang 已提交
7926
              console.log("RpcServer: sync onRemoteRequest is called");
A
Annie_wang 已提交
7927 7928 7929 7930 7931 7932
              return true;
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
      }
A
Annie_wang 已提交
7933 7934
      // Only onRemoteMessageRequest is executed.
      async onRemoteMessageRequest(code, data, reply, option) {
A
Annie_wang 已提交
7935
          if (code === 1) {
A
Annie_wang 已提交
7936
              console.log("RpcServer: async onRemoteMessageRequest is called");
A
Annie_wang 已提交
7937 7938 7939 7940
          } else {
              console.log("RpcServer: unknown code: " + code);
              return false;
          }
A
Annie_wang 已提交
7941
         await new Promise((resolve) => {
A
Annie_wang 已提交
7942 7943 7944 7945 7946 7947
            setTimeout(resolve, 100);
          })
          return true;
      }
  }
  ```
A
Annie_wang 已提交
7948

Z
zengyawen 已提交
7949 7950 7951 7952
### getCallingUid

getCallingUid(): number

A
annie_wangli 已提交
7953
Obtains the UID of the remote process.
Z
zengyawen 已提交
7954

A
annie_wangli 已提交
7955 7956
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
7957
**Return value**
A
Annie_wang 已提交
7958 7959
  | Type  | Description                   |
  | ------ | ----------------------- |
A
annie_wangli 已提交
7960
  | number | UID of the remote process obtained.|
Z
zengyawen 已提交
7961

A
Annie_wang 已提交
7962 7963
**Example**

A
Annie_wang 已提交
7964
  ```ts
A
Annie_wang 已提交
7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989
  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**

A
Annie_wang 已提交
7990
  ```ts
A
Annie_wang 已提交
7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003
  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

A
Annie_wang 已提交
8004
Obtains the interface descriptor.
A
Annie_wang 已提交
8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022

**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**

A
Annie_wang 已提交
8023
  ```ts
A
Annie_wang 已提交
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
  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 已提交
8069

A
Annie_wang 已提交
8070
**Example**
A
annie_wangli 已提交
8071

A
Annie_wang 已提交
8072
  ```ts
A
Annie_wang 已提交
8073 8074 8075 8076 8077
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8078 8079 8080 8081
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
8082 8083 8084 8085 8086 8087 8088 8089 8090
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
8091 8092
  }
  let testRemoteObject = new TestRemoteObject("testObject");
A
Annie_wang 已提交
8093
  let broker = testRemoteObject.queryLocalInterface("testObject");
Z
zengyawen 已提交
8094 8095
  ```

A
Annie_wang 已提交
8096
### getDescriptor<sup>9+</sup>
Z
zengyawen 已提交
8097

A
Annie_wang 已提交
8098
getDescriptor(): string
Z
zengyawen 已提交
8099

A
Annie_wang 已提交
8100
Obtains the interface descriptor of this object. The interface descriptor is a string.
Z
zengyawen 已提交
8101

A
annie_wangli 已提交
8102 8103
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8104
**Return value**
A
Annie_wang 已提交
8105

A
Annie_wang 已提交
8106 8107 8108 8109 8110
  | Type  | Description            |
  | ------ | ---------------- |
  | string | Interface descriptor obtained.|

**Error Code**
Z
zengyawen 已提交
8111

A
Annie_wang 已提交
8112 8113 8114 8115 8116
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 已提交
8117

A
Annie_wang 已提交
8118
**Example**
A
annie_wangli 已提交
8119

A
Annie_wang 已提交
8120
  ```ts
A
Annie_wang 已提交
8121 8122 8123 8124 8125
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8126 8127 8128 8129
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
8130 8131
      addDeathRecipient(recipient: MyDeathRecipient, flags: number);
      unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number);
A
Annie_wang 已提交
8132 8133 8134
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
8135 8136
  }
  let testRemoteObject = new TestRemoteObject("testObject");
A
Annie_wang 已提交
8137 8138 8139 8140 8141 8142 8143
  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 已提交
8144 8145
  ```

A
Annie_wang 已提交
8146
### getInterfaceDescriptor<sup>(deprecated)</sup>
Z
zengyawen 已提交
8147

A
Annie_wang 已提交
8148
>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
Z
zengyawen 已提交
8149

A
Annie_wang 已提交
8150
getInterfaceDescriptor(): string
A
annie_wangli 已提交
8151

A
Annie_wang 已提交
8152
Obtains the interface descriptor.
A
Annie_wang 已提交
8153

A
Annie_wang 已提交
8154
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8155

A
Annie_wang 已提交
8156
**Return value**
A
Annie_wang 已提交
8157

A
Annie_wang 已提交
8158 8159 8160
  | Type  | Description            |
  | ------ | ---------------- |
  | string | Interface descriptor obtained.|
Z
zengyawen 已提交
8161

A
Annie_wang 已提交
8162
**Example**
A
annie_wangli 已提交
8163

A
Annie_wang 已提交
8164
  ```ts
A
Annie_wang 已提交
8165 8166 8167 8168 8169
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8170 8171 8172 8173
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
      }
A
Annie_wang 已提交
8174 8175 8176 8177 8178 8179 8180 8181 8182
      addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
          return true;
      }
      isObjectDead(): boolean {
          return false;
      }
Z
zengyawen 已提交
8183 8184
  }
  let testRemoteObject = new TestRemoteObject("testObject");
A
Annie_wang 已提交
8185 8186
  let descriptor = testRemoteObject.getInterfaceDescriptor();
  console.log("RpcServer: descriptor is: " + descriptor);
Z
zengyawen 已提交
8187 8188
  ```

A
Annie_wang 已提交
8189
### modifyLocalInterface<sup>9+</sup>
Z
zengyawen 已提交
8190

A
Annie_wang 已提交
8191
modifyLocalInterface(localInterface: IRemoteBroker, descriptor: string): void
Z
zengyawen 已提交
8192

A
Annie_wang 已提交
8193
Binds an interface descriptor to an **IRemoteBroker** object.
Z
zengyawen 已提交
8194

A
annie_wangli 已提交
8195 8196
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8197
**Parameters**
A
Annie_wang 已提交
8198

A
Annie_wang 已提交
8199 8200 8201 8202
  | Name        | Type         | Mandatory| Description                                 |
  | -------------- | ------------- | ---- | ------------------------------------- |
  | localInterface | IRemoteBroker | Yes  | **IRemoteBroker** object.  |
  | descriptor     | string        | Yes  | Interface descriptor.|
Z
zengyawen 已提交
8203

A
Annie_wang 已提交
8204
**Example**
A
annie_wangli 已提交
8205

A
Annie_wang 已提交
8206
  ```ts
A
Annie_wang 已提交
8207 8208 8209 8210 8211
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8212 8213 8214
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
A
Annie_wang 已提交
8215 8216 8217 8218 8219 8220
          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 已提交
8221
      }
A
Annie_wang 已提交
8222 8223
      registerDeathRecipient(recipient: MyDeathRecipient, flags: number);
      unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number);
A
Annie_wang 已提交
8224 8225 8226
      isObjectDead(): boolean {
          return false;
      }
A
Annie_wang 已提交
8227 8228 8229
      asObject(): rpc.IRemoteObject {
          return this;
      }
Z
zengyawen 已提交
8230 8231 8232 8233
  }
  let testRemoteObject = new TestRemoteObject("testObject");
  ```

A
Annie_wang 已提交
8234
### attachLocalInterface<sup>(deprecated)</sup>
Z
zengyawen 已提交
8235

A
Annie_wang 已提交
8236
>This API is no longer maintained since API version 9. You are advised to use [modifyLocalInterface](#modifylocalinterface9).
Z
zengyawen 已提交
8237 8238 8239 8240 8241

attachLocalInterface(localInterface: IRemoteBroker, descriptor: string): void

Binds an interface descriptor to an **IRemoteBroker** object.

A
annie_wangli 已提交
8242 8243
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8244
**Parameters**
A
Annie_wang 已提交
8245

A
Annie_wang 已提交
8246 8247 8248 8249
  | Name        | Type         | Mandatory| Description                                 |
  | -------------- | ------------- | ---- | ------------------------------------- |
  | localInterface | IRemoteBroker | Yes  | **IRemoteBroker** object.  |
  | descriptor     | string        | Yes  | Interface descriptor.|
Z
zengyawen 已提交
8250

A
Annie_wang 已提交
8251
**Example**
A
annie_wangli 已提交
8252

A
Annie_wang 已提交
8253
  ```ts
A
Annie_wang 已提交
8254 8255 8256 8257 8258
  class MyDeathRecipient {
      onRemoteDied() {
          console.log("server died");
      }
  }
Z
zengyawen 已提交
8259 8260 8261 8262 8263
  class TestRemoteObject extends rpc.RemoteObject {
      constructor(descriptor) {
          super(descriptor);
          this.attachLocalInterface(this, descriptor);
      }
A
Annie_wang 已提交
8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275
      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 已提交
8276 8277 8278 8279 8280 8281 8282 8283
  }
  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 已提交
8284
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8285

A
Annie_wang 已提交
8286 8287
The table below describes the protection types of the mapped memory.

A
Annie_wang 已提交
8288 8289 8290 8291 8292 8293
  | 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 已提交
8294

A
Annie_wang 已提交
8295
### create<sup>9+</sup>
Z
zengyawen 已提交
8296

A
Annie_wang 已提交
8297
static create(name: string, size: number): Ashmem
Z
zengyawen 已提交
8298

A
Annie_wang 已提交
8299
Creates an **Ashmem** object with the specified name and size. This API is a static method.
Z
zengyawen 已提交
8300

A
annie_wangli 已提交
8301 8302
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8303
**Parameters**
A
Annie_wang 已提交
8304

A
Annie_wang 已提交
8305 8306 8307 8308
  | 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 已提交
8309

A
Annie_wang 已提交
8310
**Return value**
A
Annie_wang 已提交
8311

A
Annie_wang 已提交
8312 8313
  | Type  | Description                                          |
  | ------ | ---------------------------------------------- |
A
annie_wangli 已提交
8314
  | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
Z
zengyawen 已提交
8315

A
Annie_wang 已提交
8316 8317
**Example**

A
Annie_wang 已提交
8318
  ```ts
A
Annie_wang 已提交
8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335
  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

A
Annie_wang 已提交
8336
Creates an **Ashmem** object with the specified name and size. This API is a static method.
A
Annie_wang 已提交
8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352

**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 已提交
8353
**Example**
A
annie_wangli 已提交
8354

A
Annie_wang 已提交
8355
  ```ts
Z
zengyawen 已提交
8356 8357 8358 8359 8360
  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 已提交
8361
### create<sup>9+</sup>
Z
zengyawen 已提交
8362

A
Annie_wang 已提交
8363
static create(ashmem: Ashmem): Ashmem
Z
zengyawen 已提交
8364

A
Annie_wang 已提交
8365
Creates an **Ashmem** object by copying the file descriptor of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
A
annie_wangli 已提交
8366 8367

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

A
Annie_wang 已提交
8369
**Parameters**
A
Annie_wang 已提交
8370

A
Annie_wang 已提交
8371 8372 8373
  | Name| Type  | Mandatory| Description                |
  | ------ | ------ | ---- | -------------------- |
  | ashmem | Ashmem | Yes  | Existing **Ashmem** object.|
Z
zengyawen 已提交
8374

A
Annie_wang 已提交
8375
**Return value**
A
Annie_wang 已提交
8376

A
Annie_wang 已提交
8377 8378
  | Type  | Description                  |
  | ------ | ---------------------- |
A
annie_wangli 已提交
8379
  | Ashmem | **Ashmem** object created.|
Z
zengyawen 已提交
8380 8381


A
Annie_wang 已提交
8382 8383
**Example**

A
Annie_wang 已提交
8384
  ```ts
A
Annie_wang 已提交
8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402
  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

A
Annie_wang 已提交
8403
Creates an **Ashmem** object by copying the file descriptor of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
A
Annie_wang 已提交
8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418

**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 已提交
8419
**Example**
A
annie_wangli 已提交
8420

A
Annie_wang 已提交
8421
  ```ts
Z
zengyawen 已提交
8422 8423 8424 8425 8426 8427
  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 已提交
8428
### closeAshmem<sup>8+</sup>
Z
zengyawen 已提交
8429 8430 8431 8432 8433

closeAshmem(): void

Closes this **Ashmem** object.

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

A
Annie_wang 已提交
8436
**Example**
A
annie_wangli 已提交
8437

A
Annie_wang 已提交
8438
  ```ts
A
Annie_wang 已提交
8439
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
Z
zengyawen 已提交
8440 8441 8442
  ashmem.closeAshmem();
  ```

A
annie_wangli 已提交
8443
### unmapAshmem<sup>8+</sup>
Z
zengyawen 已提交
8444 8445 8446 8447 8448

unmapAshmem(): void

Deletes the mappings for the specified address range of this **Ashmem** object.

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

A
Annie_wang 已提交
8451
**Example**
A
annie_wangli 已提交
8452

A
Annie_wang 已提交
8453
  ```ts
A
Annie_wang 已提交
8454
  let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
Z
zengyawen 已提交
8455 8456 8457
  ashmem.unmapAshmem();
  ```

A
annie_wangli 已提交
8458
### getAshmemSize<sup>8+</sup>
Z
zengyawen 已提交
8459 8460 8461 8462 8463

getAshmemSize(): number

Obtains the memory size of this **Ashmem** object.

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

A
Annie_wang 已提交
8466
**Return value**
A
Annie_wang 已提交
8467

A
Annie_wang 已提交
8468 8469
  | Type  | Description                      |
  | ------ | -------------------------- |
A
annie_wangli 已提交
8470
  | number | **Ashmem** size obtained.|
Z
zengyawen 已提交
8471

A
Annie_wang 已提交
8472
**Example**
A
annie_wangli 已提交
8473

A
Annie_wang 已提交
8474
  ```ts
Z
zengyawen 已提交
8475 8476 8477 8478 8479
  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 已提交
8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503
### 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**

A
Annie_wang 已提交
8504
  ```ts
A
Annie_wang 已提交
8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516
  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 已提交
8517 8518 8519 8520 8521

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 已提交
8522
**System capability**: SystemCapability.Communication.IPC.Core
Z
zengyawen 已提交
8523

A
Annie_wang 已提交
8524
**Parameters**
A
Annie_wang 已提交
8525

A
Annie_wang 已提交
8526 8527 8528
  | Name | Type  | Mandatory| Description                          |
  | ------- | ------ | ---- | ------------------------------ |
  | mapType | number | Yes  | Protection level of the memory region to which the shared file is mapped.|
Z
zengyawen 已提交
8529

A
Annie_wang 已提交
8530
**Return value**
A
Annie_wang 已提交
8531

A
Annie_wang 已提交
8532 8533
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
Annie_wang 已提交
8534
  | boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
Z
zengyawen 已提交
8535

A
Annie_wang 已提交
8536
**Example**
A
annie_wangli 已提交
8537

A
Annie_wang 已提交
8538
  ```ts
Z
zengyawen 已提交
8539
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
A
Annie_wang 已提交
8540
  let mapReadAndWrite = ashmem.mapAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
Z
zengyawen 已提交
8541 8542 8543
  console.log("RpcTest: map ashmem result is  : " + mapReadAndWrite);
  ```

A
Annie_wang 已提交
8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561
### 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**

A
Annie_wang 已提交
8562
  ```ts
A
Annie_wang 已提交
8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574
  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 已提交
8575 8576 8577 8578 8579

mapReadAndWriteAshmem(): boolean

Maps the shared file to the readable and writable virtual address space of the process.

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

A
Annie_wang 已提交
8582
**Return value**
A
Annie_wang 已提交
8583

A
Annie_wang 已提交
8584 8585
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
Annie_wang 已提交
8586
  | boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
Z
zengyawen 已提交
8587

A
Annie_wang 已提交
8588
**Example**
A
annie_wangli 已提交
8589

A
Annie_wang 已提交
8590
  ```ts
Z
zengyawen 已提交
8591 8592 8593 8594 8595
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
  let mapResult = ashmem.mapReadAndWriteAshmem();
  console.log("RpcTest: map ashmem result is  : " + mapResult);
  ```

A
Annie_wang 已提交
8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613
### 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**

A
Annie_wang 已提交
8614
  ```ts
A
Annie_wang 已提交
8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626
  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 已提交
8627 8628 8629 8630 8631

mapReadOnlyAshmem(): boolean

Maps the shared file to the read-only virtual address space of the process.

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

A
Annie_wang 已提交
8634
**Return value**
A
Annie_wang 已提交
8635

A
Annie_wang 已提交
8636 8637
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
Annie_wang 已提交
8638
  | boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
Z
zengyawen 已提交
8639

A
Annie_wang 已提交
8640
**Example**
A
annie_wangli 已提交
8641

A
Annie_wang 已提交
8642
  ```ts
Z
zengyawen 已提交
8643 8644 8645 8646 8647
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
  let mapResult = ashmem.mapReadOnlyAshmem();
  console.log("RpcTest: Ashmem mapReadOnlyAshmem result is : " + mapResult);
  ```

A
Annie_wang 已提交
8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671
### 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**

A
Annie_wang 已提交
8672
  ```ts
A
Annie_wang 已提交
8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684
  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 已提交
8685 8686 8687 8688 8689

setProtection(protectionType: number): boolean

Sets the protection level of the memory region to which the shared file is mapped.

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

A
Annie_wang 已提交
8692
**Parameters**
A
Annie_wang 已提交
8693

A
Annie_wang 已提交
8694 8695 8696
  | Name        | Type  | Mandatory| Description              |
  | -------------- | ------ | ---- | ------------------ |
  | protectionType | number | Yes  | Protection type to set.|
Z
zengyawen 已提交
8697

A
Annie_wang 已提交
8698
**Return value**
A
Annie_wang 已提交
8699

A
Annie_wang 已提交
8700 8701
  | Type   | Description                                     |
  | ------- | ----------------------------------------- |
A
annie_wangli 已提交
8702
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
8703

A
Annie_wang 已提交
8704
**Example**
A
annie_wangli 已提交
8705

A
Annie_wang 已提交
8706
  ```ts
Z
zengyawen 已提交
8707
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
A
Annie_wang 已提交
8708
  let result = ashmem.setProtection(ashmem.PROT_READ);
Z
zengyawen 已提交
8709 8710 8711
  console.log("RpcTest: Ashmem setProtection result is : " + result);
  ```

A
Annie_wang 已提交
8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737
### 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**

A
Annie_wang 已提交
8738
  ```ts
A
Annie_wang 已提交
8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752
  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 已提交
8753 8754 8755 8756 8757

writeToAshmem(buf: number[], size: number, offset: number): boolean

Writes data to the shared file associated with this **Ashmem** object.

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

A
Annie_wang 已提交
8760
**Parameters**
A
Annie_wang 已提交
8761

A
Annie_wang 已提交
8762 8763 8764 8765 8766
  | 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 已提交
8767

A
Annie_wang 已提交
8768
**Return value**
A
Annie_wang 已提交
8769

A
Annie_wang 已提交
8770 8771
  | Type   | Description                                                                                     |
  | ------- | ----------------------------------------------------------------------------------------- |
A
Annie_wang 已提交
8772
  | boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
Z
zengyawen 已提交
8773

A
Annie_wang 已提交
8774
**Example**
A
annie_wangli 已提交
8775

A
Annie_wang 已提交
8776
  ```ts
Z
zengyawen 已提交
8777
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
A
Annie_wang 已提交
8778 8779 8780
  let mapResult = ashmem.mapReadAndWriteAshmem();
  console.info("RpcTest map ashmem result is " + mapResult);
  var ByteArrayVar = [1, 2, 3, 4, 5];
Z
zengyawen 已提交
8781 8782 8783 8784
  let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
  console.log("RpcTest: write to Ashmem result is  : " + writeResult);
  ```

A
Annie_wang 已提交
8785
### readAshmem<sup>9+</sup>
Z
zengyawen 已提交
8786

A
Annie_wang 已提交
8787
readAshmem(size: number, offset: number): number[]
Z
zengyawen 已提交
8788 8789 8790

Reads data from the shared file associated with this **Ashmem** object.

A
annie_wangli 已提交
8791 8792
**System capability**: SystemCapability.Communication.IPC.Core

A
Annie_wang 已提交
8793
**Parameters**
A
Annie_wang 已提交
8794

A
Annie_wang 已提交
8795 8796 8797 8798
  | 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 已提交
8799

A
Annie_wang 已提交
8800
**Return value**
A
Annie_wang 已提交
8801

A
Annie_wang 已提交
8802 8803
  | Type    | Description            |
  | -------- | ---------------- |
A
annie_wangli 已提交
8804
  | number[] | Data read.|
Z
zengyawen 已提交
8805

A
Annie_wang 已提交
8806 8807 8808 8809 8810 8811 8812
**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 已提交
8813

A
Annie_wang 已提交
8814
**Example**
A
annie_wangli 已提交
8815

A
Annie_wang 已提交
8816
  ```ts
A
Annie_wang 已提交
8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854
  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**

A
Annie_wang 已提交
8855
 ```ts
Z
zengyawen 已提交
8856
  let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
A
Annie_wang 已提交
8857 8858 8859
  let mapResult = ashmem.mapReadAndWriteAshmem();
  console.info("RpcTest map ashmem result is " + mapResult);
  var ByteArrayVar = [1, 2, 3, 4, 5];
Z
zengyawen 已提交
8860 8861 8862 8863
  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);
A
Annie_wang 已提交
8864 8865
 ```