Data transmission method, electronic device, chip system, and storage medium
By writing and reading data in a shared memory space, combined with direct data transfer between the JavaScript engine and NAPI components, the problem of low efficiency in data transfer from the web client to the native client is solved, achieving more efficient data transfer.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2026-04-02
AI Technical Summary
In web-based front-end applications, data transfer efficiency is low when the web client transmits data to the native client due to multiple type conversions in programming languages.
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 memory space before transmitting it to the native side, thus avoiding multiple type conversions in the programming language.
It simplifies the data transmission process, reduces transmission time, and improves data transmission efficiency and accuracy.
Smart Images

Figure CN2025098673_02042026_PF_FP_ABST
Abstract
Description
Data transmission method, electronic device, chip system and storage medium
[0001] The present application claims priority to the Chinese patent application No. 202411346923.2, filed on September 25, 2024, and entitled "Data transmission method, electronic device, chip system and storage medium", the content of which is incorporated herein by reference in its entirety. TECHNICAL FIELD
[0002] The present application relates to the terminal field, and in particular to a data transmission method, an electronic device, a chip system and a storage medium. BACKGROUND
[0003] For some web front-end development-based applications, in the process of transmitting data from the web front-end (referred to as the web end) to the Native end, due to the characteristics of the development language or the development framework of the web end, multiple type conversions of programming languages are usually involved, which consumes a large amount of time and thus reduces the data transmission efficiency. SUMMARY
[0004] The present application provides a data transmission method, an electronic device, a chip system and a storage medium, which can reduce the time consumed in the data transmission process and improve the data transmission efficiency.
[0005] In a first aspect, a data transmission method is provided, which includes: obtaining, by a JavaScript engine, first to-be-transmitted data, the first to-be-transmitted data being determined through user interaction behavior on a web page of a web end or an automatic triggering mechanism; writing, by the JavaScript engine, the first to-be-transmitted data into a target shared memory space, the target shared memory space being used to store data of a first type, and the type of the first to-be-transmitted data belonging to the first type; reading, by a native application programming interface (NAPI) component of an operating system, the first to-be-transmitted data from the target shared memory space, and converting the type of the first to-be-transmitted data into a corresponding second type to obtain target data; and transmitting, by the NAPI component, the target data to a Native end, wherein the Native end is used to process the user interface and the business logic of an application, and the user interface includes the web page.
[0006] The method can be executed by an electronic device, or by a module (such as a processor, a chip, or a chip system) in the electronic device, or by a logic module or software that can realize all or part of the functions of the electronic device.
[0007] The NAPI component can directly obtain the first to-be-transferred data from the target shared memory space, and does not need to transfer the first to-be-transferred data to the NAPI component through multiple type conversions of a programming language as in the related art, thereby simplifying a data transfer process, reducing time consumed in the data transfer process, and improving data transfer efficiency.
[0008] The JavaScript engine is an example of a V8 engine, and the first to-be-transferred data can be a V8 Value object of the first type.
[0009] The Native end is an example of an ETS layer, which can also be referred to as an ArkTS layer.
[0010] In a possible implementation, the first type includes one or more of the following: a Boolean type, an 8-bit unsigned integer type, an 8-bit signed integer type, a 16-bit unsigned integer type, a 16-bit signed integer type, a 32-bit unsigned integer type, a 32-bit signed integer type, a 64-bit unsigned integer type, a 64-bit signed integer type, a 32-bit floating point type, a 64-bit floating point type, a string, or binary data.
[0011] The target shared memory space can be a memory region used for buffering data when processing stream data, which can be represented by a flow buffer.
[0012] In a possible implementation, the target shared memory space is configured with a header field and at least one data field, and the writing of the first to-be-transferred data into the target shared memory space by the JavaScript engine includes: calling, by the JavaScript engine, a write interface corresponding to the type of the first to-be-transferred data, and writing, by the write interface, attribute information of the first to-be-transferred data into the header field, the attribute information including the type of the first to-be-transferred data; and writing, by the write interface, the first to-be-transferred data into a corresponding data field in the at least one data field.
[0013] The header field can be represented as a Header field, and the data field can be represented as a data field.
[0014] The JavaScript engine can call a corresponding write interface based on the type of the first to-be-transferred data, and automatically write attribute information including the type of the first to-be-transferred data into the header field of the target shared memory space, so as to subsequently process the first to-be-transferred data based on the attribute information. Meanwhile, the first to-be-transferred data is also written into a corresponding data field. This process improves the accuracy and reliability of data transfer.
[0015] In a possible implementation, the writing, by the writing interface, of the first to-be-transferred data into the corresponding data field in the at least one data field comprises: writing, by the writing interface, the first to-be-transferred data into the corresponding data field in the at least one data field based on writing position information corresponding to the first to-be-transferred data, the writing position information indicating a starting writing position of the first to-be-transferred data.
[0016] The above scheme can ensure that data can be accurately stored in a predetermined position, avoiding the risk of data misplacement or loss, and further improving the accuracy and reliability of data transmission.
[0017] In a possible implementation, the attribute information further comprises an index of the first to-be-transferred data in the initial to-be-transferred data and a length of the first to-be-transferred data.
[0018] Optionally, in the case where the number of the first to-be-transferred data is one, the attribute information can be a type of the first to-be-transferred data.
[0019] Exemplarily, only one first to-be-transferred data is stored in the target shared memory space.
[0020] Optionally, in the case where the type of the first to-be-transferred data is multiple, the attribute information can be a type of the first to-be-transferred data, an index of the first to-be-transferred data in the initial to-be-transferred data, and a length of the first to-be-transferred data.
[0021] In a possible implementation, the first to-be-transferred data is acquired by the JavaScript engine, comprising: acquiring, by the JavaScript engine, the initial to-be-transferred data; and in the case where data of a first type exists in the initial to-be-transferred data, acquiring, by the JavaScript engine, the data of the first type as the first to-be-transferred data.
[0022] In a possible implementation, the reading, by the NAPI component of the operating system, of the first to-be-transferred data from the target shared memory space and the type conversion of the first to-be-transferred data into a corresponding second type to obtain target data comprises: calling, by the NAPI component, a reading interface for reading data in the target shared memory space, and reading, by the reading interface, attribute information of the first to-be-transferred data from a header field configured in the target shared memory space, the attribute information comprising a type of the first to-be-transferred data, an index of the first to-be-transferred data in initial to-be-transferred data, and a length of the first to-be-transferred data; reading, by the reading interface, the first to-be-transferred data from a data field configured in the target shared memory space based on a starting write position and the length of the first to-be-transferred data; converting, by the reading interface, the type of the first to-be-transferred data into the corresponding second type to obtain converted first to-be-transferred data; and determining, by the NAPI component, the target data based on the converted first to-be-transferred data and the index of the first to-be-transferred data in the initial to-be-transferred data.
[0023] The above scheme can transfer the first to-be-transferred data to the NAPI component in the manner of shared memory, and then the NAPI component can read the first to-be-transferred data from the target shared memory space through the reading interface and convert the type of the first to-be-transferred data to obtain the converted first to-be-transferred data. The first to-be-transferred data does not need to be transferred to the NAPI component through multiple data transfer layers as in the related art, which simplifies the data transfer process, reduces the time consumed in the data transfer process, and improves the data transfer efficiency.
[0024] In a possible implementation, the initial to-be-transferred data is first-type data, and the NAPI component determines the target data based on the converted first to-be-transferred data and the index of the first to-be-transferred data in the initial to-be-transferred data, comprising: sorting, by the NAPI component, multiple converted first to-be-transferred data corresponding to multiple first to-be-transferred data in the initial to-be-transferred data based on the indexes of the multiple first to-be-transferred data in the initial to-be-transferred data, to obtain the target data.
[0025] In a possible implementation, the initial to-be-transferred data contains data of types other than the first type, and the method further comprises: taking, by the JavaScript engine, the data of types other than the first type in the initial to-be-transferred data as second to-be-transferred data, and transferring the second to-be-transferred data to the NAPI component through the multiple data transfer layers in sequence; and performing, by the NAPI component, type conversion on the data transferred through the multiple data transfer layers to obtain third data.
[0026] In a possible implementation, the target data is determined based on the converted first to-be-transferred data and the index of the first to-be-transferred data in the initial to-be-transferred data by the NAPI component, including: the converted first to-be-transferred data and the third data are sorted and spliced based on the index of the first to-be-transferred data in the initial to-be-transferred data and the index of the second to-be-transferred data in the initial to-be-transferred data by the NAPI component, to obtain the target data.
[0027] The above scheme can transfer the first to-be-transferred data to the NAPI component in the form of shared memory, and transfer the second to-be-transferred data to the NAPI component through multiple data transfer layers. Subsequently, the NAPI component respectively converts the two parts of data, and splices the converted two parts of data to obtain complete data of the corresponding C++ type (i.e., the target data). In this way, the integrity of the data in the data transfer process is ensured, and since only part of the data (i.e., the second to-be-transferred data) is transferred through multiple data transfer layers, compared with transferring all data through multiple data transfer layers, the time consumed in the data transfer process is reduced, and the data transfer efficiency is improved.
[0028] In a possible implementation, the target interface for applying for a shared memory space is called by the JavaScript engine, and the target shared memory space is applied for through the target interface.
[0029] In a possible implementation, the destructor is called through the reading interface for reading the data in the target shared memory space, and the target data is cleared or the target shared memory space is released.
[0030] The above scheme can automatically call the destructor, so that the resources occupied by the target data, the first to-be-transferred data, or the target shared memory space can be released in time and correctly when the target data, the first to-be-transferred data, or the target shared memory space is no longer needed, thereby improving the stability and performance of the system.
[0031] In a second aspect, an embodiment of the present application provides an electronic device, the electronic device comprising a processor and a memory, the memory being configured to store a computer program, and the processor being configured to call and run the computer program from the memory, so that the electronic device executes the method of any one of the first aspect.
[0032] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, the processor executes the method of any one of the first aspect.
[0033] In a fourth aspect, an embodiment of the present application provides a computer program product, which comprises computer program codes, and when the computer program codes are run by an electronic device, the electronic device executes any of the methods in the first aspect.
[0034] In a fifth aspect, an embodiment of the present application provides a chip system, which comprises processing circuitry and a storage medium, and the storage medium stores computer program instructions; and the computer program instructions are executed by the processing circuitry to implement any of the methods in the first aspect.
[0035] Optionally, the processing circuitry in the chip system can be replaced by a processor, and the storage medium can be replaced by a memory. Optionally, the chip system can further comprise a communication interface, which is configured to realize communication between the chip system and an external device.
[0036] The beneficial effects of the technical solutions in the second aspect to the fifth aspect of the present application can refer to the beneficial effects of the technical solutions in the first aspect, which will not be described here. BRIEF DESCRIPTION OF DRAWINGS
[0037] FIG. 1 is a structural schematic diagram of an electronic device according to an embodiment of the present application;
[0038] FIG. 2 is a software structure block diagram of the electronic device 100 according to an embodiment of the present application;
[0039] FIG. 3 is a flow diagram of data transmission from a web end to a Native end in the related art.
[0040] FIG. 4 is a flow diagram of a data transmission method according to an embodiment of the present application;
[0041] FIG. 5 is a flow diagram of another data transmission method according to an embodiment of the present application;
[0042] FIG. 6 is a schematic diagram of a web page in a data transmission method according to an embodiment of the present application;
[0043] FIG. 7 is a data memory layout diagram of a target shared memory space in a data transmission method according to an embodiment of the present application;
[0044] FIG. 8 is a structural schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0045] The technical solutions in the embodiments of the present application will be described below with reference to the accompanying drawings.
[0046] In the description of the embodiments of the present application, unless otherwise specified, " / " represents the meaning of or; for example, A / B can represent A or B; "and / or" herein is only a description of the relationship between the associated objects, which means that there can be three relationships TU 8; for example, A and / or B, which can represent three cases: A exists alone, A and B exist simultaneously, or B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0047] Hereinafter, the terms "first", "second", "third" are only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second", "third" can explicitly or implicitly include one or more of the features.
[0048] The embodiments of the present application provide an electronic device for performing the data transmission method provided by the present application. In some embodiments of the present application, the electronic device can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., or can be other devices or apparatuses capable of data transmission. The specific type of the electronic device is not limited in the embodiments of the present application.
[0049] Exemplarily, FIG. 1 is a structural schematic diagram of an electronic device provided by an embodiment of the present application.
[0050] As shown in FIG. 1, the electronic device 100 can 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 headset interface 170D, a sensor module 180, a key 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 can include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light 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.
[0051] It can be understood that the structure shown in the embodiments of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 can include more or fewer components than shown, or combine certain components, or split certain components, or different arrangement of components. The components shown can be implemented in hardware, software, or a combination of software and hardware.
[0052] The processor 110 can include one or more processing units, for example: the processor 110 can include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units can be independent devices, or can be integrated in one or more processors.
[0053] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to instruction operation codes and timing signals, and complete the control of fetching instructions and executing instructions.
[0054] The processor 110 can also include memory that stores instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The cache memory can hold instructions or data that the processor 110 has recently used or is likely to use again. If the processor 110 needs to use the instructions or data again, it can be retrieved directly from the cache memory. This avoids repeated accesses to the main memory, reducing the latency of the processor 110 and thus improving the efficiency of the system.
[0055] The processor 110 and the display screen 194 communicate through a DSI interface to implement the display function of the electronic device 100.
[0056] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor, etc.
[0057] The antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals. The structure of the antenna 1 and the antenna 2 in FIG. 1 is only an example. Each antenna in the electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example, the antenna 1 can be multiplexed as a diversity antenna of a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0058] The electronic device 100 implements the display function through the GPU, the display screen 194, and the application processor, etc. 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 for graphics rendering. The processor 110 can include one or more GPUs that execute program instructions to generate or change display information.
[0059] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can adopt 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 Miniled, a MicroLed, a Micro-oLed, a quantum dot light emitting diodes (QLED), etc. In some embodiments, the electronic device 100 can include 1 or N display screens 194, N being a positive integer greater than 1.
[0060] The external memory interface 120 can be configured to connect an external memory card, such as a Micro SD card, to extend the storage capability of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to store data. For example, music, video, and other files can be stored in the external memory card.
[0061] The pressure sensor 180A is configured to sense a pressure signal and convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be disposed on the display screen 194.
[0062] The touch sensor 180K, also referred to as a "touch panel". The touch sensor 180K can be disposed on the display screen 194, and the touch sensor 180K and the display screen 194 together form a touch screen, also referred to as a "touch screen".
[0063] The keys 190 include a power key, a volume key, and the like. The keys 190 can be mechanical keys. Alternatively, the keys 190 can be touch keys. The electronic device 100 can receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0064] The software system of the electronic device 100 can adopt a layered architecture. In this embodiment, the HarmonyOS system is taken as an example to illustrate the software architecture of the electronic device 100. It should be understood that the scheme provided in this application can also be applied to other types of operating systems, such as the Android operating system, the Apple operating system, and the Windows operating system.
[0065] FIG. 2 is a schematic diagram of the software structure of the electronic device 100 according to an embodiment of the present application.
[0066] In some embodiments, The system includes four layers, from bottom to top, a kernel layer, a system foundation service layer, a framework layer, and an application layer.
[0067] The system adopts a multi-kernel design, and optionally includes a Linux kernel, a microkernel, and a lightweight Internet of Things operating system kernel (LiteOS). Through this design, devices with different device capabilities can select appropriate system kernels. The kernel layer further includes a kernel abstract layer, which provides basic kernel capabilities, such as process management, thread management, memory management, file system management, network management, and peripheral management, to other layers.
[0068] The system foundation service layer is The system's core capabilities support In multi-device deployment scenarios, the system provides application services through a framework layer. This layer may optionally include the following components:
[0069] System basic capability subsystem set: for distributed applications in The system provides fundamental capabilities for operation, scheduling, and migration across multiple devices, comprising 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 including C / C++ / JavaScript, as well as basic system class 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).
[0070] Basic software service subsystem set: for The system provides common, general-purpose software services, comprising subsystems such as graphics and image processing, distributed media, distributed AI, multimodal input, mobile sensing development platform (MSDP) & device virtualization (DV) technology, event notification, telephony services, and design for X (DFX) for non-functional product attributes. The basic software service subsystem set can be tailored to different deployment environments based on device types, and each subsystem can be customized according to functional granularity.
[0071] Enhanced software service subsystem set (see the enhanced software section highlighted by the dashed line in Figure 2): for The system provides differentiated enhanced software services for different devices, consisting of subsystems such as tablet business software, smart screen business software, in-vehicle business software, and Internet of Things (IoT) business software. The enhanced software service subsystem set can be tailored to the deployment environment of different device forms, at the subsystem level, and each subsystem can be further tailored at the functional level.
[0072] Driver framework ( Driver Foundation (HDF) and Hardware Abstraction Layer (HAL): are... The system's hardware ecosystem is the foundation for openness, providing hardware capability abstraction at the top and development frameworks and runtime environments for various peripheral drivers at the bottom.
[0073] Hardware service subsystem set: for The system provides common, adaptable hardware services, consisting of subsystems for general-purpose sensors, location, power, USB, and biometrics. The hardware service subsystem set can be tailored to different deployment environments based on device form factors, and each subsystem can be customized at a functional level.
[0074] Proprietary hardware service subsystem (see the proprietary hardware section outlined in dashed lines in Figure 2): for The system provides differentiated hardware services for different devices, including optional subsystems such as tablet-specific hardware services, vehicle-specific hardware services, wearable-specific hardware services, and IoT-specific hardware services. The proprietary hardware service subsystems can be tailored at the subsystem level, and each subsystem can be tailored at the functional level.
[0075] The framework layer is The system's applications provide user program frameworks and meta-capability frameworks in multiple languages such as Java, C, C++, and JavaScript, as well as multi-language application programming interfaces (APIs) for various software and hardware services.
[0076] The application layer includes system applications and third-party applications (or extended applications), which may include applications such as camera, gallery, calendar, calling, drawing applications, navigation, WLAN, music, video, and SMS. Applications in the system are built upon atomic ability (AA) and feature ability (FA).
[0077] The following is an explanation of the relevant technical terms used in this application.
[0078] 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.
[0079] Web (World Wide Web), also known as the World Wide Web: It is a global, dynamic interactive, cross-platform distributed graphical information system based on hypertext and hypertext transfer protocol (HTTP). It relies on the Internet, a global computer network, to provide users with a graphical, intuitive and easy-to-access interface, allowing users to easily search, browse and interact with various information resources on the Internet.
[0080] JavaScript Bridge, abbreviated as JSB: A bridge technology for connecting different technology platforms and languages. Specifically, it allows interaction between the web side and the native side.
[0081] For example, the Native side and the web side can be two parts of the code of an application; during the running of the application, the web side and the Native side can be associated through the JSB.
[0082] Webview: A component that embeds web content in a mobile application, allowing developers to embed web content (such as HTML pages, Cascading Style Sheets (CSS), or JavaScript-written web pages) directly into the application interface, enabling the loading and display of web pages.
[0083] ETS (Extended TypeScript) layer: used to handle the user interface and business logic of the application. ETS is an application development language in the ecosystem.
[0084] JavaScript engine: A virtual machine that specializes in handling JavaScript scripts, responsible for parsing and executing JavaScript code.
[0085] V8 engine: A JavaScript engine that can convert JavaScript code into machine code through just-in-time compilation, thereby improving the execution speed of JavaScript code.
[0086] Native Application Programming Interface (NAPI) component: is an interface developed based on the native language of the operating system. Through the NAPI component, JS code and C / C++ code can access each other. The application can use the capabilities provided by the operating system by directly or indirectly calling the NAPI interface to achieve the business requirements of the application. For example, for some operating systems, the native programming language can include one or more of C, C++, Objective-C, Swift, Java, Kotlin, JS, or ETS.
[0087] Chromium layer, also known as Chromium: is an open source web browser project that provides most of the functionality of the browser, including tab management, user interface rendering, network communication, etc.
[0088] CEF (Chromium Embedded Framework) layer: is an open source project based on Chromium. The CEF layer provides tight integration with Chromium, allowing the host application to embed and render web content.
[0089] Nweb layer: is a Native engine for web components built based on CEF, which can load and display web page content.
[0090] JS (JavaScript) object: is one of the core data types in the JavaScript language for storing and organizing data.
[0091] The following describes the data transmission method provided by the embodiments of the present application in detail taking an electronic device with the structure shown in FIG. 1 and FIG. 2 as an example.
[0092] Currently, in the process of transmitting data from the web end to the Native end, the data is first transmitted from the web end to the NAPI component provided by the operating system, and then the received data is transmitted to the Native end by the NAPI component. In the process of transmitting data from the web end to the NAPI component, multiple type conversions of programming languages are involved, which consumes a lot of time and reduces the data transmission efficiency. The following describes in detail the transmission of data from the web end to the NAPI component taking an operating system as an example. The following describes in detail the transmission of data from the web end to the NAPI component taking an operating system as an example.
[0093] Exemplarily, the web end can call the JSB through the Webview component, and pass the data to be transmitted to the NAPI component and transmitted to the Native end by the NAPI component through the JSB. In which, the passing of the data to be transmitted to the NAPI component through the JSB can be implemented by the following steps: the web end first passes the data to be transmitted to the V8 engine in the form of a JS object, then the V8 engine compiles and parses the JS object into a V8 Value object, and then the V8 Value object is transmitted from the V8 engine to the NAPI component through the Chromium layer, the CEF layer and the Nweb layer in turn. In this process, each layer (i.e. the Chromium layer, the CEF layer and the Nweb layer) needs to perform type conversion on the incoming data to ensure the transmissibility of the data.
[0094] Exemplarily, the CEF layer, the Nweb layer and the Chromium layer can be optional layers.
[0095] FIG. 3 is a flow diagram of the data transmission from the web end to the Native end in the related art. As shown in FIG. 3, the web end first passes the data to be transmitted to the V8 engine in the form of a JS object, and then the V8 engine compiles and parses the JS object into a V8 Value object. The V8 engine transmits the V8 Value object to the Chromium layer, which needs to convert the V8 Value object into the C++ type corresponding to the Chromium layer (referred to as Chromium type) so as to continue transmitting to the CEF layer. The CEF layer converts the data transmitted from the Chromium layer into the C++ type corresponding to the CEF layer (referred to as CEF type) so as to continue transmitting to the Nweb layer. The Nweb layer converts the data transmitted from the CEF layer into the C++ type corresponding to the Nweb layer (referred to as Nweb type) so as to continue transmitting to the NAPI component. Finally, the NAPI component converts the data transmitted from the Nweb layer so as to continue transmitting to the Native end. In which, the process of transmitting the data from the web end to the NAPI component involves multiple type conversions of programming languages, which consumes a lot of time, thereby increasing the time cost of the whole data transmission process, and further affecting the data transmission efficiency.
[0096] Based on this, the embodiment of the present application provides a data transmission method, which can apply a target shared memory space from a memory space, write the obtained first to-be-transmitted data into the target shared memory space through a JavaScript engine, the target shared memory space is used to store data of a first type, and the type of the first to-be-transmitted data belongs to the first type; then the first to-be-transmitted data can be directly read from the target shared memory space through an NAPI component, and the type of the first to-be-transmitted data is converted into a corresponding type (i.e. a second type), so as to obtain target data; finally, the target data is transmitted to a Native end through the NAPI component. In this way, the first to-be-transmitted data does not need to be transmitted to the NAPI component through multiple type conversions of a programming language as in the related art, the time consumed in the data transmission process is reduced, and the data transmission efficiency is improved. The JavaScript engine can be referred to as a web JavaScript engine.
[0097] Exemplarily, the operating system is Harmony, the JavaScript engine can be a V8 engine. The following describes the data transmission method provided by the embodiment of the present application in detail with the operating system being Harmony. Harmony, the JavaScript engine can be a V8 engine. The following describes the data transmission method provided by the embodiment of the present application in detail with the operating system being Harmony.
[0098] As shown in FIG. 4, the web end first gives the data to be transmitted to the V8 engine in the form of a JS object, and then the V8 engine compiles and parses the JS object into a V8 Value object. Next, the V8 engine writes the V8 Value object of the first type into the target shared memory space. The NAPI component calls a C++ API, and reads the V8 Value object of the first type from the target shared memory space through the C++ API, and performs type conversion on the V8 Value object to obtain a converted Value object, and determines the target data based on the converted Value object. The target data at least includes the converted V8 Value object, or the target data at least includes data obtained by processing the converted V8 Value object. The type of the converted V8 Value object is a C++ type corresponding to the type of the V8 Value object. The C++ API is an interface provided by the target shared memory space, which is used to read data in the target shared memory space and perform type conversion on the data.
[0099] The data transmission method provided in the embodiments of the present application can be applied to the scenario of interaction between an H5 page and a Native end. The H5 page is a specific web page, specifically, a web page developed using HTML technology and loaded and displayed by Webview. The data transmission method provided in the embodiments of the present application is exemplarily explained and described below in the scenario of interaction between an H5 page and a Native end.
[0100] When a user performs an operation (such as clicking a product detail button, selecting an option, etc.) on the H5 page of the web end, the Webview component responds to the user operation and invokes JSB to implement data transmission from the web end to the Native end. The data of the web end is, for example, a product identifier (ID) and the name of the product obtained in response to the user operation. The data of the web end is transmitted to the Native end through JSB. For example, the product ID and the name of the product are transmitted to the V8 engine in the form of a JS object. The V8 engine compiles and parses the JS object to obtain V8 Value objects. In a case where the types of the V8 Value objects belong to a first type, the V8 engine can write the V8 Value objects into a target shared memory space. Then, the NAPI component invokes a C++ API provided by the target shared memory space, reads the V8 Value objects from the target shared memory space through the C++ API, and performs type conversion on the V8 Value objects to obtain converted V8 Value objects. Finally, the NAPI component transmits the converted V8 Value objects to the Native end, or transmits the converted V8 Value objects to the Native end after processing.
[0101] Exemplarily, the first type includes one or more of the following: a Boolean type, an 8-bit unsigned integer type, an 8-bit signed integer type, a 16-bit unsigned integer type, a 16-bit signed integer type, a 32-bit unsigned integer type, a 32-bit signed integer type, a 64-bit unsigned integer type, a 64-bit signed integer type, a 32-bit floating point type, a 64-bit floating point type, a string, or binary data.
[0102] In the process of transmitting the data from the web end to the Native end, the V8 Value object of the first type is written into the target language-independent shared memory space first, and then the NAPI component cross-language extracts the V8 Value object from the target shared memory space and performs type conversion to transmit the data to the Native end. The V8 Value object of the first type does not need to be transmitted to the NAPI component through multiple type conversions across programming languages (such as type conversion in the Chromium layer, the CEF layer, and the Nweb layer) as in the related art, the number of type conversions across programming languages in the data transmission process is reduced, and thus the load of the entire data transmission link is reduced, and the data transmission speed and efficiency are improved.
[0103] FIG. 5 is a flowchart of another data transmission method provided by the embodiments of the present application. The data transmission method can be applied to an electronic device, and the electronic device is not limited to the specific order shown in FIG. 5. It should be understood that in other embodiments, the order of some steps of the method can be exchanged according to actual needs, or some steps can be omitted or deleted. The method can be applied to, but is not limited to, the scenario of interaction between an H5 page and a Native end. The method can be implemented by calling JSB from the web end. As shown in FIG. 5, the method includes S501-S504, and each step is explained and described in detail below.
[0104] S501, acquiring first to-be-transmitted data by using a JavaScript engine.
[0105] The first to-be-transmitted data is determined by a user interaction behavior or an automatic triggering mechanism on a web page of the web end. The JavaScript engine can also be referred to as a web JavaScript engine. The JavaScript engine can include but is not limited to a V8 engine and a Hermes engine. The data transmission method provided by the embodiments of the present application can be applied to different operating systems, and the JavaScript engines corresponding to different operating systems are different.
[0106] For example, when the data transmission method is applied to an iOS operating system, the JavaScript engine can be a V8 engine. When the data transmission method is applied to an Android operating system, the JavaScript engine can be a Hermes engine.
[0107] It should be understood that the user interaction behavior can be an operation performed by the user when interacting with an element on the web page. The operation can trigger the execution of the JavaScript code. The operation includes, but is not limited to, filling and submitting a form on the web page, clicking (such as clicking a button, a link, or a picture) on the web page, inputting text or selecting an option in an input box on the web page, dragging a page element using a mouse, and the like.
[0108] In the embodiment of the present application, the first to-be-transferred data can be obtained by the JavaScript engine. When the JavaScript engine is a V8 engine, the first to-be-transferred data can be a V8 Value object of the first type.
[0109] In a possible implementation, the electronic device obtains original to-be-transferred data (i.e., data that needs to be transferred) through a user interaction behavior or an automatic triggering mechanism on a web page of a web end. The web end provides the original to-be-transferred data to the JavaScript engine in the form of a JS object. The JavaScript engine can compile and parse the JS object to obtain an object corresponding to the JavaScript engine, and use the object corresponding to the JavaScript engine as initial to-be-transferred data. Subsequently, when the initial to-be-transferred data contains data of a first type, the data of the first type is used as the first to-be-transferred data.
[0110] Exemplarily, when the JavaScript engine is a V8 engine, the initial to-be-transferred data is a V8 Value object.
[0111] It should be understood that the automatic triggering mechanism allows the JavaScript code to be automatically executed without user intervention. Such a mechanism can use internal system logic, timer settings (such as using setlnterval or setTimeout to periodically trigger a function), or other automated processes to actively obtain the original to-be-transferred data. For example, a timer can be set to periodically execute a function to retrieve data from a data source (such as an API, a database, or a file), and the retrieved data can be used as the original to-be-transferred data. In addition, events of the browser or the system (such as window size adjustment, network status change, and the like) can be listened to, and when these events occur, the logic is automatically triggered to generate the original to-be-transferred data.
[0112] The following combined examples explain how to obtain the first to-be-transferred data by the JavaScript engine.
[0113] Exemplarily, the original data to be transmitted is determined by a user interaction behavior on a web page of a web end, and the first data to be transmitted is obtained by a JavaScript engine. As shown in a web page of FIG. 6, the web page is a page of collecting information of XXXX of company A, and the page includes a form, and the form is provided with three input fields of name, age and email address. When the user fills in the form and clicks a button of submitting data, the behavior triggers an event. The JavaScript code captures the submission event, obtains the data in the form, and takes the data in the form as the original data to be transmitted. Subsequently, a Webview component of the web end calls a JSB, encapsulates the original data to be transmitted into a JS object by the JSB, and gives the JS object to the JavaScript engine. The JavaScript engine can compile and parse the JS object into an object corresponding to the JavaScript engine, and take the object corresponding to the JavaScript engine as the initial data to be transmitted. Finally, in a case where the initial data to be transmitted includes the first type of data, the first type of data is taken as the first data to be transmitted.
[0114] Exemplarily, the original data to be transmitted is determined by an automatic triggering mechanism, and the first data to be transmitted is obtained by a JavaScript engine. The JavaScript code includes an automatic triggering mechanism, which periodically obtains data from a data source (such as an API), and takes the obtained data as the original data to be transmitted. Subsequently, a Webview component of the web end calls a JSB, encapsulates the original data to be transmitted into a JS object by the JSB, and gives the JS object to the JavaScript engine. The JavaScript engine can compile and parse the JS object into an object corresponding to the JavaScript engine, and take the object corresponding to the JavaScript engine as the initial data to be transmitted. Finally, in a case where the initial data to be transmitted includes the first type of data, the first type of data is taken as the first data to be transmitted.
[0115] Exemplarily, the initial data to be transmitted can be data required to be transmitted to a Native end by a function or a method of the JavaScript engine.
[0116] Optionally, the parameter list is obtained by the JavaScript engine, and data in the parameter list is taken as the initial data to be transmitted. The initial data to be transmitted is carried in the parameter list.
[0117] In a possible implementation, the first type includes one or more of the following:
[0118] 1) BOOL: represents a Boolean type, stored in 1 bit, which can be true (1) or false (0).
[0119] 2) UINT8: 8-bit unsigned integer. Its value ranges from 0 to 255 (i.e., 0 to 2 8 -1). Since it is unsigned, it cannot represent negative numbers.
[0120] 3) INT8: 8-bit signed integer. Its value ranges from -128 to 127. Unlike UINT8, INT8 can represent positive and negative numbers.
[0121] 4) UINT16: 16-bit unsigned integer. Its value ranges from 0 to 65535 (i.e., 0 to 2 16 -1).
[0122] 5) INT16: 16-bit signed integer. Its value ranges from -32768 to 32767.
[0123] 6) UINT32: 32-bit unsigned integer. Its value ranges from 0 to 429496725 (i.e., 0 to 2 32 -1).
[0124] 7) INT32: 32-bit signed integer. Its value ranges from -2147483648 to 2147483647.
[0125] 8) UINT64: 64-bit unsigned integer. Its value ranges from 0 to 18446744073709551615 (i.e., 2 64 -1).
[0126] 9) INT64: 64-bit signed integer. Its value ranges from -9223372036854775808 to 9223372036854775807.
[0127] 10) FLOAT: 32-bit floating point type. It is used to represent numbers with decimal parts, with limited precision and range.
[0128] 11) DOUBLE: 64-bit floating point type.
[0129] 12) STRING: string of arbitrary length. This represents a sequence of characters, with variable length, depending on the application or language limitations.
[0130] 13) BINARY: binary data of arbitrary length.
[0131] S502, write the first to-be-transferred data into the target shared memory space through the JavaScript engine.
[0132] The target shared memory space is used to store the first type of data, and the first type of data to be transmitted belongs to the first type.
[0133] In a possible implementation, the first type includes: a Boolean type, an 8-bit unsigned integer type, an 8-bit signed integer type, a 16-bit unsigned integer type, a 16-bit signed integer type, a 32-bit unsigned integer type, a 32-bit signed integer type, a 64-bit unsigned integer type, a 64-bit signed integer type, a 32-bit floating point type, a 64-bit floating point type, a string, and binary data.
[0134] In the embodiment of the application, the number of the first data to be transmitted can be at least one. The target shared memory space is a memory region space applied from the memory by the JavaScript engine. The target shared memory space is configured with a header field (i.e., a header field) and at least one data field (i.e., a 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 a plurality of attribute fields, and the attribute field at least includes a type field (i.e., a Type field). The data memory layout of the target shared memory space is determined by the header field and the data field configured by the target shared memory space.
[0135] Exemplarily, the target shared memory space can be a memory region used to buffer data when processing stream data, which can be represented by a flow buffer (Flowbuffer).
[0136] In a possible implementation, the target interface for applying the shared memory space can be called by the JavaScript engine, and the target shared memory space can be applied through the target interface.
[0137] Exemplarily, the target shared memory space is a Flowbuffer, and the target interface can be a Flowbuffer application programming interface (API).
[0138] In the embodiment of the application, the target shared memory space is configured with a header field and at least one data field, and the first data to be transmitted is written into the target shared memory space by the JavaScript engine in S502, which can be implemented in the following manner:
[0139] A write interface corresponding to the type of the first data to be transmitted is called by the JavaScript engine, and attribute information of the first data to be transmitted is written into the header field through the write interface, the attribute information including the type of the first data to be transmitted; the first data to be transmitted is written into a corresponding data field in the at least one data field through the write interface.
[0140] In a possible implementation, for different types of the first to-be-transferred data, there is a corresponding write interface through which the first to-be-transferred data and attribute information of the first to-be-transferred data can be written into the target shared memory space.
[0141] Exemplarily, taking the number of the first to-be-transferred data as 3 as an example, the three first to-be-transferred data are sequentially denoted as Data1, Data2 and Data3. The target shared memory space is Flowbuffer, and the write interface corresponding to the type of the first to-be-transferred data can be referred to as a 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 Flowbuffer and write Data1 into the corresponding data field in the at least one data field. Through the JavaScript engine, the FlowbufferStore interface corresponding to the type of Data2 can be called to write the attribute information of Data2 into the header field of Flowbuffer and write Data2 into the corresponding data field in the at least one data field. Through the JavaScript engine, the FlowbufferStore interface corresponding to the type of Data3 can be called to write the attribute information of Data3 into the header field of Flowbuffer and write Data3 into the corresponding data field in the at least one data field.
[0142] In the embodiment of the present application, the plurality of first to-be-transferred data can be written into the target shared memory space continuously, so as to ensure that the positions of the plurality of first to-be-transferred data in the target shared memory space are continuous. The corresponding data field in the at least one data field can be determined based on the write position of the first to-be-transferred data and the size of the first to-be-transferred data.
[0143] In a possible implementation, the first to-be-transferred data is written into the corresponding data field in the at least one data field through the write interface, and the writing can also be implemented in the following manner: the first to-be-transferred data is written into the corresponding data field in the at least one data field through the write interface based on the write position information corresponding to the first to-be-transferred data, the write position information indicating the starting write position of the first to-be-transferred data or the write position of the first to-be-transferred data. The write position includes the starting write position and the write end position.
[0144] The write position information of the first first to-be-transferred data in the plurality of first to-be-transferred data can be pre-set or randomly determined. The write position information of the first to-be-transferred data other than the first first to-be-transferred data in the plurality of first to-be-transferred data can be determined based on the write end position of the previous data.
[0145] Exemplarily, taking the number of the first to-be-transferred data as 3 as an example, the three first to-be-transferred data are sequentially represented 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 to the header field of the Flowbuffer; the starting write position of Data1 is 512 bytes, and 8 bytes of data of Data1 can be continuously written from the 512 byte position of the Flowbuffer until the end of Data1 is reached; wherein the starting write position of Data1 can be determined based on the 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 that the size of Data2 is also 8 bytes, since Data1 has occupied the space from 512 bytes to 519 bytes (including 519 bytes), the starting write position of Data2 can be the next byte of the write end position of Data1, that is, 520 bytes. Through the JavaScript engine, the FlowbufferStore interface corresponding to the type of Data2 can be called to write the attribute information of Data2 to the header field of the Flowbuffer, and 8 bytes of data of Data2 can be continuously written from the 520 byte position of the Flowbuffer. Finally, for Data3, assuming that the size of Data3 is also 8 bytes, since Data3 has occupied the space from 520 bytes to 527 bytes (including 527 bytes), the starting write position of Data3 can be the next byte of the write end position of Data2, that is, 528 bytes. Through the JavaScript engine, the FlowbufferStore interface corresponding to the type of Data3 can be called to write the attribute information of Data3 to the header field of the Flowbuffer, and 8 bytes of data of Data3 can be continuously written from the 528 byte position of the Flowbuffer.
[0146] In a possible implementation, the attribute information can further include the index of the first to-be-transferred data in the initial to-be-transferred data and / or the length of the first to-be-transferred data.
[0147] In a possible implementation, the attribute information includes a type of the first to-be-transferred data, an index of the first to-be-transferred data in the initial to-be-transferred data, and a length of the first to-be-transferred data, the header field of the target shared memory space configuration includes a plurality of groups of attribute fields, each group of attribute fields includes a type field (that is, a Type field), an index field (that is, an index field), and a length field (that is, a length field), and the attribute information of the first to-be-transferred data is written into the corresponding group of attribute fields in the header field by calling a write interface corresponding to the type of the first to-be-transferred data through a JavaScript engine and writing the attribute information of the first to-be-transferred data into the write interface, which can be implemented in the following manner:
[0148] The attribute information of the first to-be-transferred data is written into the corresponding group of attribute fields in the header field by calling a write interface corresponding to the type of the first to-be-transferred data through a JavaScript engine, and specifically, the type of the first to-be-transferred data, the index in the first to-be-transferred data, and the length of the first to-be-transferred data are written into the type field, the index field, and the length field of the corresponding group of attribute fields in the header field, respectively.
[0149] Exemplarily, taking the number of the first to-be-transferred data as 3 as an example, the three first to-be-transferred data are sequentially denoted as Data1, Data2, and Data3. In the process of writing Data1 into the target shared memory space, a FlowbufferStore interface corresponding to the type of Data1 can be called through a JavaScript engine, the type of Data1 is written into the type field of the first group of attribute fields in the header field, the index of Data1 is written into the index field of the first group of attribute fields, and the length of Data1 is written into the length field of the first group of attribute fields. In the process of writing Data2 into the target shared memory space, a FlowbufferStore interface corresponding to the type of Data2 can be called through a JavaScript engine, the type of Data2 is written into the type field of the second group of attribute fields in the header field, the index of Data2 is written into the index field of the second group of attribute fields, and the length of Data2 is written into the length field of the second group of attribute fields. Finally, in the process of writing Data3 into the target shared memory space, a FlowbufferStore interface corresponding to the type of Data3 can be called through a JavaScript engine, the type of Data3 is written into the type field of the third group of attribute fields in the header field, the index of Data3 is written into the index field of the third group of attribute fields, and the length of Data3 is written into the length field of the third group of attribute fields.
[0150] Optionally, in the case where the number of the first to-be-transferred data is one, the attribute information can be the type of the first to-be-transferred data.
[0151] Exemplarily, in a case that the number of the first to-be-transferred data is one, the first to-be-transferred data is written into any data field of the Flow buffer, and all data in the data field of the Flow buffer can be the first to-be-transferred data.
[0152] Optionally, in a case that the type of the first to-be-transferred data is multiple, the attribute information can be the type of the first to-be-transferred data, the index of the first to-be-transferred data in the initial to-be-transferred data, and the length of the first to-be-transferred data.
[0153] FIG. 7 is a schematic diagram of data memory layout of a target shared memory space in a data transferring method provided by an embodiment of the present application. As shown in FIG. 7, m first to-be-transferred data, data1, data2, …, data m, are written into at least one data field of the target shared memory space in sequence. The header field of the target shared memory space contains multiple groups of attribute fields, and the multiple groups of attribute fields are written in sequence to match the order of the data in the data field. As shown in FIG. 7, the type of data1 (data1 type), the index of data1 (data1 index), and the length of data1 (data1 length) are written into the first group of attribute fields, the type of data2 (data2 type), the index of data2 (data2 index), and the length of data2 (data2 length) are written into the second group of attribute fields, and the type of data m (data m type), the index of data m (data m index), and the length of data m (data m length) are written into the mth group of attribute fields.
[0154] In the embodiment of the present application, the target shared memory space can be constructed, written, modified, and destroyed by calling a group of APIs for the shared memory space in different language environments. The target shared memory space supports storing data of the first type. The group of APIs includes a target interface for applying (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 destruction of the target shared memory space.
[0155] S503, reading the first to-be-transferred data from the target shared memory space through the native application programming interface (NAPI) component, and converting the type of the first to-be-transferred data into a corresponding second type to obtain target data.
[0156] The second type belongs to a C++ type. The first type of the data to be transmitted is different, and the second type is different.
[0157] For example, the first type of the data to be transmitted is STRING, and the second type can be C++ STRING. The first type of the data to be transmitted is FLOAT, and the second type can be C++ FLOAT.
[0158] In the embodiment of the present application, the NAPI component can read the data in the data field in the target shared memory space to obtain the first data to be transmitted, and convert the type of the first data to be transmitted into a corresponding second type to obtain the target data.
[0159] In a possible implementation, the NAPI component reads the data in the header field of the target shared memory space to obtain attribute information of the first data to be transmitted, and the attribute information includes the type of the first data to be transmitted. Then, the NAPI component reads the data in the data field of the target shared memory space to obtain the first data to be transmitted. Next, the first data to be transmitted is converted based on the type of the first data to be transmitted to obtain converted first data to be transmitted. The type of the converted first data to be transmitted is a C++ type corresponding to the type of the first data to be transmitted. Then, the converted first data to be transmitted can be used as the target data, or the converted first data to be transmitted is processed to obtain the target data. The number of the first data to be transmitted can be one or more.
[0160] For example, if the number of the first data to be transmitted is one, the NAPI component can directly read the data in the data field in the target shared memory space, and use the read data as the first data to be transmitted.
[0161] For example, if the number of the first data to be transmitted is more than one, the NAPI component can read each first data to be transmitted based on information in the attribute information other than the type of the first data to be transmitted. For example, the information in the attribute information other than the type of the first data to be transmitted is the length of the first data to be transmitted.
[0162] In a possible implementation, the NAPI component reads the first data to be transmitted from the target shared memory space in S503, and converts the type of the first data to be transmitted into a corresponding second type to obtain the target data can be implemented in the following way:
[0163] The read interface is called by the NAPI component to read data in the target shared memory space, and the attribute information of the first to-be-transferred data is read from the header field configured in the target shared memory space through the read interface. The attribute information includes the type of the first to-be-transferred data, the index of the first to-be-transferred data in the initial to-be-transferred data, and the length of the first to-be-transferred data. The first to-be-transferred data 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 to-be-transferred data. The type of the first to-be-transferred data is converted into a corresponding second type through the read interface to obtain the converted first to-be-transferred data. The target data is determined based on the converted first to-be-transferred data and the index of the first to-be-transferred data in the initial to-be-transferred data through the NAPI component.
[0164] Exemplarily, the read interface can be a Flowbuffer C++ API, which can also be denoted as a C++ API. Through the C++ API, data in the first group of attribute fields in the header field configured in the target shared memory space can be read to obtain attribute information of data1, which includes the type of data1, the index of data1 in the initial to-be-transferred data, and the length of data1. Subsequently, data in the corresponding data field of the at least one data field configured in the target shared memory space is read based on the starting write position of data1 and the length of data1 to obtain data1. Then, data1 is converted into a corresponding C++ type based on the type of data1 to obtain converted data1; for example, the type of data1 is STRING, and the type of converted data1 is C++ STRING.
[0165] Exemplarily, if the number of the first to-be-transferred data is one, for example, data1, converted data1 can be used as the target data.
[0166] Exemplarily, if the number of the first to-be-transferred data is m, and the initial to-be-transferred data includes the m first to-be-transferred data. In the foregoing manner, converted data1, converted data2, …, and converted data m can be obtained through the C++ API. Subsequently, the target data is determined based on the index of data1 in the initial to-be-transferred data, the index of data2 in the initial to-be-transferred data, …, the index of data m in the initial to-be-transferred data, converted data1, converted data2, …, and converted data m.
[0167] In a possible implementation, in a case where the initial to-be-delivered data is first type data, the target data can be determined by the NAPI component based on the converted first to-be-delivered data and the index of the first to-be-delivered data in the initial to-be-delivered data, which can be implemented in the following manner: the NAPI component sorts the plurality of converted first to-be-delivered data corresponding to the plurality of first to-be-delivered data based on the index of the plurality of first to-be-delivered data in the initial to-be-delivered data, to obtain the target data.
[0168] Exemplarily, m is 3, the initial to-be-delivered data only contains three first to-be-delivered data, and the three first to-be-delivered data are data1, data2 and data3 respectively. The three converted first to-be-delivered data are converted data1, converted data2 and converted data3 respectively. The converted data1, converted data2 and converted data3 can be sorted based on the index of data1 in the initial to-be-delivered data, the index of data2 in the initial to-be-delivered data and the index of data3 in the initial to-be-delivered data, to obtain sorted data, and the sorted data is taken as the target data. The index of data1 in the initial to-be-delivered data represents the position of data1 in the initial to-be-delivered data, the index of data2 in the initial to-be-delivered data represents the position of data2 in the initial to-be-delivered data, and the index of data3 in the initial to-be-delivered data represents the position of data3 in the initial to-be-delivered data. Assuming that the order of data1, data2 and data3 is data2, data1 and data3 in turn based on the index of data1 in the initial to-be-delivered data, the index of data2 in the initial to-be-delivered data and the index of data2 in the initial to-be-delivered data, then the sorted data follows this order, that is, the order of converted data1, converted data2 and converted data3 in the sorted data is converted data2, converted data1 and converted data3 in turn. The sorted data can be taken as the target data, or the sorted data can be processed, and the data obtained after processing is taken as the target data.
[0169] There is data of a type other than the first type in the initial to-be-delivered data, and the data of the type other than the first type in the initial to-be-delivered data can be taken as second to-be-delivered data, and the number of the second to-be-delivered data can be at least one. The second to-be-delivered data can be delivered to the NAPI component by the JavaScript engine in the following manner:
[0170] The data of the types other than the first type existing in the initial to-be-delivered data is taken as second to-be-delivered data by the JavaScript engine, and the second to-be-delivered data is sequentially delivered to the NAPI component through the plurality of data delivery layers. Through the NAPI component, type conversion is performed on the data delivered through the plurality of data delivery layers to obtain third data.
[0171] Exemplarily, the second to-be-delivered data can be objects other than the V8 value objects of the first type in the V8 value object, and as shown in FIG. 3, the plurality of data delivery layers include a Chromium layer, a CEF layer, and an Nweb layer. The second to-be-delivered data can be delivered to the Chromium layer by the JavaScript engine first, and the Chromium layer needs to convert the second to-be-delivered data into data of a C++ type corresponding to the Chromium layer, so as to continue delivering to the CEF layer. Subsequently, the CEF layer converts the data delivered by the Chromium layer into data of a C++ type corresponding to the CEF layer, so as to continue delivering to the Nweb layer. Then, the Nweb layer converts the data delivered by the CEF layer into data of a C++ type corresponding to the Nweb layer, so as to continue delivering to the NAPI component. Finally, the NAPI component converts the data delivered by the CEF layer into data of a corresponding C++ type based on the type of the data, to obtain third data.
[0172] The above determination of the target data by the NAPI component based on the converted first to-be-delivered data and the index of the first to-be-delivered data in the initial to-be-delivered data can also be implemented in the following manner:
[0173] The NAPI component sorts and splices the converted first to-be-delivered data and the third data based on the index of the first to-be-delivered data in the initial to-be-delivered data and the index of the second to-be-delivered data in the initial to-be-delivered data, to obtain the target data.
[0174] Exemplarily, the number of the first to-be-delivered data is 3, the three first to-be-delivered data are data1, data2 and data3 respectively, the second to-be-delivered data is 2, and the two second to-be-delivered data are data4 and data5 respectively; the initial to-be-delivered data includes data1, data2, data3, data4 and data5. Based on the indexes of the five data in the initial to-be-delivered data, the order between the five data is determined as data2, data1, data3, data5 and data4. In accordance with the order, the converted data1, the converted data2, the converted data3, the converted data4 and the converted data5 are sorted to obtain sorted data, and the sorted data is spliced to obtain target data, or the sorted data is processed to obtain target data. The plurality of converted first to-be-delivered data includes the converted data1, the converted data2 and the converted data3, and the plurality of third data includes the converted data4 and the converted data5.
[0175] In accordance with the order, the converted data1, the converted data2, the converted data3, the converted data4 and the converted data5 are sorted to obtain sorted data, and the sorted data is spliced to obtain target data. Specifically, in accordance with the determined order, the converted data (i.e., the converted data2, the converted data1, the converted data3, the converted data5 and the converted data4) is added to a new list in sequence by using an append or insert operation, so as to ensure the accurate order between them. Finally, the data in the sorted list is spliced to obtain the final target data.
[0176] It should be understood that the sorted data is processed to obtain target data in this document, wherein the processing of the sorted data can be some internal business processing or other processing, and the processing performed by the embodiments of the present application on the sorted data is not limited.
[0177] The above scheme can pass the first to-be-transferred data to the NAPI component in a shared memory manner, and pass the second to-be-transferred data to the NAPI component in multiple data transfer layers. Then, the NAPI component respectively converts the two parts of data, and splices the converted two parts of data to obtain the target data. In this way, the integrity of the data in the data transfer process is ensured, and since only part of the data (i.e., the second to-be-transferred data) is transferred through multiple data transfer layers, compared with the related art in which all data is transferred through multiple data transfer layers, the number of type conversions of the data across programming languages in the data transfer process is reduced, thereby reducing the time consumed in the data transfer process and improving the data transfer efficiency.
[0178] S504, passing the target data to the Native end through the NAPI component.
[0179] The Native end is used to process the user interface and business logic of the application, and the user interface includes a web page.
[0180] Exemplarily, the Native end is an ETS layer.
[0181] In the embodiments of the present application, after S504, the method can further include: calling a destructor through a reading interface to clear the first to-be-transferred data, 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, and is used to release the resources occupied by the object. In this way, by automatically calling the destructor, the resources occupied by the target data, the first to-be-transferred data, or the target shared memory space can be released in time and correctly when they are no longer needed, so as to improve the stability and performance of the system.
[0182] The embodiment of the present application provides a data transmission method, realizes cross-language data transmission, and the method comprises the following steps: obtaining first to-be-transmitted data through a JavaScript engine, the first to-be-transmitted data is determined through user interaction behavior on a web page of a web end or an automatic triggering mechanism; writing the first to-be-transmitted data into a target shared memory space through the JavaScript engine, the target shared memory space is used for storing data of a first type, and the first type comprises the type of the first to-be-transmitted data; reading the first to-be-transmitted data from the target shared memory space through an NAPI component of an operating system, and converting the type of the first to-be-transmitted data into a corresponding second type to obtain target data; and transmitting the target data to a Native end through the NAPI component, wherein the Native end is used for processing the user interface and the business logic of an application, and the user interface comprises the web page. In this way, the first to-be-transmitted data does not need to be transmitted to the NAPI component through multiple type conversions of a programming language as in the related art, the time consumed in the data transmission process is reduced, and the data transmission efficiency is improved.
[0183] The above describes an example of the data transmission method provided by the present application. It can be understood that, in order to realize the above functions, the electronic device comprises a hardware structure and / or a software module corresponding to each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed in the present application, the present application can be realized in the form of hardware or a combination of hardware and computer software. Whether a certain function is realized in the form of hardware or 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 realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application. The present application can divide the functional units of the data transmission method according to the above method examples, for example, each function can be divided into a functional unit, or two or more functions can be integrated into one unit. The integrated unit can be realized in the form of hardware or software functional unit. It should be noted that the division of units in the present application is illustrative, and is only a logical functional division. When actually implemented, there can be another division method.
[0184] FIG. 8 is a structural schematic diagram of an electronic device provided by the embodiment of the present application. The dashed line in FIG. 8 indicates that the unit or the module is optional. The electronic device 8 can be used to realize the method described in the above method embodiment. The electronic device 8 can be an electronic device or a chip (system).
[0185] The electronic device 8 includes one or more processors 801, which can support the electronic device 8 to implement the data transmission method in the above-described method embodiments. The processor 801 can be a general-purpose processor or a special-purpose 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 a software program, and process data of the software program. The electronic device 8 can further include a communication unit 805 to implement input (reception) and output (transmission) of signals.
[0186] The electronic device 8 described above can be a chip (system) including a memory and a processor, where the processor is configured to execute a computer program stored in the memory to implement the method shown in each of the above-described embodiments.
[0187] The communication unit 805 can be an input and / or output circuit of the chip (system), or the communication unit 805 can be a communication interface of the chip (system), which can be a component of the electronic device 8.
[0188] For another example, the communication unit 805 can be a transceiver of the electronic device 8, or the communication unit 805 can be a transceiving circuit of the electronic device 8. The electronic device 8 can include one or more memories 802 having programs 804 stored thereon, where the programs 804 can be run by the processor 801 to generate instructions 803, so that the processor 801 executes the method described in the above-described method embodiments according to the instructions 803. Optionally, the memory 802 can further store data. Optionally, the processor 801 can further read the data stored in the memory 802, where the data can be stored in the same storage address as the programs 804, or the data can be stored in different storage addresses from the programs 804.
[0189] The processor 801 and the memory 802 can be separately arranged or integrated together, for example, integrated on a system on chip (SOC) of the electronic device. The specific implementation of the processor 801 to execute the data transmission method can be referred to the related description in the method embodiments.
[0190] It should be understood that each step of the above-described method embodiments can be completed by a logic circuit in the form of hardware or instructions in the form of software 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, for example, discrete gates, transistor logic devices, or discrete hardware components.
[0191] The application further provides a computer program product, which, when executed by the processor 801, implements the method of any method embodiment in the application. The computer program product can be stored in the memory 802, for example, a program 804, which is finally converted into an executable object file capable of being executed by the processor 801 through preprocessing, compiling, assembling, linking and the like processing procedures.
[0192] The application further provides a computer readable storage medium, which stores a computer program, and the computer program, when executed by a computer, implements the method of any method embodiment in the application. The computer program can be a high-level language program or an executable object program.
[0193] The computer readable storage medium is, for example, the memory 802. The memory 802 can be a volatile memory or a non-volatile memory, or the memory 802 can include both volatile memory and non-volatile memory. The non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM) or a flash memory. The volatile memory can be a random access memory (RAM) used as an external cache. By way of example, but not limitation, many forms of RAM can be used, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchlink dynamic random access memory (SLDRAM) and direct Rambus RAM (DRRAM).
[0194] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described apparatus and device and the generated technical effects can refer to the corresponding processes and technical effects in the foregoing method embodiments, which will not be described here.
[0195] In several embodiments provided in the present application, the disclosed system, device and method can be implemented in other manners. For example, some features of the above-described method embodiments can be omitted, or can not be executed. The above-described device embodiments are merely illustrative, and the split of units is merely logical function split, and there can be another split manner in actual implementation. Multiple units or components can be combined or integrated into another system, or some features can be left out or not executed. In addition, coupling or connection between the units, or the components can be direct or indirect, and can be electrical, mechanical or in other forms.
[0196] The above-described embodiments are merely used to illustrate the technical solutions of the present application, rather than limit the same. Although the present application is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalent features, and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A data transfer method, characterized by, The method is applied to an electronic device and comprises: acquiring, by a JavaScript engine, first to-be-transferred data, the first to-be-transferred data being determined by a user interaction behavior on a web page of a web end or an automatic triggering mechanism; writing, by the JavaScript engine, the first to-be-transferred data into a target shared memory space, the target shared memory space being used to store data of a first type, and a type of the first to-be-transferred data belonging to the first type; reading, by a native application programming interface (NAPI) component of an operating system, the first to-be-transferred data from the target shared memory space and converting a type of the first to-be-transferred data into a corresponding second type to obtain target data; transferring, by the NAPI component, the target data to a Native end, wherein the Native end is used to process a user interface and business logic of an application; and the user interface comprises the web page.
2. The method of claim 1, wherein, The target shared memory space is configured with a header field and at least one data field, and the writing, by the JavaScript engine, of the first to-be-transferred data into the target shared memory space comprises: calling, by the JavaScript engine, a write interface corresponding to the type of the first to-be-transferred data and writing, by the write interface, attribute information of the first to-be-transferred data into the header field, the attribute information comprising the type of the first to-be-transferred data; writing, by the write interface, the first to-be-transferred data into a corresponding data field of the at least one data field.
3. The method of claim 2, wherein, The writing, by the write interface, of the first to-be-transferred data into the corresponding data field of the at least one data field comprises: writing, by the write interface, the first to-be-transferred data into the corresponding data field of the at least one data field based on write position information corresponding to the first to-be-transferred data, the write position information indicating a starting write position of the first to-be-transferred data.
4. The method according to claim 2 or 3, characterized in that, The attribute information further comprises an index of the first to-be-transferred data in initial to-be-transferred data and a length of the first to-be-transferred data.
5. The method according to any one of claims 1 to 4, characterized in that, The acquiring, by the JavaScript engine, of the first to-be-transferred data comprises: acquiring, by the JavaScript engine, the initial to-be-transferred data; in a case where data of the first type exists in the initial to-be-transferred data, taking the data of the first type as the first to-be-transferred data.
6. The method of claim 5, wherein, The reading, by the NAPI component of the operating system, of the first to-be-transferred data from the target shared memory space and the converting of the type of the first to-be-transferred data into the corresponding second type to obtain the target data comprise: reading, by the NAPI component, an attribute of the first to-be-transferred data from a header field configured in the target shared memory space through a read interface for reading data in the target shared memory space, the attribute including a type of the first to-be-transferred data, an index of the first to-be-transferred data in the initial to-be-transferred data, and a length of the first to-be-transferred data; reading, by the NAPI component, the first to-be-transferred data from a data field configured in the target shared memory space based on the start write position of the first to-be-transferred data and the length through the read interface; converting, by the NAPI component, the type of the first to-be-transferred data into a corresponding second type to obtain converted first to-be-transferred data; determining, by the NAPI component, the target data based on the converted first to-be-transferred data and the index of the first to-be-transferred data in the initial to-be-transferred data.
7. The method of claim 6, wherein, The initial to-be-transferred data is data of a first type. The determining, by the NAPI component, the target data based on the converted first to-be-transferred data and the index of the first to-be-transferred data in the initial to-be-transferred data includes: sorting, by the NAPI component, a plurality of converted first to-be-transferred data corresponding to a plurality of first to-be-transferred data in the initial to-be-transferred data based on the indexes of the plurality of first to-be-transferred data in the initial to-be-transferred data to obtain the target data.
8. The method of claim 6, wherein, The initial to-be-transferred data includes data of a type other than the first type, and the method further includes: transferring, by the JavaScript engine, the data of the type other than the first type existing in the initial to-be-transferred data as second to-be-transferred data, and sequentially transferring the second to-be-transferred data to the NAPI component through a plurality of data transfer layers; performing, by the NAPI component, type conversion on data transferred through the plurality of data transfer layers to obtain third data; Correspondingly, the determining, by the NAPI component, the target data based on the converted first to-be-transferred data and the index of the first to-be-transferred data in the initial to-be-transferred data includes: sorting and splicing, by the NAPI component, the converted first to-be-transferred data and the third data based on the index of the first to-be-transferred data in the initial to-be-transferred data and the index of the second to-be-transferred data in the initial to-be-transferred data to obtain the target data.
9. The method according to any one of claims 1 to 8, characterized in that, The method further includes: calling, by the JavaScript engine, a target interface for applying for a shared memory space, and applying for 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: a Boolean type, an 8-bit unsigned integer type, an 8-bit signed integer type, a 16-bit unsigned integer type, a 16-bit signed integer type, a 32-bit unsigned integer type, a 32-bit signed integer type, a 64-bit unsigned integer type, a 64-bit signed integer type, a 32-bit floating point type, a 64-bit floating point type, a string, or binary data.
11. An electronic device, comprising: The method further includes: A processor coupled with a memory for storing a program or instructions that, when executed by the processor, cause the electronic device to perform the method of any one of claims 1-10.
12. A chip system, characterized by The chip system comprises a memory and a processor configured to execute a computer program stored in the memory to implement the method of any one of claims 1-10.
13. A computer readable storage medium having stored thereon a computer program or instructions, characterized in that, The computer program or instructions, when executed, cause a computer to perform the method of any one of claims 1-10.
14. A computer program product, characterised in that, Computer program instructions, which cause the computer to perform the method of any one of claims 1-10.
Citation Information
Patent Citations
Data interaction method and device, electronic equipment and storage medium
CN116541185A
Data transmission method and related device
CN117931465A
JsBridge communication method and device during running of small swan gap program and storage medium
CN118331765A