Data transmission method, electronic equipment, chip system and storage medium
By writing and reading data in the target shared memory space, combined with direct operations of the JavaScript engine and NAPI components, the problem of low efficiency in data transfer from the web front-end to the native side is solved, achieving more efficient data transfer.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2026-03-27
AI Technical Summary
In the process of passing data from the web front-end to the native side, the data transfer efficiency is low due to multiple type conversions in the programming language.
The JavaScript engine writes the data to be transmitted into the target shared memory space, and the NAPI component reads and converts the data directly from this space, avoiding multiple programming language conversions.
It simplifies the data transmission process, reduces time consumption, and improves data transmission efficiency and accuracy.
Smart Images

Figure CN121742845A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminals, and more particularly to a data transmission method, electronic device, chip system, and storage medium. Background Technology
[0002] For some applications developed based on the web (world wide web) front-end, the process of transferring data from the web front-end (referred to as the web end) to the native end often involves multiple type conversions due to the characteristics of the web end's development language or framework. These type conversions consume a lot of time, thereby reducing the efficiency of data transfer. Summary of the Invention
[0003] This application provides a data transmission method, electronic device, chip system, and storage medium that can reduce the time spent in the data transmission process and improve data transmission efficiency.
[0004] Firstly, a data transfer method is provided, comprising: obtaining first data to be transferred through a JavaScript engine, wherein the first data to be transferred is determined by user interaction behavior or automatic triggering mechanism on a web page; writing the first data to be transferred into a target shared memory space through the JavaScript engine, wherein the target shared memory space is used to store data of a first type, and the type of the first data to be transferred belongs to the first type; reading the first data to be transferred from the target shared memory space through the operating system's native application programming interface (NAPI) component, and converting the type of the first data to be transferred into a corresponding second type to obtain target data; and transferring the target data to a native end through the NAPI component, wherein the native end is used to handle the application's user interface and business logic; the user interface includes a web page.
[0005] This method can be executed by an electronic device, or by a module (such as a processor, chip, or chip system) in the electronic device, or by a logic module or software that can implement all or part of the functions of the electronic device.
[0006] The above solution allows the NAPI component to directly obtain the first data to be transmitted through the target shared memory space, eliminating the need for multiple type conversions in the programming language to pass the first data to be transmitted to the NAPI component, as is required in related technologies. This simplifies the data transmission process, reduces the time consumed in the data transmission process, and improves data transmission efficiency.
[0007] For example, the JavaScript engine is the V8 engine, and the first data to be transmitted can be a V8 Value object of type first.
[0008] For example, the Native side is the ETS layer, which can also be called the ArkTS layer.
[0009] In one possible implementation, the first type includes one or more of the following: Boolean type, 8-bit unsigned integer, 8-bit signed integer, 16-bit unsigned integer, 16-bit signed integer, 32-bit unsigned integer, 32-bit signed integer, 64-bit unsigned integer, 64-bit signed integer, 32-bit floating-point type, 64-bit floating-point type, string, or binary data.
[0010] For example, the target shared memory space can specifically be a memory region used to cache data when processing streaming data, which can be represented by a flowbuffer.
[0011] In one possible implementation, the target shared memory space is configured with a header field and at least one data field. The first data to be transmitted is written into the target shared memory space through a JavaScript engine, including: calling a write interface corresponding to the type of the first data to be transmitted through the JavaScript engine, and writing the attribute information of the first data to be transmitted into the header field through the write interface, the attribute information including the type of the first data to be transmitted; and writing the first data to be transmitted into the corresponding data field of at least one data field through the write interface.
[0012] The header field can be represented as the Header field, and the data field can be represented as the data field.
[0013] The above solution, through the JavaScript engine, can automatically write the attribute information containing the type of the first piece of data to be transmitted into the header field of the target shared memory space by calling the corresponding write interface based on the type of the first piece of data to be transmitted. This allows for subsequent processing of the first piece of data to be transmitted based on the attribute information. Simultaneously, the first piece of data to be transmitted is also written into the corresponding data field. This process improves the accuracy and reliability of data transmission.
[0014] In one possible implementation, the first data to be transmitted is written to the corresponding data field of at least one data field through the write interface, including: writing the first data to be transmitted to the corresponding data field of at least one data field based on the write position information corresponding to the first data to be transmitted through the write interface, wherein the write position information indicates the starting write position of the first data to be transmitted.
[0015] The above solution ensures that data is accurately stored in the designated location, avoiding the risk of data misplacement or loss, and further improving the accuracy and reliability of data transmission.
[0016] In one possible implementation, the attribute information also includes the index of the first data to be transmitted in the initial data to be transmitted and the length of the first data to be transmitted.
[0017] Optionally, if the number of the first data to be transmitted is one, this attribute information can be the type of the first data to be transmitted.
[0018] For example, the target shared memory space contains only one first piece of data to be transmitted.
[0019] Optionally, if there are multiple types of the first data to be transmitted, the attribute information can be the type of the first data to be transmitted, the index of the first data to be transmitted in the initial data to be transmitted, and the length of the first data to be transmitted.
[0020] In one possible implementation, obtaining the first data to be transmitted via a JavaScript engine includes: obtaining the initial data to be transmitted via a JavaScript engine; and, if the initial data to be transmitted contains data of the first type, using the data of the first type as the first data to be transmitted via a JavaScript engine.
[0021] In one possible implementation, the first data to be transmitted is read from the target shared memory space using the operating system's NAPI component, and the type of the first data to be transmitted is converted to a corresponding second type to obtain the target data. This includes: calling a read interface for reading data from the target shared memory space through the NAPI component, and reading attribute information of the first data to be transmitted from the header field configured in the target shared memory space through the read interface. The attribute information includes the type of the first data to be transmitted, the index of the first data to be transmitted in the initial data to be transmitted, and the length of the first data to be transmitted; reading the first data to be transmitted from the data field configured in the target shared memory space based on the starting write position and length of the first data to be transmitted through the read interface; converting the type of the first data to be transmitted to the corresponding second type through the read interface to obtain the converted first data to be transmitted; and determining the target data based on the converted first data to be transmitted and the index of the first data to be transmitted in the initial data to be transmitted through the NAPI component.
[0022] The above solution enables the first data to be transferred to the NAPI component via shared memory. The NAPI component can then read the first data from the target shared memory space through a read interface and perform type conversion to obtain the converted first data. This eliminates the need to pass the first data to the NAPI component through multiple data transfer layers, as is done in related technologies, simplifying the data transfer process, reducing the time consumed in the data transfer process, and improving data transfer efficiency.
[0023] In one possible implementation, the initial data to be transmitted is data of the first type. The target data is determined by the NAPI component based on the transformed first data to be transmitted and the index of the first data to be transmitted in the initial data to be transmitted. This includes: sorting the multiple transformed first data to be transmitted corresponding to the multiple first data to be transmitted based on the index of the multiple first data to be transmitted in the initial data to be transmitted by the NAPI component to obtain the target data.
[0024] In one possible implementation, the initial data to be transmitted contains data of a type other than the first type. The method further includes: using a JavaScript engine, taking the data of a type other than the first type in the initial data to be transmitted as the second data to be transmitted, and passing the second data to be transmitted sequentially through multiple data transmission layers to the NAPI component; and using the NAPI component to perform type conversion on the data passed through the multiple data transmission layers to obtain the third data.
[0025] In one possible implementation, the target data is determined by using the NAPI component based on the transformed first data to be transmitted and the index of the first data to be transmitted in the initial data to be transmitted. This includes: using the NAPI component, sorting and concatenating the transformed first data to be transmitted and the third data based on the index of the first data to be transmitted in the initial data to be transmitted and the index of the second data to be transmitted in the initial data to be transmitted to obtain the target data.
[0026] The above scheme enables the transfer of the first piece of data to the NAPI component via shared memory, and the transfer of the second piece of data to the NAPI component via multiple data transfer layers. Subsequently, the NAPI component performs type conversion on both pieces of data and concatenates the converted data to obtain the complete corresponding C++ type data (i.e., the target data). This ensures data integrity during the transfer process, and because only a portion of the data (i.e., the second piece of data) is transferred through multiple data transfer layers, the time consumed in the data transfer process is reduced compared to transferring all data through multiple layers, thus improving data transfer efficiency.
[0027] In one possible implementation, the JavaScript engine calls the target interface for requesting shared memory space, and then requests the target shared memory space through the target interface.
[0028] In one possible implementation, a destructor function is called via a read interface used to read data from the target shared memory space to clear the target data or release the target shared memory space.
[0029] The above solution, by automatically calling the destructor, ensures that the resources occupied by the target data, the first data to be transmitted, or the target shared memory space are no longer needed, thereby improving the stability and performance of the system.
[0030] In a second aspect, embodiments of this application provide an electronic device, which includes a processor and a memory. The memory is used to store a computer program, and the processor is used to call and run the computer program from the memory, causing the electronic device to perform any of the methods in the first aspect.
[0031] Thirdly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to perform any of the methods in the first aspect.
[0032] Fourthly, embodiments of this application provide a computer program product, which includes computer program code that, when executed by an electronic device, causes the electronic device to perform any of the methods in the first aspect.
[0033] Fifthly, embodiments of this application provide a chip system, which includes a processing circuit and a storage medium storing computer program instructions; when the computer program instructions are executed by the processing circuit, they implement any of the methods in the first aspect.
[0034] Optionally, the processing circuitry in the above-mentioned chip system can be replaced by a processor, and the storage medium can be replaced by a memory. Optionally, the chip system may also include a communication interface for enabling communication between the chip system and external devices.
[0035] The beneficial effects of the technical solutions in the second to fifth aspects of this application can be referred to the beneficial effects of the technical solutions in the first aspect, and will not be repeated here. Attached Figure Description
[0036] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;
[0037] Figure 2 This is a software structure block diagram of the electronic device 100 according to an embodiment of this application;
[0038] Figure 3 This is a schematic diagram illustrating the process of transferring data from the web client to the native client in related technologies.
[0039] Figure 4 A flowchart illustrating a data transmission method provided in an embodiment of this application;
[0040] Figure 5A flowchart illustrating another data transmission method provided in an embodiment of this application;
[0041] Figure 6 A schematic diagram of a web page in a data transmission method provided in an embodiment of this application;
[0042] Figure 7 This is a schematic diagram of the data memory layout of the target shared memory space in a data transfer method provided in an embodiment of this application;
[0043] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0044] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0045] In the description of the embodiments of this application, unless otherwise stated, " / " means "or"; for example, A / B can mean A or B; "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist; for example, A and / or B can mean: A exists alone, A and B exist simultaneously, or B exists alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more.
[0046] Hereinafter, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include one or more of that feature.
[0047] This application provides an electronic device for executing the data transmission method provided in this application. In some embodiments of this application, the electronic device may be a mobile phone, tablet computer, wearable device, in-vehicle device, augmented reality (AR) / virtual reality (VR) device, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc., or may be other devices or apparatuses capable of data transmission. This application does not limit the specific type of electronic device.
[0048] For example, Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0049] like Figure 1 As shown, the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0050] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0051] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0052] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0053] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0054] The processor 110 and the display screen 194 communicate via a DSI interface to realize the display function of the electronic device 100.
[0055] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.
[0056] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Figure 1 The structures of antennas 1 and 2 shown are merely one example. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with a tuning switch.
[0057] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0058] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Mini LED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.
[0059] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.
[0060] The pressure sensor 180A is used to sense pressure signals and can convert the pressure signals into electrical signals. In some embodiments, the pressure sensor 180A may be disposed on the display screen 194.
[0061] Touch sensor 180K, also known as "touch panel". Touch sensor 180K can be set on display screen 194. Touch sensor 180K and display screen 194 together form touch screen, also known as "touch screen".
[0062] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. Electronic device 100 can receive button input and generate key signal inputs related to user settings and function control of electronic device 100.
[0063] The software system of electronic device 100 can adopt a layered architecture. This application uses the Harmony operating system as an example to illustrate the software architecture of electronic device 100. It should be understood that the solution provided in this application can also be applied to other types of operating systems such as Android, Apple, and Windows.
[0064] Figure 2 This is a schematic diagram of the software structure of the electronic device 100 according to an embodiment of this application.
[0065] In some implementations, the Harmony system comprises four layers, from bottom to top: the kernel layer, the system basic services layer, the framework layer, and the application layer.
[0066] The Harmony system employs a multi-kernel design, optionally including the Linux kernel, the Harmony microkernel, and the lightweight IoT operating system kernel (LiteOS). This design allows devices with varying capabilities to choose the appropriate system kernel. The kernel layer also includes a kernel abstraction layer, providing foundational kernel capabilities to other Harmony layers, such as process management, thread management, memory management, file system management, network management, and peripheral device management.
[0067] The system's basic service layer is the core capability set of the Harmony system, enabling it to provide application services through a framework layer in multi-device deployment scenarios. This layer may optionally include the following components:
[0068] The system's basic capability subsystems provide fundamental capabilities for the operation, scheduling, and migration of distributed applications across multiple devices within the Harmony system. These subsystems comprise a distributed soft bus, distributed data management and file management, distributed task scheduling, the Ark runtime, and distributed security and privacy protection. The Ark runtime provides runtime environments for multiple languages (C / C++ / JavaScript) and basic system libraries. It also provides a runtime environment for Java programs statically generated using the Ark compiler (i.e., the parts of the application or framework layer developed using the Java language).
[0069] The basic software service subsystem suite provides common and general software services for the Harmony system. It comprises subsystems such as graphics and image processing, distributed media, distributed AI, multimodal input, mobile sensing development platform (MSDP) & device virtualization (DV), event notification, telephony services, and design for X (DFX) for non-functional product attributes. Each subsystem can be tailored to the functional granularity required for deployment in different device configurations.
[0070] Enhanced software service subsystem set (see) Figure 2The enhanced software portion (highlighted by the dashed line) provides differentiated capability enhancement software services for the Harmony system across various devices. It comprises subsystems such as tablet business software, smart screen business software, in-vehicle system business software, and Internet of Things (IoT) business software. This set of enhanced software service subsystems can be tailored to the deployment environment of different device types, with each subsystem further tailored to its functional granularity.
[0071] Harmony Driver Foundation (HDF) and Hardware Abstraction Layer (HAL) form the foundation for the open hardware ecosystem of the Harmony system. HDF provides hardware capability abstraction to the hardware and provides a development framework and runtime environment for various peripheral drivers to the hardware.
[0072] Hardware Service Subsystem Set: Provides common and adaptable hardware services for the Harmony system, consisting of hardware service subsystems such as general sensor, location, power, USB, and biometrics. The Hardware Service Subsystem Set can be tailored to the deployment environment of different device types, with each subsystem allowing for functional customization.
[0073] Proprietary hardware service subsystem (see) Figure 2 The proprietary hardware component (highlighted by the dashed line) provides differentiated hardware services for different devices within the Harmony system. Optional subsystems include proprietary hardware services for tablets, in-vehicle systems, wearables, and IoT devices. These proprietary hardware service subsystems can be tailored at the subsystem level, and each subsystem can be tailored at the functional level.
[0074] The framework layer provides Harmony system applications with multi-language user program frameworks and meta-capability frameworks in languages such as Java, C, C++, and JavaScript, as well as multi-language framework application programming interfaces (APIs) for various software and hardware services.
[0075] The application layer includes system applications and third-party applications (or extended applications), which can include applications such as camera, gallery, calendar, calling, drawing applications, navigation, WLAN, music, video, and SMS. Applications in the Harmony system are built upon atomic capabilities (AA) and feature capabilities (FA).
[0076] The following is an explanation of the relevant technical terms used in this application.
[0077] Hypertext Markup Language (HTML) is a standard markup language used to create web pages and web applications. It uses a series of elements and tags to build the structure and content of a web page. These elements and tags indicate how to display various content on a web page, such as text, images, videos, links, tables, lists, etc.
[0078] The Web (World Wide Web), also known as the World Wide Web, is a global, dynamic, interactive, cross-platform, distributed graphical information system based on Hypertext and the Hypertext Transfer Protocol (HTTP). Relying on the Internet, a global computer network, it provides users with a graphical, intuitive, and easily accessible interface, enabling them to conveniently find, browse, and interact with various information resources on the Internet.
[0079] JavaScript Bridge (JSB) is a technology used to connect different technology platforms and languages. Specifically, it allows interaction between the web client and the native client.
[0080] For example, the native and web sides can be two parts of the application code; during application runtime, the web side and the native side can be linked through JSB.
[0081] Webview is a component that embeds web page content into mobile applications. It allows developers to directly embed web page content (such as HTML pages, cascading style sheets (CSS), or web pages written in JavaScript) into the application interface, thereby enabling the loading and display of web pages.
[0082] The ETS (Extended TypeScript) layer is used to handle the application's user interface and business logic. ETS is an application development language within the Harmony ecosystem.
[0083] JavaScript engine: A virtual machine specifically designed to process JavaScript scripts, responsible for parsing and executing JavaScript code.
[0084] V8 engine: A JavaScript engine that uses just-in-time (JIT) compilation technology to convert JavaScript code into machine code, thereby improving the execution speed of JavaScript code.
[0085] Native Application Programming Interface (NAPI) components are interfaces developed based on the operating system's native programming language. NAPI components enable communication between JavaScript (JS) and C / C++ code. Applications can directly or indirectly call NAPI interfaces to utilize the capabilities provided by the operating system to fulfill their business requirements. For example, for some operating systems, the native programming language may include one or more of the following: C, C++, Objective-C, Swift, Java, Kotlin, JS, or ETS.
[0086] The Chromium layer, also known as Chromium, is an open-source web browser project that provides most of the browser's functionality, including tab management, user interface rendering, and network communication.
[0087] CEF (Chromium Embedded Framework) layer: This is an open-source project based on Chromium. The CEF layer provides tight integration with Chromium, enabling host applications to embed and render web content.
[0088] Nweb layer: A native engine for web components built on CEF, capable of loading and displaying web page content.
[0089] JS (JavaScript) objects are one of the core data types used in the JavaScript language for storing and organizing data.
[0090] The following has Figure 1 and Figure 2 Taking the electronic device with the structure shown as an example, the data transmission method provided in the embodiments of this application will be explained in detail.
[0091] Currently, in the process of transferring data from the web client to the native client, the data is first transmitted from the web client to the NAPI component provided by the operating system, and then the NAPI component transmits the received data to the native client. This data transfer from the web client to the NAPI component involves multiple type conversions in the programming language, which consume a significant amount of time and reduce data transfer efficiency. The following explanation uses HarmonyOS as an example to illustrate the process of transferring data from the web client to the NAPI component.
[0092] For example, the web application can call JSB through the WebView component, and then use JSB to pass data to the NAPI component and from there to the native application. Specifically, passing data to the NAPI component via JSB can be achieved through the following steps: The web application first sends the data to the V8 engine as a JS object. The V8 engine then compiles and parses the JS object into a V8 Value object. This V8 Value object then passes through the Chromium layer, CEF layer, and Nweb layer sequentially from the V8 engine, finally reaching the NAPI component. During this process, each layer (Chromium, CEF, and Nweb) needs to perform type conversion on the incoming data to ensure data transferability.
[0093] For example, the CEF layer, Nweb layer, and Chromium layer can be optional layers.
[0094] Figure 3 This is a schematic diagram illustrating the process of transferring data from the web client to the native client in related technologies. For example... Figure 3 As shown, the web client first sends the data to be transmitted as a JavaScript object to the V8 engine. The V8 engine then compiles and parses the JavaScript object into a V8Value object. The V8 engine passes the V8 Value object to the Chromium layer. At the Chromium layer, the V8 Value object is converted to the corresponding C++ type (referred to as the Chromium type) for further transmission to the CEF layer. The CEF layer converts the data from the Chromium layer to the corresponding C++ type (referred to as the CEF type) for further transmission to the Nweb layer. The Nweb layer converts the data from the CEF layer to... NThe web layer uses a corresponding C++ type (referred to as the Nweb type) to pass data to the NAPI component. Finally, the NAPI component performs type conversion on the data passed from the Nweb layer before passing it to the native side. The process of passing data from the web side to the NAPI component involves multiple type conversions in the programming language, consuming a significant amount of time and increasing the overall time cost of the data transfer process, thus impacting data transfer efficiency.
[0095] Based on this, this application provides a data transfer method. This method allocates a target shared memory space from the memory space, and writes the acquired first data to be transferred into the target shared memory space using a JavaScript engine. The target shared memory space is used to store data of a first type, and the type of the first data to be transferred belongs to this first type. Subsequently, the NAPI component can directly read the first data to be transferred from the target shared memory space and convert the type of the first data to be transferred to the corresponding type (i.e., the second type) to obtain the target data. Finally, the NAPI component transfers the target data to the native side. Thus, unlike related technologies, it is not necessary to pass the first data to be transferred through multiple type conversions in the programming language to the NAPI component, reducing the time consumed in the data transfer process and improving data transfer efficiency. The JavaScript engine can be referred to as a web JavaScript engine.
[0096] For example, when the operating system is HarmonyOS, the JavaScript engine can be the V8 engine. The following detailed explanation of the data transfer method provided in this application embodiment, using HarmonyOS as the operating system, will illustrate this method in detail.
[0097] like Figure 4As shown, the web client first sends the data to be transmitted to the V8 engine in the form of a JS object. The V8 engine then compiles and parses the JS object into a V8 Value object. Next, the V8 engine writes the V8 Value object of type 1 into the target shared memory space. The NAPI component calls the C++ API, which reads the V8 Value object of type 1 from the target shared memory space and performs type conversion on it to obtain a converted Value object. The target data is then determined based on the converted Value object. The target data includes at least the converted V8 Value object, or at least the data obtained after processing the converted V8 Value object. The type of the converted V8 Value object is the C++ type corresponding to the type of the V8 Value object. The C++ API is an interface provided by the target shared memory space for reading data from the target shared memory space and performing type conversion on that data.
[0098] The data transfer method provided in this application embodiment can be applied to scenarios where H5 pages interact with native clients. An H5 page is a specific type of web page, specifically a web page developed using HTML technology that is loaded and displayed by a WebView. The following provides an exemplary explanation of the data transfer method provided in this application embodiment for scenarios where H5 pages interact with native clients.
[0099] When a user interacts with an H5 page on the web (e.g., clicking a product details button, selecting an option), the WebView component responds to the user's action by calling a JSB to pass data from the web to the native side. This web-side data might include, for example, the product's identity document (ID) and name, retrieved in response to the user's action. The JSB then passes this data to the native side. For instance, the product ID and name are provided to the V8 engine as JavaScript objects. The V8 engine compiles and parses these JavaScript objects to obtain V8 Value objects. If these V8 Value objects are of type 1, the V8 engine can write them to the target shared memory space. Next, the NAPI component calls the C++ API provided by the target shared memory space to read the V8 Value objects from the target shared memory space and perform type conversion to obtain the converted V8 Value objects. Finally, the NAPI component passes the converted V8 Value objects to the native side, or processes the converted V8 Value objects before passing them to the native side.
[0100] For example, the first type includes one or more of the following: Boolean type, 8-bit unsigned integer, 8-bit signed integer, 16-bit unsigned integer, 16-bit signed integer, 32-bit unsigned integer, 32-bit signed integer, 64-bit unsigned integer, 64-bit signed integer, 32-bit floating-point type, 64-bit floating-point type, string, or binary data.
[0101] The above solution, during the data transfer process from the web client to the native client, first writes a V8 Value object of type 1 to the language-independent target shared memory space. Then, the NAPI component retrieves this V8 Value object from the target shared memory space across languages and performs type conversion to transfer the data to the native client. This eliminates the need for multiple type conversions across programming languages (such as at the Chromium, CEF, and Nweb layers) to pass the V8 Value object of type 1 to the NAPI component, as in related technologies. This reduces the number of cross-language type conversions during data transfer, thereby reducing the load on the entire data transfer chain and improving data transfer speed and efficiency.
[0102] Figure 5 This is a flowchart illustrating another data transmission method provided in an embodiment of this application. This data transmission method can be applied to an electronic device, which does not rely on... Figure 5The specific order shown is a limitation. It should be understood that in other embodiments, the order of some steps in this method can be interchanged according to actual needs, or some steps can be omitted or deleted. This method can be applied to, but is not limited to, scenarios where H5 pages interact with native clients. This method can be implemented by the web client calling JSB. Figure 5 As shown, the method includes steps S501 to S504, and each step is explained in detail below.
[0103] S501: Obtain the first data to be transmitted through the JavaScript engine.
[0104] The first data to be transmitted is determined through user interaction or automatic triggering mechanisms on the web page. The JavaScript engine used can also be called a web JavaScript engine. JavaScript engines can include, but are not limited to, the V8 engine and the Hermes engine. The data transmission method provided in this application can be applied to different operating systems, and different operating systems correspond to different JavaScript engines.
[0105] For example, when the data transfer method is applied to the HarmonyOS operating system, the JavaScript engine can be the V8 engine. When the data transfer method is applied to the Android operating system, the JavaScript engine can be the Hermes engine.
[0106] It should be understood that user interaction can be any action performed by a user when interacting with elements on a web page. This action can trigger the execution of JavaScript code. Such actions include, but are not limited to, filling out and submitting a form on a web page, clicking on a web page (such as clicking a button, link, or image), entering text or selecting options in an input box on a web page, and dragging page elements with the mouse.
[0107] In this embodiment of the application, the first data to be transmitted can be obtained through a JavaScript engine. When the JavaScript engine is a V8 engine, the first data to be transmitted can be a V8 Value object of type first type.
[0108] In one possible implementation, the electronic device obtains the raw data to be transmitted (i.e., the data to be transmitted) through user interaction or automatic triggering mechanisms on a web page. The web interface provides the raw data to be transmitted as a JS object to the JavaScript engine. The JavaScript engine compiles and parses this JS object to obtain a corresponding JavaScript engine object, which is then used as the initial data to be transmitted. Subsequently, if the initial data to be transmitted contains data of a first type, that existing data of the first type is used as the first data to be transmitted.
[0109] For example, when the JavaScript engine is V8, the initial data to be passed is a V8 Value object.
[0110] It should be understood that automatic triggering mechanisms allow JavaScript code to execute automatically without user intervention. This mechanism can utilize internal system logic, timer settings (such as using `setInterval` or `setTimeout` to periodically trigger a function), or other automated processes to proactively retrieve the raw data to be transmitted. For example, a timer can be set to periodically execute a function to retrieve data from a data source (such as an API, database, or file), and this retrieved data can be used as the raw data to be transmitted. Furthermore, browser or system events (such as window resizing, network status changes, etc.) can be listened for, and logic can be automatically triggered to generate the raw data to be transmitted when these events occur.
[0111] The following example illustrates how to obtain the first piece of data to be transmitted using a JavaScript engine.
[0112] For example, consider determining the original data to be transmitted through user interaction on a web page, and then obtaining the first data to be transmitted through a JavaScript engine. Figure 6The web page shown is for Company A to collect XXXX information. This page contains a form with three input fields: name, age, and email address. When a user fills out the form and clicks the submit button, this triggers an event. JavaScript code captures this submit event, retrieves the data from the form, and uses this data as the initial data to be transmitted. Subsequently, the WebView component on the web side calls a JavaScript Scripting Bundle (JSB), which encapsulates the initial data into a JavaScript object and passes this object to the JavaScript engine. The JavaScript engine compiles and parses the JS object into its corresponding object, using this object as the initial data to be transmitted. Finally, if the initial data to be transmitted contains data of type 1, then that data of type 1 is used as the first data to be transmitted.
[0113] For example, consider determining the original data to be transmitted through an automatic triggering mechanism, and then obtaining the first data to be transmitted through the JavaScript engine. The JavaScript code includes an automatic triggering mechanism that periodically retrieves data from a data source (such as an API) and uses this retrieved data as the original data to be transmitted. Subsequently, the WebView component on the web side calls a JSB, which encapsulates the original data to be transmitted into a JS object and provides the JS object to the JavaScript engine. The JavaScript engine can compile and parse the JS object into a corresponding JavaScript engine object, using this object as the initial data to be transmitted. Finally, if the initial data to be transmitted contains data of the first type, then the data of the first type is used as the first data to be transmitted.
[0114] For example, the initial data to be transmitted can be data that the JavaScript engine needs to pass to a function or method on the native side.
[0115] Optionally, the JavaScript engine can be used to retrieve the parameter list, and the data in the parameter list can be used as the initial data to be transmitted. The initial data to be transmitted is carried within the parameter list.
[0116] In one possible implementation, the first type includes one or more of the following:
[0117] 1) BOOL: Represents a Boolean type, stored in 1 bit, which can be true (1) or false (0).
[0118] 2) UINT8: 8-bit unsigned integer. Its value range is from 0 to 255 (i.e., 0 to 2...). 8 -1). Because it is unsigned, it cannot represent negative numbers.
[0119] 3) INT8: 8-bit signed integer. Its value range is from -128 to 127. Unlike UINT8, INT8 can represent both positive and negative numbers.
[0120] 4) UINT16: 16-bit unsigned integer. Its value range is from 0 to 65535 (i.e., 0 to 2^35). 16 -1).
[0121] 5) INT16: 16-bit signed integer. Its value range is from -32768 to 32767.
[0122] 6) UINT32: 32-bit unsigned integer. Its value range is from 0 to 429496725 (i.e., 0 to 2^35). 32 -1).
[0123] 7) INT32: 32-bit signed integer. Its value range is from -2147483648 to 2147483647.
[0124] 8) UINT64: 64-bit unsigned integer. Its value range is from 0 to 18446744073709551615 (i.e., 2^64). 64 -1).
[0125] 9) INT64: 64-bit signed integer. Its value range is from -9223372036854775808 to 9223372036854775807.
[0126] 10) FLOAT: 32-bit floating-point type. It is used to represent numerical values with a decimal part, and has limited precision and range.
[0127] 11) DOUBLE: 64-bit floating-point type.
[0128] 12) STRING: A string of arbitrary length. This represents a string of characters whose length can vary, depending on the limitations of the application or language.
[0129] 13) BINARY: Binary data of arbitrary length.
[0130] S502: Using the JavaScript engine, the first data to be transmitted is written into the target shared memory space.
[0131] The target shared memory space is used to store data of type 1, and the type of the first data to be transmitted belongs to type 1.
[0132] In one possible implementation, the first type includes: Boolean type, 8-bit unsigned integer, 8-bit signed integer, 16-bit unsigned integer, 16-bit signed integer, 32-bit unsigned integer, 32-bit signed integer, 64-bit unsigned integer, 64-bit signed integer, 32-bit floating-point type, 64-bit floating-point type, string, and binary data.
[0133] In this embodiment, the number of first data to be transmitted can be at least one. The target shared memory space is a memory region space allocated from memory by the JavaScript engine. This target shared memory space is configured with a header field and at least one data field. The header field is used to write attribute information of the data, and the data field is used to write the data. The header field includes multiple sets of attribute fields, and the attribute fields include at least a type field. The header field and data field configured in the target shared memory space determine the data memory layout of the target shared memory space.
[0134] For example, the target shared memory space can specifically be a memory region used to cache data when processing streaming data, which can be represented by a flowbuffer.
[0135] In one possible implementation, the JavaScript engine can call the target interface for requesting shared memory space, and then request the target shared memory space through the target interface.
[0136] For example, the target shared memory space is Flowbuffer, and the target interface can be the Flowbuffer application programming interface (API).
[0137] In this embodiment, the target shared memory space is configured with a header field and at least one data field. In S502, the first data to be transmitted is written into the target shared memory space through a JavaScript engine, which can be achieved in the following way:
[0138] The JavaScript engine calls the write interface corresponding to the type of the first data to be transmitted, and writes the attribute information of the first data to be transmitted into the header field through the write interface. The attribute information includes the type of the first data to be transmitted. The first data to be transmitted is written into the corresponding data field of at least one data field through the write interface.
[0139] In one possible implementation, there is a corresponding write interface for different types of first data to be transmitted, through which the first data to be transmitted and its attribute information can be written to the target shared memory space.
[0140] For example, taking a first batch of three data items to be transmitted as Data1, Data2, and Data3, respectively, the target shared memory space is a Flowbuffer, and the write interface corresponding to the type of the first data item to be transmitted can be called the FlowbufferStore interface. Through the JavaScript engine, the FlowbufferStore interface corresponding to the type of Data1 can be called to write the attribute information of Data1 into the header field of the Flowbuffer and to write Data1 into at least one of the corresponding data fields. Similarly, the FlowbufferStore interface corresponding to the type of Data2 can be called through the JavaScript engine to write the attribute information of Data2 into the header field of the Flowbuffer and to write Data2 into at least one of the corresponding data fields. Likewise, the FlowbufferStore interface corresponding to the type of Data3 can be called through the JavaScript engine to write the attribute information of Data3 into the header field of the Flowbuffer and to write Data3 into at least one of the corresponding data fields.
[0141] In this embodiment, multiple first data to be transmitted can be written consecutively to the target shared memory space, thus ensuring that their positions in the target shared memory space are continuous. At least one data field can be determined based on the write position and size of the first data to be transmitted.
[0142] In one possible implementation, the first data to be transmitted is written to the corresponding data field of at least one data field via a write interface. Alternatively, it can be implemented as follows: Based on the write position information corresponding to the first data to be transmitted, the first data to be transmitted is written to the corresponding data field of at least one data field via the write interface. The write position information indicates either the starting write position or the current write position of the first data to be transmitted. The write position includes a starting write position and a writing end position.
[0143] The write position information of the first first data to be transmitted among multiple first data to be transmitted can be preset or randomly determined. The write position information of the first data to be transmitted among multiple first data to be transmitted can be determined based on the end position of the previous data.
[0144] For example, taking a first batch of three data items to be transmitted as Data1, Data2, and Data3, the size of the Flowbuffer is, for example, 1024 bytes. Through the JavaScript engine, the FlowbufferStore interface corresponding to the type of Data1 can be called to write the attribute information of Data1 into the header field of the Flowbuffer. The starting write position of Data1 is byte 512, and 8 bytes of Data1 data can be continuously written from the byte 512 position of the Flowbuffer until the end of Data1 is reached. The starting write position of Data1 can be determined based on write position information, which can be set by the user or determined by the electronic device based on the data distribution in the target shared memory space. Next, for Data2, assuming its size is also 8 bytes, since Data1 has already occupied space from byte 512 to byte 519 (inclusive), the starting write position of Data2 can be the byte after the end position of Data1, i.e., byte 520. The JavaScript engine can call the FlowbufferStore interface corresponding to the Data2 type to write the attribute information of Data2 into the header field of the Flowbuffer, and then continuously write 8 bytes of Data2 data into the Flowbuffer starting from byte 520. Finally, for Data3, assuming its size is also 8 bytes, since Data3 already occupies space from byte 520 to byte 527 (inclusive), the starting write position for Data3 can be the byte following the ending position of Data2, i.e., byte 528. The JavaScript engine can then call the FlowbufferStore interface corresponding to the Data3 type to write the attribute information of Data3 into the header field of the Flowbuffer, and then continuously write 8 bytes of Data3 data into the Flowbuffer starting from byte 528.
[0145] In one possible implementation, the attribute information may also include the index of the first data to be transmitted in the initial data to be transmitted and / or the length of the first data to be transmitted.
[0146] In one possible implementation, the attribute information includes the type of the first data to be transmitted, the index of the first data to be transmitted in the initial data to be transmitted, and the length of the first data to be transmitted. The header field of the target shared memory space configuration includes multiple sets of attribute fields, each set of attribute fields including a type field, an index field, and a length field. The JavaScript engine calls the write interface corresponding to the type of the first data to be transmitted, and writes the attribute information of the first data to be transmitted into the header field through the write interface. This can be achieved in the following way:
[0147] The JavaScript engine calls the write interface corresponding to the type of the first data to be transmitted, writing the attribute information of the first data to be transmitted into a set of attribute fields in the header field. Specifically, the type of the first data to be transmitted, the index of the first data to be transmitted, and the length of the first data to be transmitted are written into the type field, index field, and length field of the corresponding set of attribute fields in the header field, respectively.
[0148] For example, taking a first batch of three data items to be transmitted as Data1, Data2, and Data3, the JavaScript engine can call the FlowbufferStore interface corresponding to the type of Data1 to write the type of Data1 into the type field of the first group of attribute fields in the header, write the index of Data1 into the index field of the first group of attribute fields, and write the length of Data1 into the length field of the first group of attribute fields. Similarly, when writing Data2 into the target shared memory space, the JavaScript engine can call the FlowbufferStore interface corresponding to the type of Data2 to write the type of Data2 into the type field of the second group of attribute fields in the header, write the index of Data2 into the index field of the second group of attribute fields, and write the length of Data2 into the length field of the second group of attribute fields. Finally, during the process of writing Data3 to the target shared memory space, the JavaScript engine can call the FlowbufferStore interface corresponding to the type of Data3 to write the type of Data3 to the type field of the third group of attribute fields in the header field, write the index of Data3 to the index field of the third group of attribute fields, and write the length of Data3 to the length field of the third group of attribute fields.
[0149] Optionally, if the number of the first data to be transmitted is one, this attribute information can be the type of the first data to be transmitted.
[0150] For example, if the number of first data to be transmitted is one, the first data to be transmitted is written into any data field of the Flowbuffer, and all data in the data field of the Flowbuffer can be the first data to be transmitted.
[0151] Optionally, if there are multiple types of the first data to be transmitted, the attribute information can be the type of the first data to be transmitted, the index of the first data to be transmitted in the initial data to be transmitted, and the length of the first data to be transmitted.
[0152] Figure 7 This is a schematic diagram of the data memory layout of the target shared memory space in a data transfer method provided in an embodiment of this application. Figure 7 As shown, at least one data field configured in the target shared memory space contains m consecutive pieces of first data to be transmitted, namely data1, data2…datam. The header field configured in this target shared memory space contains multiple sets of attribute fields, which are written sequentially to match the order of the data in the data fields. For example… Figure 7 As shown, the first set of attribute fields contains the type of data1, the index of data1, and the length of data1. The second set of attribute fields contains the type of data2, the index of data2, and the length of data2. The m-th set of attribute fields contains the type of data m, the index of data m, and the length of data m.
[0153] In this embodiment, by calling a set of APIs targeting the shared memory space in different language environments, it is possible to construct, write, modify, and destroy the target shared memory space; the target shared memory space supports storing data of a first type. This set of APIs includes a target interface for requesting (i.e., constructing) the target shared memory space, a write interface for writing (or modifying) data to the target shared memory space, and a read interface for reading data from the target shared memory space. The read interface is also used for type conversion of the read data and for destroying the target shared memory space.
[0154] S503: Read the first data to be transmitted from the target shared memory space through the native application programming interface (NAPI) component, and convert the type of the first data to be transmitted to the corresponding second type to obtain the target data.
[0155] The second type belongs to the C++ type. The second type varies depending on the type of the data to be transmitted in the first case.
[0156] For example, if the first type of data to be transmitted is STRING, the second type can be C++STRING; if the first type of data to be transmitted is FLOAT, then the second type can be C++FLOAT.
[0157] In this embodiment of the application, the data of the data field in the target shared memory space can be read by the NAPI component to obtain the first data to be transmitted, and the type of the first data to be transmitted can be converted into the corresponding second type to obtain the target data.
[0158] In one possible implementation, data from the header field of the target shared memory space is read using a NAPI component to obtain attribute information of the first data to be transmitted, including its type. Then, the first data to be transmitted is obtained by reading data from the data field of the target shared memory space using the NAPI component. Next, based on the type of the first data to be transmitted, a type conversion is performed to obtain the converted first data to be transmitted. The converted first data to be transmitted is of a C++ type corresponding to the type of the first data to be transmitted. Subsequently, the converted first data to be transmitted can be used as the target data, or the converted first data to be transmitted can be processed to obtain the target data. The number of first data to be transmitted can be one or more.
[0159] For example, if the first data to be transmitted is one, the NAPI component can directly read the data from the data field in the target shared memory space and use the read data as the first data to be transmitted.
[0160] For example, if there are multiple first data items to be transmitted, the NAPI component can read each first data item based on information in the attribute information other than the type of the first data item to be transmitted. This information, other than the type of the first data item to be transmitted, could be, for example, the length of the first data item to be transmitted.
[0161] In one possible implementation, S503 uses the NAPI component to read the first data to be transmitted from the target shared memory space and convert the type of the first data to be transmitted to the corresponding second type to obtain the target data. This can be achieved in the following way:
[0162] The NAPI component calls the read interface used to read data from the target shared memory space. Through the read interface, it reads the attribute information of the first data to be transferred from the header field configured in the target shared memory space. The attribute information includes the type of the first data to be transferred, its index in the initial data to be transferred, and its length. Based on the starting write position and length of the first data to be transferred, the read interface reads the first data to be transferred from the data field configured in the target shared memory space. The read interface then converts the type of the first data to be transferred to the corresponding second type, obtaining the converted first data to be transferred. Finally, the NAPI component determines the target data based on the converted first data to be transferred and its index in the initial data to be transferred.
[0163] For example, the read interface can be a Flowbuffer C++ API, which can also be represented as a C++ API. Through this C++ API, data in the first group of attribute fields in the header fields configured in the target shared memory space can be read to obtain the attribute information of data1. This attribute information includes the type of data1, the index of data1 in the initial data to be transmitted, and the length of data1. Subsequently, based on the starting write position of data1 and the length of data1, data in the corresponding data field of at least one data field configured in the target shared memory space is read to obtain data1. Next, based on the type of data1, data1 is converted to the corresponding C++ type to obtain the converted data1; for example, if the type of data1 is STRING, the converted data1 is of type C++STRING.
[0164] For example, if the first data to be transmitted is one, such as data1, then the converted data1 can be used as the target data.
[0165] For example, if the number of first data items to be transmitted is m, the initial data to be transmitted contains these m first data items. Following the aforementioned method, the transformed data1, transformed data2, ..., transformed data m can be obtained through this C++ API. Subsequently, the target data is determined based on the index of data1 in the initial data to be transmitted, the index of data2 in the initial data to be transmitted, ..., the index of data m in the initial data to be transmitted, the transformed data1, the transformed data2, ..., and the transformed data m.
[0166] In one possible implementation, when the initial data to be transmitted is of the first type, the target data is determined by using the NAPI component based on the transformed first data to be transmitted and the index of the first data to be transmitted in the initial data to be transmitted. This can be achieved by: using the NAPI component, sorting the multiple transformed first data to be transmitted corresponding to the multiple first data to be transmitted based on the indices of the multiple first data to be transmitted in the initial data to obtain the target data.
[0167] For example, m is 3, and the initial data to be transmitted contains only three first data items: data1, data2, and data3. The three transformed first data items are transformed data1, transformed data2, and transformed data3. The transformed data1, transformed data2, and transformed data3 can be sorted based on their indices in the initial data to be transmitted (data1, data2, and data3), resulting in sorted data, which is then used as the target data. Here, the index of data1 in the initial data to be transmitted represents the position of data1, the index of data2 in the initial data to be transmitted represents the position of data2, and the index of data3 in the initial data to be transmitted represents the position of data3. Assuming that based on the indices of data1, data2, and data3 in the initial data to be transmitted, the order of data1, data2, and data3 is determined to be data2, data1, and data3 respectively; then the sorted data follows this order, meaning the order of the transformed data1, transformed data2, and transformed data3 in the sorted data is transformed data2, transformed data1, and transformed data3 respectively. The sorted data can be used as the target data; alternatively, the sorted data can be processed, and the processed data can be used as the target data.
[0168] If the initial data to be passed contains data of a type other than the first type, this data of a different type can be used as the second data to be passed. There can be at least one second data item to be passed. The second data to be passed to the NAPI component via the JavaScript engine can be achieved in the following way:
[0169] The JavaScript engine uses data of types other than the first type present in the initial data to be transmitted as the second data to be transmitted. This second data is then passed through multiple data transmission layers to the NAPI component. The NAPI component performs type conversion on the data passed through these layers to obtain the third data.
[0170] For example, the second data to be transmitted can be an object in the V8 value object other than the first type of V8 value object, such as... Figure 3 As shown, the data transmission layers include the Chromium layer, CEF layer, and Nweb layer. The second data to be transmitted can be first passed to the Chromium layer via the JavaScript engine. In the Chromium layer, the second data needs to be converted into its corresponding C++ type for transmission to the CEF layer. Subsequently, the CEF layer converts the data from the Chromium layer into its corresponding C++ type for transmission to the Nweb layer. Next, the Nweb layer converts the data from the CEF layer into its corresponding C++ type for transmission to the NAPI component. Finally, the NAPI component, based on the type of the data from the CEF layer, converts it into its corresponding C++ type to obtain the third data.
[0171] The above method of determining the target data using the NAPI component, based on the transformed first data to be transmitted and its index in the initial data to be transmitted, can also be achieved in the following ways:
[0172] Using the NAPI component, the transformed first and third data are sorted and concatenated based on the indices of the first and second data to be transmitted in the initial data to be transmitted, to obtain the target data.
[0173] For example, the number of first data items to be transmitted is three, namely data1, data2, and data3; the number of second data items to be transmitted is two, namely data4 and data5; the initial data to be transmitted includes data1, data2, data3, data4, and data5. Based on the indices of these five data items in the initial data to be transmitted, the order of these five data items is determined to be data2, data1, data3, data5, and data4. Following this order, the transformed data1, transformed data2, transformed data3, transformed data4, and transformed data5 are sorted to obtain sorted data. The sorted data is then concatenated to obtain the target data, or the sorted data is processed to obtain the target data. Here, multiple transformed first data items to be transmitted include transformed data1, transformed data2, and transformed data3; multiple third data items include transformed data4 and transformed data5.
[0174] Following this order, the transformed data1, transformed data2, transformed data3, transformed data4, and transformed data5 are sorted to obtain sorted data. The sorted data is then concatenated to obtain the target data. Alternatively, the transformed data (i.e., transformed data2, transformed data1, transformed data3, transformed data5, and transformed data4) can be added sequentially to a new list using append or insert operations to ensure their correct order. Finally, the data in the sorted lists are concatenated to obtain the final target data.
[0175] It should be understood that the sorted data is processed to obtain the target data in this document. The processing of the sorted data may be some internal business processing or other processing. The specific processing performed on the sorted data in this application embodiment is not limited.
[0176] The above scheme can pass the first piece of data to be transmitted to the NAPI component via shared memory, and pass the second piece of data to the NAPI component via multiple data transmission layers. Subsequently, the NAPI component performs type conversion on both pieces of data and concatenates the converted data to obtain the target data. This ensures data integrity during transmission, and because only a portion of the data (i.e., the second piece of data) is transmitted through multiple data transmission layers, compared to related technologies where all data is transmitted through multiple layers, it reduces the number of cross-programming language type conversions during transmission, thereby reducing the time consumed in the data transmission process and improving data transmission efficiency.
[0177] S504. Pass target data to the native side through the NAPI component.
[0178] The native side is used to handle the application's user interface and business logic. The user interface includes web pages.
[0179] For example, the Native side is the ETS layer.
[0180] In this embodiment, after S504, the process may further include: calling a destructor through the read interface to clear the first data to be transmitted, the target data, or release the target shared memory space. The destructor is a special method that is automatically called when an object is destroyed to release the resources occupied by the object. Thus, by automatically calling the destructor, the resources occupied by the target data, the first data to be transmitted, or the target shared memory space can be released promptly and correctly when they are no longer needed, thereby improving system stability and performance.
[0181] This application provides a data transfer method that enables cross-language data transfer. The method includes: obtaining first data to be transferred via a JavaScript engine, the first data to be transferred being determined by user interaction or automatic triggering mechanisms on a web page; writing the first data to be transferred into a target shared memory space via the JavaScript engine, the target shared memory space being used to store data of a first type, the first type including the type of the first data to be transferred; reading the first data to be transferred from the target shared memory space via the operating system's NAPI component, and converting the type of the first data to be transferred into a corresponding second type to obtain target data; and transferring the target data to a native end via the NAPI component, wherein the native end is used to process the application's user interface and business logic, the user interface including the web page. Thus, unlike related technologies, it eliminates the need for multiple type conversions of the first data to be transferred through programming languages before passing it to the NAPI component, reducing the time consumed in the data transfer process and thereby improving data transfer efficiency.
[0182] The foregoing has detailed examples of the data transmission method provided in this application. It is understood that, in order to achieve the above functions, the electronic device includes corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application. This application can divide the data transmission method into functional units based on the above method examples; for example, each function can be divided into separate functional units, or two or more functions can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. It should be noted that the unit division in this application is illustrative and only represents a logical functional division; other division methods may exist in actual implementation.
[0183] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 8 The dashed line indicates that the unit or module is optional. Electronic device 8 can be used to implement the methods described in the above method embodiments. Electronic device 8 can be an electronic device or a chip (system).
[0184] The electronic device 8 includes one or more processors 801, which can support the electronic device 8 in implementing the data transmission method described in the above method embodiments. The processor 801 can be a general-purpose processor or a dedicated processor. For example, the processor 801 can be a central processing unit (CPU). The CPU can be used to control the electronic device 8, execute software programs, and process data from the software programs. The electronic device 8 may also include a communication unit 805 for implementing signal input (reception) and output (transmission).
[0185] The aforementioned electronic device 8 may be a chip (system) including a memory and a processor, wherein the processor is configured to execute a computer program stored in the memory to implement the methods shown in the various embodiments above.
[0186] The communication unit 805 may be an input and / or output circuit of the chip (system), or the communication unit 805 may be a communication interface of the chip (system), and the chip (system) may be a component of the electronic device 8.
[0187] For example, the communication unit 805 may be a transceiver of the electronic device 8, or the communication unit 805 may be a transceiver circuit of the electronic device 8. The electronic device 8 may include one or more memories 802, which store a program 804. The program 804 can be executed by the processor 801 to generate instructions 803, causing the processor 801 to execute the method described in the above method embodiments according to the instructions 803. Optionally, the memory 802 may also store data. Optionally, the processor 801 may also read data stored in the memory 802, which may be stored at the same memory address as the program 804, or the data may be stored at a different memory address than the program 804.
[0188] The processor 801 and memory 802 can be configured separately or integrated together, for example, integrated on a system-on-chip (SOC) of an electronic device. For details on how the processor 801 performs data transfer, please refer to the relevant description in the method embodiments.
[0189] It should be understood that the steps of the above method embodiments can be implemented by hardware logic circuits or software instructions in the processor 801. The processor 801 can be a CPU, a digital signal processor (DSP), a field programmable gate array (FPGA), or other programmable logic devices, such as discrete gate, transistor logic devices, or discrete hardware components.
[0190] This application also provides a computer program product that, when executed by processor 801, implements the method of any of the method embodiments in this application. The computer program product can be stored in memory 802, for example, as program 804. Program 804 undergoes preprocessing, compilation, assembly, and linking processes to ultimately be converted into an executable object file that can be executed by processor 801.
[0191] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a computer, implements the method of any of the method embodiments of this application. The computer program may be a high-level language program or an executable object program.
[0192] The computer-readable storage medium is, for example, memory 802. Memory 802 can be volatile memory or non-volatile memory, or memory 802 can include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate Synchronous DRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), SynchLink DRAM (SLDRAM), and Direct Rambus RAM (DRRAM).
[0193] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process and technical effects of the above-described apparatus and equipment can be referred to the corresponding processes and technical effects in the foregoing method embodiments, and will not be repeated here.
[0194] The systems, apparatuses, and methods disclosed in the embodiments provided in this application can be implemented in other ways. For example, some features of the method embodiments described above may be omitted or not performed. The apparatus embodiments described above are merely illustrative; the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Multiple units or components may be combined or integrated into another system. Furthermore, the coupling between units or components can be direct or indirect, including electrical, mechanical, or other forms of connection.
[0195] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A data transmission method, characterized in that, Applied to electronic devices, the method includes: The first piece of data to be transmitted is obtained through the JavaScript engine. This first piece of data is determined by user interaction behavior or automatic triggering mechanism on the web page. The JavaScript engine writes the first data to be transmitted into the target shared memory space, which is used to store data of the first type, and the type of the first data to be transmitted belongs to the first type. The first data to be transmitted is read from the target shared memory space through the operating system's native application programming interface (NAPI) component, and the type of the first data to be transmitted is converted into the corresponding second type to obtain the target data. The target data is transmitted to the native side through the NAPI component, wherein the native side is used to process the application's user interface and business logic; the user interface includes the web page.
2. The method according to claim 1, characterized in that, The target shared memory space is configured with a header field and at least one data field. The step of writing the first data to be transmitted into the target shared memory space via the JavaScript engine includes: The JavaScript engine calls the write interface corresponding to the type of the first data to be transmitted, and writes the attribute information of the first data to be transmitted into the header field through the write interface. The attribute information includes the type of the first data to be transmitted. The first data to be transmitted is written into the corresponding data field of the at least one data field through the write interface.
3. The method according to claim 2, characterized in that, The step of writing the first data to be transmitted into the corresponding data field of the at least one data field through the writing interface includes: Through the write interface, based on the write position information corresponding to the first data to be transmitted, the first data to be transmitted is written into the corresponding data field of the at least one data field, and the write position information indicates the starting write position of the first data to be transmitted.
4. The method according to claim 2 or 3, characterized in that, The attribute information also includes the index of the first data to be transmitted in the initial data to be transmitted and the length of the first data to be transmitted.
5. The method according to any one of claims 1 to 4, characterized in that, The process of obtaining the first data to be transmitted via a JavaScript engine includes: The initial data to be transmitted is obtained through the JavaScript engine. If the JavaScript engine contains data of the first type in the initial data to be transmitted, the data of the first type will be used as the first data to be transmitted.
6. The method according to claim 5, characterized in that, The step of reading the first data to be transmitted from the target shared memory space through the NAPI component of the operating system, and converting the type of the first data to be transmitted to the corresponding second type to obtain the target data, includes: The NAPI component calls the read interface for reading data in the target shared memory space, and reads the attribute information of the first data to be transmitted from the header field configured in the target shared memory space through the read interface. The attribute information includes the type of the first data to be transmitted, the index of the first data to be transmitted in the initial data to be transmitted, and the length of the first data to be transmitted. The first data to be transmitted is read from the data field configured in the target shared memory space through the read interface, based on the starting write position and the length of the first data to be transmitted. The type of the first data to be transmitted is converted into the corresponding second type through the reading interface to obtain the converted first data to be transmitted. The target data is determined using the NAPI component based on the transformed first data to be transmitted and the index of the first data to be transmitted in the initial data to be transmitted.
7. The method according to claim 6, characterized in that, The initial data to be transmitted is of the first type; The step of determining the target data using the NAPI component, based on the transformed first data to be transmitted and the index of the first data to be transmitted in the initial data to be transmitted, includes: Using the NAPI component, based on the indices of multiple first data to be transmitted in the initial data to be transmitted, the multiple transformed first data to be transmitted corresponding to the multiple first data to be transmitted are sorted to obtain the target data.
8. The method according to claim 6, characterized in that, The method further includes: (The initial data to be transmitted contains data of types other than the first type.) The JavaScript engine selects data of types other than the first type from the initial data to be transmitted as the second data to be transmitted, and transmits the second data to be transmitted to the NAPI component in sequence through multiple data transmission layers. The NAPI component performs type conversion on the data passed through the multiple data transfer layers to obtain the third data. Accordingly, determining the target data using the NAPI component, based on the transformed first data to be transmitted and the index of the first data to be transmitted in the initial data to be transmitted, includes: Using the NAPI component, the transformed first data to be transmitted and the third data are sorted and concatenated based on the index of the first data to be transmitted in the initial data to be transmitted and the index of the second data to be transmitted in the initial data to be transmitted, in order to obtain the target data.
9. The method according to any one of claims 1 to 8, characterized in that, The method further includes: The JavaScript engine calls the target interface for requesting shared memory space, and then requests the target shared memory space through the target interface.
10. The method according to any one of claims 1 to 9, characterized in that, The first type includes one or more of the following: Boolean type, 8-bit unsigned integer, 8-bit signed integer, 16-bit unsigned integer, 16-bit signed integer, 32-bit unsigned integer, 32-bit signed integer, 64-bit unsigned integer, 64-bit signed integer, 32-bit floating-point type, 64-bit floating-point type, string, or binary data.
11. An electronic device, characterized in that, include: A processor coupled to a memory for storing programs or instructions that, when executed by the processor, cause the electronic device to perform the method of any one of claims 1 to 10.
12. A chip system, characterized in that, The chip system includes a memory and a processor, the processor being configured to execute a computer program stored in the memory to implement the method as described in any one of claims 1 to 10.
13. A computer-readable storage medium having a computer program or instructions stored thereon, characterized in that, When the computer program or instructions are executed, they cause the computer to perform the method as described in any one of claims 1 to 10.
14. A computer program product, characterized in that, It includes computer program instructions that cause the computer to perform the method as described in any one of claims 1 to 10.
Citation Information
Cited By
An openharmony-oriented end-side speech recognition optimization system
CN122135722A
An edge-side speech recognition optimization system for OpenHarmony
CN122135722B