> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
A **Buffer** object represents a byte sequence of a fixed length. It is used to store binary data.
You can use the APIs provided by the **Buffer** module to process images and a large amount of binary data, receive and upload files, and use network protocols.
| buf1 | Buffer \| Uint8Array | Yes| **Buffer** instance to compare.|
| buf2 | Buffer \| Uint8Array | Yes| **Buffer** instance to compare.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if **buf1** is the same as **buf2**.<br>Returns **1** if **buf1** comes after **buf2** when sorted.<br>Returns **-1** if **buf1** comes before **buf2** when sorted.|
| arrayBuffer | ArrayBuffer \| SharedArrayBuffer | Yes| Array of **Buffer** instances, whose memory is to be shared.|
| byteOffset | number | No| Byte offset. The default value is **0**.|
| length | number | No| Length of the **Buffer** instance to create, in bytes. The default value is the length of **arrayBuffer** minus **byteOffset**.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance with shared memory.|
**Example**
```ts
importbufferfrom'@ohos.buffer';
letab=newArrayBuffer(10);
letbuf=buffer.from(ab,0,2);
```
### from
from(data: Buffer | Uint8Array): Buffer
Creates a **Buffer** instance with the copy of another instance.
| targetStart | number | No| Offset to the start of the data to compare in the target **Buffer** instance. The default value is **0**.|
| targetEnd | number | No| Offset to the end of the data to compare in the target **Buffer** instance (not inclusive). The default value is length of the target **Buffer** instance.|
| sourceStart | number | No| Offset to the start of the data to compare in this **Buffer** instance. The default value is **0**.|
| sourceEnd | number | No| Offset to the end of the data to compare in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the two **Buffer** instances are the same.<br>Returns **1** if the target instance comes before this instance when sorted.<br>Returns **-1** if the target instance comes after this instance when sorted.|
| target | Buffer \| Uint8Array | Yes| Instance to which data is copied.|
| targetStart | number | No| Offset to the start position in the target instance where data is copied. The default value is **0**.|
| sourceStart | number | No| Offset to the start position in this **Buffer** instance where data is copied. The default value is **0**.|
| sourceEnd | number | No| Offset to the end position in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Total length of the data copied, in bytes.|
| value | string \| Buffer \| Uint8Array \| number | Yes| Value to fill.|
| offset | number | No| Offset to the start position in this **Buffer** instance where data is filled. The default value is **0**.|
| end | number | No| Offset to the end position in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
| encoding | BufferEncoding | No| Encoding format (valid only when **value** is a string). The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance filled with the specified value.|
| value | string \| number \| Buffer \| Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before checking data. If the offset is a negative number, data is searched from the end of the **Buffer** instance. The default value is **0**.|
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the instance contains the specified value; returns **false** otherwise.|
**Example**
```ts
importbufferfrom'@ohos.buffer';
letbuf=buffer.from('this is a buffer');
console.log(buf.includes('this'));// Print: true
console.log(buf.includes('be'));// Print: false
```
### indexOf
indexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number
Obtains the index of the first occurrence of the specified value in this **Buffer** instance.
| value | string \| number \| Buffer \| Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before checking data. If the offset is a negative number, data is searched from the end of the **Buffer** instance. The default value is **0**.|
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Index obtained. <br>If **-1** is returned, the **Buffer** instance does not contain the specified value.|
**Example**
```ts
importbufferfrom'@ohos.buffer';
letbuf=buffer.from('this is a buffer');
console.log(buf.indexOf('this'));// Print: 0
console.log(buf.indexOf('is'));// Print: 2
```
### keys
keys(): IterableIterator<number>
Creates and returns an iterator that contains the keys of this **Buffer** instance.
| value | string \| number \| Buffer \| Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before checking data. If the offset is a negative number, data is searched from the end of the **Buffer** instance. The default value is **0**.|
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Index obtained.<br>If **-1** is returned, the **Buffer** instance does not contain the specified value.|
readIntBE(offset: number, byteLength: number): number
Reads the specified number of bytes from this **Buffer** instance at the specified offset, and interprets the result as a big-endian, two's complement signed value that supports up to 48 bits of precision.
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
| byteLength | number | No| Number of bytes to read.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Data read.|
**Example**
```ts
importbufferfrom'@ohos.buffer';
letbuf=Buffer.from("ab");
letnum=buf.readIntBE(0,1);
console.log(num);// 97
```
### readIntLE
readIntLE(offset: number, byteLength: number): number
Reads the specified number of bytes from this **Buffer** instance at the specified offset and interprets the result as a little-endian, two's complement signed value that supports up to 48 bits of precision.
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | An unsigned, little-endian 32-bit integer.|
**Example**
```ts
importbufferfrom'@ohos.buffer';
letbuf=buffer.from([0x12,0x34,0x56,0x78]);
console.log(buf.readUInt32LE(0).toString(16));
```
### readUIntBE
readUIntBE(offset: number, byteLength: number): number
Reads the specified number of bytes from this **Buffer** instance at the specified offset, and interprets the result as an unsigned, big-endian integer that supports up to 48 bits of precision.
readUIntLE(offset: number, byteLength: number): number
Reads the specified number of bytes from this **Buffer** instance at the specified offset, and interprets the result as an unsigned, little-endian integer that supports up to 48 bits of precision.
| start | number | No| Offset to the start position in this **Buffer** instance where data is truncated. The default value is **0**.|
| end | number | No| Offset to the end position in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
| sources | string[] \| ArrayBuffer[] \| TypedArray[] \| DataView[] \| Blob[] | Yes| Data sources of the **Blob** instance.|
| options | Object | No| options:<br>- **endings**: 'transparent' or 'native'.<br>- **type**: type of the data in **Blob**.|
| file | string | Yes | Name of the database. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is the error object. |
| file | string | Yes | Name of the database file. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
| files | Array<string> | Yes | Name of the backup file to delete. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants). |
| callback | AsyncCallback<Array<[string, number]>> | Yes | Callback invoked to return the name of the backup file deleted and the operation result. |
Obtains a **KvStoreResultSet** object that matches the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
Obtains a **KvStoreResultSet** object that matches the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
@@ -8,7 +8,7 @@ The motion recognition module provides motion recognition and control capabiliti
...
@@ -8,7 +8,7 @@ The motion recognition module provides motion recognition and control capabiliti
The motion recognition driver is developed based on the hardware driver foundation (HDF). It shields hardware differences and provides APIs for the Multimodal Sensor Data Platform (MSDP) to implement capabilities such as enabling or disabling motion recognition, and subscribing to or unsubscribing from motion recognition data.
The motion recognition driver is developed based on the hardware driver foundation (HDF). It shields hardware differences and provides APIs for the Multimodal Sensor Data Platform (MSDP) to implement capabilities such as enabling or disabling motion recognition, and subscribing to or unsubscribing from motion recognition data.
The figure below shows the motion recognition driver architecture. The framework layer provides MSDP services, and interacts with the Motion Hardware Device Interface (HDI) Server through the Motion HDI Client. The Motion HDI Server calls the Motion HDI Impl APIs to provide motion recognition capabilities for upper-layer services.
The figure below shows the motion recognition driver architecture. The framework layer provides MSDP services, and interacts with the Motion Stub through the Motion Proxy in the User Hardware Driver Foundation (UHDF). The Motion Stub calls the Motion HDI Impl APIs to provide motion recognition capabilities for upper-layer services.
@@ -22,7 +22,7 @@ The figure below illustrates how a motion recognition driver works.
...
@@ -22,7 +22,7 @@ The figure below illustrates how a motion recognition driver works.
![](figures/motion_recognition_driver_work.png)
![](figures/motion_recognition_driver_work.png)
1. MSDP: The MSDP service obtains a Motion HDI service instance from the Motion Proxy at the IDL and calls the Motion HDI API.
1. MSDP: The MSDP service obtains a Motion HDI service instance from the Motion Proxy and calls the Motion HDI API.
2. IDL: The IService Manager allocates a Motion HDI instance requested by the MSDP service, and the Motion Proxy forwards the instance to the MSDP service. After the MSDP service calls the HDI API provided by the Motion Proxy, Motion Stub is called through Inter-Process Communication (IPC) to invoke the Motion Service API. The code is automatically generated by a tool and does not need to be developed by the component vendor.
2. IDL: The IService Manager allocates a Motion HDI instance requested by the MSDP service, and the Motion Proxy forwards the instance to the MSDP service. After the MSDP service calls the HDI API provided by the Motion Proxy, Motion Stub is called through Inter-Process Communication (IPC) to invoke the Motion Service API. The code is automatically generated by a tool and does not need to be developed by the component vendor.
3. HDI Service: HDI Service consists of Motion Interface Driver, Motion Service, and Motion Impl. Motion Interface Driver provides the motion recognition driver code. A **HdfDriverEntry** structure is defined to implement the **Init**, **Bind**, and **Release** functions. The **HDF_INIT** macro is used to load the driver in the functions. Motion Service provides the motion recognition service interface class. The specific implementation is described in Motion Impl. The code of HDI Service must be developed by the component vendor.
3. HDI Service: HDI Service consists of Motion Interface Driver, Motion Service, and Motion Impl. Motion Interface Driver provides the motion recognition driver code. A **HdfDriverEntry** structure is defined to implement the **Init**, **Bind**, and **Release** functions. The **HDF_INIT** macro is used to load the driver in the functions. Motion Service provides the motion recognition service interface class. The specific implementation is described in Motion Impl. The code of HDI Service must be developed by the component vendor.