Data processing method and related device
By converting the original code library file into a target code library file suitable for the running environment of the applet, the problem that third-party libraries in the applet cannot be run directly is solved, and the code portability and development efficiency are improved.
Patent Information
- Application Number
- CN202311207923.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-15
- Publication Date
- 2025-03-18
AI Technical Summary
In the applet running environment, many third-party libraries cannot be run directly, and developers need to make large changes to the source code to adapt to the applet environment, resulting in large workloads and error-prone.
By obtaining the original code base file, creating the target object and the target object code segment, generating the object instance combination, creating a global object and merging its code segments, generating the target code base file suitable for the target running environment, without modifying the original code.
It realizes portability and maintainability of running code in different running environments, simplifies the development process, reduces the risk of errors, and improves the efficiency and readability of the code.
Smart Images

Figure CN119645407A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data processing method and related devices. Background Art
[0002] In the process of building programs based on the browser environment, implementing some functions in the program through many excellent third-party libraries can help program developers develop programs faster and more efficiently. However, since the mini-program operating environment is different from the browser environment, many third-party libraries used in the browser environment cannot be directly run in the mini-program. Even if the developer of the third-party library provides a compatible version, the developer needs to make a lot of changes to the source code of the third-party library. It is necessary to find all the compatibility processing points in the source code of the third-party library, and then perform complex logic replacement to adapt to the mini-program operating environment. However, this method of modifying the existing source code is labor-intensive and error-prone, and has high requirements for developers, which greatly increases the development time. Summary of the invention
[0003] The embodiment of the present application provides a data processing method and related devices, which convert a third-party original code library file into a target code library file that can be used in a target operating environment without modifying the original code, thereby improving development efficiency.
[0004] One aspect of the present application provides a data processing method, comprising:
[0005] Obtaining an original code library file to be processed, wherein the original code library file is used in an original running environment, the original code library file includes M original objects and M original object code segments corresponding to the M original objects, the M original objects correspond to M functions, and the functions corresponding to the original objects are realized by running the original object code segments, where M is an integer greater than or equal to 1;
[0006] Create M target objects, and generate M target object code segments corresponding to the M target objects according to the M original object code segments, wherein the M target objects have a corresponding relationship with the M original objects;
[0007] Running the M target object codes to generate an object instance combination, wherein the object instance combination includes M object instances;
[0008] According to the object instance combination, a global object is created, and according to the global object, a global object code segment is generated, wherein the global object is used to realize access to M target objects;
[0009] The global object code segment is merged with the original code library file to generate a target code library file, wherein the target code library file is used in the target operating environment.
[0010] Another aspect of the present application provides a data processing device, including: an original code library file acquisition module, a target object and target object code segment generation module, an object instance generation module, a global object and global object code segment generation module and a target code library file generation module; specifically:
[0011] an original code library file acquisition module, used to acquire an original code library file to be processed, wherein the original code library file is used in an original running environment, the original code library file includes M original objects and M original object code segments corresponding to the M original objects, the M original objects correspond to M functions, and the functions corresponding to the original objects are realized by running the original object code segments, where M is an integer greater than or equal to 1;
[0012] A target object and target object code segment generating module, used for creating M target objects, and generating M target object code segments corresponding to the M target objects according to the M original object code segments, wherein the M target objects have a corresponding relationship with the M original objects;
[0013] An object instance generation module, used for running the M target object codes to generate an object instance combination, wherein the object instance combination includes M object instances;
[0014] A global object and global object code segment generation module is used to create a global object according to the object instance combination, and to generate a global object code segment according to the global object, wherein the global object is used to realize the access to M target objects;
[0015] The target code library file generation module is used to merge the global object code segment with the original code library file to generate a target code library file, wherein the target code library file is used in the target operating environment.
[0016] In another implementation of the embodiment of the present application, the target object and target object code segment generation module is further used to:
[0017] Determine the document object programming interface information of the original operating environment according to the original code library file;
[0018] Create an agent operating environment based on the document object programming interface information;
[0019] Create M target objects in the agent running environment;
[0020] M target object code segments used by the M target objects in the proxy execution environment are generated according to the M original object code segments.
[0021] In another implementation of the embodiment of the present application, the target object and target object code segment generation module is further used to:
[0022] Obtaining M original logic information corresponding to the M original object code segments when they are running in the original running environment, wherein the original logic information is used to represent the running logic of the original object code segments in the original running environment;
[0023] Generate M target logic information according to the M original logic information, wherein the target logic information is used to represent the operation logic of the target object in the agent operation environment;
[0024] Generate M target object code segments according to the M target logic information.
[0025] In another implementation of the embodiment of the present application, the object instance generation module is further used to:
[0026] Run the M target object codes in the proxy runtime environment to generate M object instances;
[0027] Merge M object instances to generate an object instance combination.
[0028] In another implementation of the embodiment of the present application, the object instance generation module is further used to:
[0029] Create a context runtime function in the agent runtime;
[0030] Bind the following running environment function to the global object to generate a global object code segment.
[0031] In another implementation of the embodiment of the present application, the target code library file generation module is further used to:
[0032] Determine the file insertion position in the global object code segment;
[0033] Insert the original code library file into the file insertion position to generate the target code library file.
[0034] In another implementation of the embodiment of the present application, the data processing device further includes: an obfuscation module and an export module; specifically:
[0035] The obfuscation module is used to perform obfuscation processing on the target code library file to reduce the amount of code in the target code library file and generate a target code package file;
[0036] The export module is used to package the target code file for export.
[0037] In another implementation of the embodiment of the present application, the target object and target object code segment generation module is further used to:
[0038] Create a canvas object, where the canvas object is one of the M target objects;
[0039] Define the target type attribute of the canvas object corresponding to the target operating environment;
[0040] Get the original canvas object code segment in the original running environment of the canvas object;
[0041] The original canvas object code segment is updated according to the target type attribute to generate a target canvas object code segment corresponding to the canvas object, wherein the canvas object target code segment is one of the M target object code segments.
[0042] In another implementation of the embodiment of the present application, the target object and target object code segment generation module is further used to:
[0043] Creating a first picture object and a second picture object, wherein the first picture object is one of the M target objects, the second picture object is one of the M target objects, and the type corresponding to the first picture object is different from the type corresponding to the second picture object;
[0044] Setting attribute information of the first picture object, and setting attribute information of the second picture object, wherein the attribute information includes location information of the picture object;
[0045] Calling back the attribute information of the first picture object and the attribute information of the second picture object to generate a first target picture object code segment corresponding to the first picture object, wherein the first target picture object code segment is one of the M target object code segments;
[0046] The attribute information of the second picture object and the attribute information of the second picture object are called back to generate a second target picture object code segment corresponding to the second picture object, wherein the second target picture object code segment is one of the M target object code segments.
[0047] In another implementation of the embodiment of the present application, the target object and target object code segment generation module is further used to:
[0048] Create a network request object, where the network request object is one of the M target objects;
[0049] Configure the properties of the network request object, where the properties of the network request object include event distribution and message acquisition;
[0050] The properties of the network request object are called back to generate a network request object code segment, wherein the network request object code segment is one of the M target object code segments.
[0051] In another implementation of the embodiment of the present application, the target object and target object code segment generation module is further used to:
[0052] Create an event mechanism object, where the event mechanism object is one of the M target objects;
[0053] Obtaining an object instance corresponding to the event mechanism object, wherein the object instance corresponding to the event mechanism object is obtained by running the event mechanism object in a target running environment;
[0054] An event mechanism object code segment is generated according to the object instance corresponding to the event mechanism object, wherein the event mechanism object code segment is one of the M target object code segments.
[0055] Another aspect of the present application provides a computer device, comprising:
[0056] memories, transceivers, processors, and bus systems;
[0057] Wherein, the memory is used to store programs;
[0058] The processor is used to execute the program in the memory, including executing the above-mentioned methods;
[0059] The bus system is used to connect the memory and the processor so that the memory and the processor can communicate with each other.
[0060] Another aspect of the present application provides a computer-readable storage medium, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer is enabled to execute the above-mentioned methods.
[0061] Another aspect of the present application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided by the above aspects.
[0062] It can be seen from the above method that the embodiment of the present application has the following advantages:
[0063] The present application provides a data processing method and a related device, the method comprising: first, obtaining an original code library file to be processed, wherein the original code library file is used in an original operating environment, the original code library file includes M original objects and M original object code segments corresponding to the M original objects, the M original objects correspond to M functions, and the functions corresponding to the original objects are realized by running the original object code segments; second, creating M target objects, and generating M target object code segments corresponding to the M target objects according to the M original object code segments, wherein the M target objects have a corresponding relationship with the M original objects; then, running the M target object codes to generate an object instance combination, wherein the object instance combination includes M object instances; then, creating a global object according to the object instance combination, and generating a global object code segment according to the global object, wherein the global object is used to realize access to the M target objects; finally, merging the global object code segment with the original code library file to generate a target code library file, wherein the target code library file is used in a target operating environment. The method provided in the embodiment of the present application converts multiple original objects in the original code library file into a target code library file suitable for the target operating environment, so that the code can be run in different environments, improving the portability and maintainability of the code; at the same time, the creation of global objects also facilitates the access and management of multiple target objects, improving the efficiency and readability of code operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 A schematic diagram of the architecture of a data processing system provided for a certain embodiment of the present application;
[0065] Figure 2 A flowchart of a data processing method provided in an embodiment of the present application;
[0066] Figure 3 A flowchart of a data processing method provided by another embodiment of the present application;
[0067] Figure 4 A flowchart of a data processing method provided by another embodiment of the present application;
[0068] Figure 5 A flowchart of a data processing method provided by another embodiment of the present application;
[0069] Figure 6 A flowchart of a data processing method provided by another embodiment of the present application;
[0070] Figure 7 A flowchart of a data processing method provided by another embodiment of the present application;
[0071] Figure 8A flowchart of a data processing method provided by another embodiment of the present application;
[0072] Fig. 9 A flowchart of a data processing method provided by another embodiment of the present application;
[0073] Fig.10 A flowchart of a data processing method provided by another embodiment of the present application;
[0074] Fig.11 A flowchart of a data processing method provided by another embodiment of the present application;
[0075] Fig.12 A flowchart of a data processing method provided in yet another embodiment of the present application;
[0076] Fig.13 A system architecture diagram of a data processing method provided in a certain embodiment of the present application;
[0077] Fig.14 A logic flow chart of a virtual interface layer provided for a certain embodiment of the present application;
[0078] Fig.15 A flowchart of Canvas compatibility processing provided for an embodiment of the present application;
[0079] Fig.16 A logical flow chart of document compatibility processing provided for an embodiment of the present application;
[0080] Fig.17 A flowchart of compatible processing of Image objects provided in one embodiment of the present application;
[0081] Fig.18 A module diagram for event mechanism compatibility processing provided for a certain embodiment of the present application;
[0082] Fig.19 A processing flow chart of a packaging module provided in an embodiment of the present application;
[0083] Fig. 20 A schematic diagram of the structure of a data processing device provided in one embodiment of the present application;
[0084] Fig.21 A schematic diagram of the structure of a data processing device provided in another embodiment of the present application;
[0085] Fig. 22 A schematic diagram of a server structure provided for a certain embodiment of the present application. DETAILED DESCRIPTION
[0086] An embodiment of the present application provides a data processing method, which converts original object code segments into target object code segments and creates global objects to access multiple target objects, and finally generates a target code library file suitable for the target operating environment.
[0087] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "corresponding to" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0088] To facilitate understanding of the method provided in the embodiments of the present application, some key terms used in the embodiments of the present application are explained here:
[0089] Browser operating environment: The browser operating environment is a complex system that requires comprehensive consideration of multiple aspects such as the operating system, browser engine, plug-ins, extensions, versions, and hardware configuration to ensure that the browser can operate normally and provide a good user experience.
[0090] Node runtime environment: The Node.js runtime environment is a complete development environment that includes an operating system, a package manager, a V8 engine, an event loop, a module system, and development tools, among other aspects. It can help developers quickly build high-performance server-side JavaScript applications.
[0091] Mini Program operating environment: Different from the regular browser operating environment and node operating environment, the logic layer and rendering layer of the mini program are separated. The logic layer runs in JSCore (a program specifically used to interpret and execute JS code) and does not have a complete browser object. Therefore, it lacks the relevant DOM API (API for manipulating page structure) and BOM API (API for manipulating browser pages).
[0092] Third-party libraries: Third-party libraries, also known as third-party code libraries, are collections of code written by non-development teams that can be used by developers in their own software projects. These code libraries are usually open source, and developers can download and use them for free to speed up development and improve code quality.
[0093] When dealing with compatibility issues, if the source code file needs to be modified, it is called intrusive adaptation; if the source code does not need to be modified, it is called non-intrusive adaptation.
[0094] In the process of building programs based on the browser environment, implementing some functions in the program through many excellent third-party libraries can help program developers develop programs faster and more efficiently. However, since the running environment of mini-programs is different from the browser environment, many third-party libraries used in the browser environment cannot be directly run in mini-programs. Even if the developers of third-party libraries (common libraries such as echart, phaser, pixijs, etc.) provide compatible versions, developers still need to make a lot of changes to the source code of the third-party libraries, and many of them are no longer maintained as the source libraries are upgraded.
[0095] Currently, when developers want to connect a third-party library to the mini-program running environment, they need to modify the source code in the third-party library. This method of modifying the source code is cumbersome and tedious. It is necessary to find all the compatibility processing points and then perform complex logic replacements. This is a lot of work for developers and prone to errors. At the same time, it requires developers to have a good understanding of the source code logic, which is costly for developers to understand. When the third-party library is upgraded, developers are also required to modify all the changes. If the third-party library is undergoing a major version upgrade or some reconstruction, the cost of modifying the source code will be even higher.
[0096] The method provided in the embodiment of the present application converts multiple original objects in the original code library file into a target code library file suitable for the target operating environment, so that the code can be run in different environments, improving the portability and maintainability of the code; at the same time, the creation of global objects also facilitates the access and management of multiple target objects, improving the efficiency and readability of code operation.
[0097] The method provided in the embodiment of the present application can be applied to the scenario of game program development, including but not limited to game development based on mini-programs, such as the development of sports mini-program games based on AI recognition implemented according to the phaser compatible library. By using a third-party phaser compatible library to implement the motion effect display and gravity drop logic in the mini-program game, users can feel a more realistic physical experience in the game.
[0098] For easier understanding, see Figure 1 , Figure 1 FIG. 1 is an application environment diagram of the data processing method in the embodiment of the present application, such as Figure 1As shown, the data processing method in the embodiment of the present application is applied to the data processing system. The data processing system includes: a server and a terminal device; wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, and the embodiments of the present application are not limited here.
[0099] The server first obtains the original code library file to be processed, wherein the original code library file is used in the original operating environment, and the original code library file includes M original objects and M original object code segments corresponding to the M original objects, the M original objects correspond to M functions, and the functions corresponding to the original objects are realized by running the original object code segments; secondly, the server creates M target objects, and generates M target object code segments corresponding to the M target objects according to the M original object code segments, wherein the M target objects have a corresponding relationship with the M original objects; then, the server runs the M target object codes to generate an object instance combination, wherein the object instance combination includes M object instances; then, the server creates a global object according to the object instance combination, and generates a global object code segment according to the global object, wherein the global object is used to realize access to the M target objects; finally, the server merges the global object code segment with the original code library file to generate a target code library file, wherein the target code library file is used in the target operating environment.
[0100] The following is an introduction to the data processing method in this application from the perspective of the server. Figure 2 , the data processing method provided in the embodiment of the present application includes: step S110 to step S150. Specifically:
[0101] S110: Obtain the original code library file to be processed.
[0102] Among them, the original code library file is used in the original operating environment. The original code library file includes M original objects and M original object code segments corresponding to the M original objects. The M original objects correspond to M functions, and the functions corresponding to the original objects are realized by running the original object code segments.
[0103] It is understandable that in the method provided in the embodiment of the present application, the original code library file may be a file in a third-party library, and the original operating environment for running the original code library file includes but is not limited to a browser operating environment and a Node operating environment. The M original objects correspond to M different functions, each of which has its specific implementation functions, which can be implemented by running the corresponding code segments.
[0104] By running the original code library file containing multiple original objects and corresponding code segments in the original running environment, M different functions corresponding to M original objects can be implemented.
[0105] S120 , creating M target objects, and generating M target object code segments corresponding to the M target objects according to the M original object code segments.
[0106] Among them, the M target objects have a corresponding relationship with the M original objects.
[0107] It is understandable that each target object is created based on an original object; based on the original object code segment corresponding to the original object, the target object code segment corresponding to the target object is generated. The "corresponding relationship" means that each original object code segment corresponds to a target object, and the generated target object code segment should have the same function and behavior as the original object code segment.
[0108] According to the original object code segment set in the original code library file, M target objects are created, and a corresponding target object code segment is generated for each target object, so that these target object code segments have the same functions and behaviors as the original object code segments.
[0109] S130: Run M target object codes to generate an object instance combination.
[0110] The object instance combination includes M object instances.
[0111] It can be understood that by running the M target object codes, an object instance combination including M object instances is generated, wherein each object instance corresponds to a target object. The object instance combination is a collection that includes multiple object instances. By running the target object code, these object instances can be created and combined together to implement the functions corresponding to the target object.
[0112] S140. Create a global object according to the object instance combination, and generate a global object code segment according to the global object.
[0113] Among them, the global object is used to implement access to M target objects.
[0114] It can be understood that, through the object instance combination, a global object is created, and a global object code segment is generated for the global object. The global object is used to implement access to the M target objects, so that the M target objects can be accessed through the global object.
[0115] A global object is a special object that provides global access to other objects. In this example, M target objects need to be accessed through the global object, so a global object is created to implement this function. The global object code segment is a code segment used to implement the global object function, which contains the definition and implementation of the global object.
[0116] S150: Merge the global object code segment with the original code library file to generate a target code library file.
[0117] Among them, the target code library file is used in the target operating environment.
[0118] It is understandable that the global object code segment is merged with the original code library file to generate a new target code library file, which contains all the codes in the global object code segment and the original code library file for use in the target operating environment.
[0119] The target code library file is a code library file used to run in the target runtime environment. By merging the global object code segment with the original code library file, they can be integrated together to form a complete code library file for use in the target runtime environment.
[0120] The method provided in the embodiment of the present application converts multiple original objects in the original code library file into a target code library file suitable for the target operating environment, so that the code can be run in different environments, improving the portability and maintainability of the code; at the same time, the creation of global objects also facilitates the access and management of multiple target objects, improving the efficiency and readability of code operation.
[0121] In this application Figure 2 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Figure 3 , step S120 further includes sub-steps S121 to S124. Specifically:
[0122] S121. Determine the document object programming interface information of the original operating environment according to the original code library file.
[0123] It can be understood that by studying the original code base files, we can understand how the original code base files interact with the original operating environment and extract information related to the document object programming interface. By understanding the interaction between the original code base files and the original operating environment, we can correctly simulate this interaction in the proxy operating environment.
[0124] Based on the code and related information in the original code library file, determine the information of the Document Object Model (DOM) used by the code in the original running environment. DOM is a standard programming interface for processing HTML and XML documents, which defines a set of standard methods and objects for manipulating and accessing document content. In the original code library file, DOM methods and objects may be used to manipulate and access document content. Therefore, by analyzing the original code library file, the DOM version, DOM objects, methods and other information used by the code in the original running environment can be determined, so as to correctly implement the code in the target running environment.
[0125] S122. Create an agent operating environment according to the document object programming interface information.
[0126] It can be understood that the information extracted from the original code base file is used to build a proxy operating environment that can simulate the original operating environment. By providing an environment that can simulate the original operating environment, the target object can run correctly in it.
[0127] The process of creating a proxy runtime environment based on Document Object Model (DOM) information includes: 1) Obtaining DOM information: First, you need to understand the DOM information of the original runtime environment, including DOM objects, methods, and attributes. This information can be obtained by reading relevant documents, viewing source code, or using debugging tools. 2) Creating proxy objects: Based on the obtained DOM information, create proxy objects to simulate the DOM objects in the original runtime environment in the proxy runtime environment. Proxy objects are usually implemented using JavaScript, and the behavior of the original DOM objects can be simulated by defining objects and methods. 3) Implementing proxy methods: Implement proxy methods for each method in the proxy object, which will be called in the proxy runtime environment to simulate the DOM methods in the original runtime environment. The proxy methods need to be processed accordingly based on the parameters and return values of the original DOM methods. 4) Configuring the proxy runtime environment: Configure the proxy runtime environment so that it can correctly identify and use proxy objects. This may include setting global variables, introducing external libraries, or modifying references in the code. 5) Testing the proxy runtime environment: Finally, the proxy runtime environment needs to be tested to ensure that it can correctly simulate the DOM objects and methods in the original runtime environment. Testing can be done using test cases or manual testing.
[0128] S123. Create M target objects in the agent runtime environment.
[0129] It is understandable that the same number of target objects as in the original code base file are created in the agent execution environment.
[0130] The process of creating M target objects in the proxy runtime environment includes: 1) Determine the definition of the target object: First, the definition of the target object needs to be clarified, including the properties, methods, and data structures of the target object. This information can be obtained from the original code library file or other relevant documents. 2) Create a proxy object: According to the definition of the target object, create a proxy object. The proxy object is usually implemented using JavaScript, and the behavior of the target object can be simulated by defining objects and methods. 3) Implement the proxy method: Implement the proxy method for each method in the proxy object, which will be called in the proxy runtime environment to simulate the method of the target object. The proxy method needs to be processed accordingly according to the parameters and return values of the target method. 4) Create M target objects: In the proxy runtime environment, use the proxy object to create M target objects. You can use a loop or other method to create these objects and assign a unique identifier or index to each object. 5) Initialize the target object: Initialize each target object, set its properties and initialize data. This can be achieved by calling the method of the proxy object. 6) Use the target object: In the proxy runtime environment, you can use the created M target objects to perform related operations. This can be achieved by calling the method of the target object or accessing its properties.
[0131] S124. Generate M target object code segments used by M target objects in the proxy execution environment according to the M original object code segments.
[0132] It is understandable that, according to the original object code segment, a corresponding target object code segment is generated for each target object in the proxy runtime environment so that they can run correctly in the proxy runtime environment. The original object code segment is converted into a target code segment suitable for the proxy runtime environment so that the target object can run correctly in the proxy runtime environment.
[0133] The process of generating M target object code segments used by M target objects in the proxy runtime environment based on M original object code segments includes: 1) Parsing the original object code segments: First, it is necessary to parse the code segments of the M original objects and extract the object definitions, methods, properties and other information therein. 2) Generate target object definitions: Generate the definitions of M target objects based on the parsed information. The definition of the target object should be the same or similar to the definition of the original object. 3) Implement target object methods: Implement the required methods for each target object. These methods should have the same functions and parameters as the methods of the original objects. 4) Generate target object code segments: Use the generated target object definitions and implemented methods to generate code segments used by M target objects in the proxy runtime environment. These code segments should be able to create M target objects and call their methods. 5) Test and debug the code segments: Finally, the generated code segments need to be tested and debugged to ensure that they can correctly create and use the target objects.
[0134] The method provided by the embodiment of the present application is a process of converting the original code library file into a target code suitable for the proxy operation environment so as to run the target object in the proxy operation environment. This process includes determining the document object programming interface information of the original operation environment, creating the proxy operation environment, creating the target object in the proxy operation environment, and generating the target object code segment according to the original object code segment. By converting the original code library file into a target code suitable for the proxy operation environment, the code can be made more portable, and the code can be run in different operation environments without a lot of modification or recompilation.
[0135] In this application Figure 3 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Figure 4 , step S124 further includes sub-steps S1241 to S1243. Specifically:
[0136] S1241. Obtain M original logic information corresponding to the M original object code segments when they are running in the original running environment.
[0137] The original logic information is used to represent the running logic of the original object code segment in the original running environment.
[0138] It is understandable that the M original object code segments are run in the original running environment and their running logic is recorded. Specifically, operations such as running the code, recording logs, and collecting performance data are performed in the original running environment to understand the actual running status of the code.
[0139] The original logic information refers to the information that can characterize the operation logic of the original object code segment in the original operation environment. This information may include the input and output of the program, the execution flow of the program, the error information of the program, etc. By obtaining this original logic information, the actual operation of the original object code segment in the original operation environment can be understood so as to analyze and optimize it. At the same time, this information can also be used as the basis for subsequent steps to generate the target object code segment to ensure that the target object can achieve the same function in the proxy operation environment as the original object in the original operation environment.
[0140] S1242. Generate M target logic information according to the M original logic information.
[0141] The target logic information is used to represent the operation logic of the target object in the agent operation environment.
[0142] It is understood that the target logic information refers to the logic information of the target object when it is running in the proxy runtime environment. This may require some conversion or modification of the original logic information to adapt to the requirements of the proxy runtime environment. Specifically, the original logic information is analyzed, converted or modified to adapt to the requirements of the proxy runtime environment. For example, if the original code uses a specific library or framework in the original runtime environment, and the proxy runtime environment does not have these libraries or frameworks, the target logic information needs to be modified to use the alternative library or framework.
[0143] The target logic information refers to the information related to the operation logic of the target object code segment obtained after certain processing and conversion based on the original logic information. This information will be used to guide the generation of the target object code segment to ensure that the target object can achieve the same function in the proxy operation environment as the original object in the original operation environment. Therefore, generating M target logic information based on M original logic information is an important step to migrate the operation logic of the original object code segment from the original operation environment to the proxy operation environment. Through this process, it can be ensured that the target object can correctly achieve the required function in the proxy operation environment.
[0144] S1243. Generate M target object code segments according to the M target logic information.
[0145] It is understandable that, according to the target logic information, corresponding codes are written to implement the operation logic of the target object in the proxy operation environment. Specifically, the code is written in a programming language to implement the target logic information and is organized into target object code segments. These code segments should be able to run in the proxy operation environment and implement the same functions as the original object in the original operation environment.
[0146] The target object code segment refers to a code segment written according to the target logic information and used to implement the target object function. These code segments will be integrated into the proxy operation environment to replace the functions of the original object in the original operation environment. Therefore, generating M target object code segments according to M target logic information is a key step to migrate the operation logic of the original object code segment from the original operation environment to the proxy operation environment. Through this process, it can be ensured that the target object can correctly implement the required functions in the proxy operation environment.
[0147] The method provided by the embodiment of the present application converts the operation logic of the original object code segment in the original operation environment into the operation logic of the target object in the proxy operation environment, and generates a corresponding code segment. This is usually used to run the same code in different environments, or to add new functions to the original code without changing it. In this way, it can be ensured that the code can run normally in different environments, and new functions can be easily added or existing functions can be modified.
[0148] In this application Figure 3 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Figure 5 , step S130 further includes sub-steps S131 to S132. Specifically:
[0149] S131. Run M target object codes in the proxy execution environment to generate M object instances.
[0150] It can be understood that each target object code segment is executed and its corresponding object instance is created. Each object instance is an independent entity with its own state and behavior. The state of an object instance may include its attributes (e.g., variables, arrays, etc.), while its behavior is defined by its methods (e.g., functions, procedures, etc.).
[0151] The proxy runtime environment is a virtual or abstract environment that allows the code of multiple target objects to run at the same time without running these objects simultaneously on physical hardware. This mode of operation can improve the efficiency and flexibility of the system. Generating M object instances means that when the code of the target object is run, M instances corresponding to the object type defined in the code will be created. Each object instance has its own memory space and state, which can be used to store and process data.
[0152] S132: Merge the M object instances to generate an object instance combination.
[0153] It is understood that this merging process can be implemented in a variety of ways, such as merging the properties and methods of multiple object instances into a new object instance, or forming multiple object instances into a collection or array. When merging object instances, they can be modified or extended as needed. For example, new properties or methods can be added, or existing properties or methods can be modified. In addition, object instances can be sorted, filtered, or otherwise operated to generate a combination of object instances that meets specific requirements.
[0154] In programming, an object instance refers to a specific instantiation of a class, and each object instance has its own unique properties and behaviors. By merging multiple object instances into a new object instance combination, unified management and operation of these objects can be achieved. There are many ways to merge object instances, and the specific implementation methods may vary depending on the programming language and requirements. For example, in some programming languages, multiple object instances can be merged into a new object instance by using aggregation, combination, or reference. The advantage of generating an object instance combination is that it is convenient to uniformly operate and manage multiple objects and simplify the complexity of the code. In addition, by merging and combining object instances, some more advanced functions can be implemented, such as inheritance, polymorphism, etc. It should be noted that when merging object instances, the relationship between objects and the consistency of data need to be considered to avoid errors and exceptions.
[0155] The method provided by the embodiment of the present application combines multiple target object code segments into an object instance combination so as to more conveniently process and use these objects. The object instance combination can provide a unified way to access and operate multiple objects, and can simplify the complexity of the code. In addition, by combining object instances, some more advanced functions, such as inheritance, polymorphism, etc., can also be implemented. These functions can make the code more flexible and easy to maintain, and can improve the reusability of the code.
[0156] In this application Figure 5 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Figure 6 , step S130 further includes sub-steps S133 to S134. Specifically:
[0157] S133. Create a context execution environment function in the proxy execution environment.
[0158] S134. Bind the following execution environment function to the global object to generate a global object code segment.
[0159] It is understandable that the agent runtime is an abstract concept that provides a mechanism to create and manage contexts at runtime. A context runtime function is a function created in the agent runtime that can be used to set and manage a specific runtime context, such as setting global variables, initializing system resources, etc.
[0160] A global object is an object that exists throughout the program and can be accessed and used by all code modules. Binding a context runtime function to a global object means associating the function with the global object so that the function can be executed in the context of the global object and affect the global object.
[0161] The method provided in the embodiment of the present application can realize dynamic configuration and management of global objects by binding the context runtime function to the global object. For example, global variables can be set in the context runtime function, and these variables can be accessed and modified through the global object in other code modules. This method can improve the flexibility and scalability of the code, so that the program can be dynamically adjusted according to different needs and scenarios.
[0162] In this application Figure 2 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Figure 7 , step S150 further includes sub-steps S151 to S152. Specifically:
[0163] S151. Determine the file insertion position in the global object code segment.
[0164] It is understood that the global object code segment refers to a code segment that exists during the entire program execution and can be accessed and used by all code modules. The file insertion position refers to a position reserved in the global object code segment for inserting the code of other files.
[0165] S152, inserting the original code library file into the file insertion position to generate a target code library file.
[0166] It is understandable that the original code library file refers to an existing code library file, which contains some codes that need to be inserted into the global object code segment. Inserting the original code library file into the file insertion position means inserting the code in the file into the reserved position in the global object code segment and generating a new target code library file.
[0167] By inserting the original code library file into the file insertion position, the global object code segment can be expanded and modified. For example, new functions, variables, classes and other codes can be added to the global object code segment, and these codes can be accessed and used through the global object in other code modules.
[0168] The method provided in the embodiment of the present application can improve the flexibility and scalability of the code, so that the program can be dynamically adjusted according to different needs and scenarios.
[0169] In this application Figure 2 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Figure 8 , after step S150, it also includes steps S160 to S170. Specifically:
[0170] S160: Obfuscate the target code library file to reduce the amount of code in the target code library file and generate a target code package file.
[0171] It is understood that the target code library file refers to a set of code files obtained after a series of processing, which contains all the code required by the program. Obfuscation is a code compression technology that makes the code more compact and difficult to understand by performing a series of conversions and replacements on the code, thereby reducing the amount of code and improving the security of the code. The target code package file refers to the file obtained by packaging the set of obfuscated code files.
[0172] S170, exporting the target code package file.
[0173] It is understandable that exporting the object code package file refers to outputting the object code package file from the program to an external storage device or network so that other users or systems can use or access it.
[0174] The method provided in the embodiment of the present application can compress and encrypt the code by obfuscating and exporting the target code library file, thereby reducing the amount of code and improving the security of the code. At the same time, exporting the target code package file can also facilitate other users or systems to use or access the program, thereby improving the reusability and portability of the code.
[0175] In this application Figure 2 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Fig. 9 , step S120 further includes sub-steps S1201 to S1204. Specifically:
[0176] S1201. Create a canvas object.
[0177] Among them, the canvas object is one of the M target objects.
[0178] It can be understood that a canvas object is created, which is one of the M target objects. This means that this canvas object together with other target objects constitutes the whole of the target object.
[0179] S1202: Define the target type attribute of the canvas object corresponding to the target operating environment.
[0180] It can be understood that defining the target type attribute of the canvas object corresponding to the target operating environment may be to set some attributes related to the target operating environment, such as screen size, resolution, etc., for the canvas object.
[0181] In order for the canvas object to work properly in the target runtime environment, it is necessary to define some properties related to the target runtime environment. These properties describe the characteristics and behaviors of the canvas object in the target runtime environment, such as screen size, resolution, color depth, etc.
[0182] S1203: Obtain an original canvas object code segment in the original running environment of the canvas object.
[0183] It is understandable that the code segments related to the canvas object are obtained from the original code of the program so as to update it. In order to make the canvas object work properly in different operating environments, it is necessary to obtain some code segments related to the original operating environment.
[0184] S1204: Update the original canvas object code segment according to the target type attribute to generate a target canvas object code segment corresponding to the canvas object.
[0185] Among them, the canvas object target code segment is one of the M target object code segments.
[0186] It is understandable that, according to the requirements of the target operating environment, the original canvas object code segment is modified and optimized to generate a target canvas object code segment suitable for the target operating environment.
[0187] The method provided in the embodiment of the present application enables the canvas object to work normally in the target operating environment and to be adaptively adjusted according to the requirements of the target operating environment, thereby improving the compatibility and portability of the program, and also improving the performance of the program and user experience.
[0188] In this application Figure 2 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Fig.10 , step S120 further includes sub-steps S1211 to S1214. Specifically:
[0189] S1211. Create a first picture object and a second picture object.
[0190] The first picture object is one of the M target objects, the second picture object is one of the M target objects, and the type corresponding to the first picture object is different from the type corresponding to the second picture object.
[0191] It can be understood that the creation of a picture object is achieved by calling a corresponding image creation function or using a specific image data structure.
[0192] S1212. Set attribute information of the first picture object, and set attribute information of the second picture object.
[0193] The attribute information includes the location information of the image object.
[0194] It is understandable that setting the attribute information of the picture object includes setting the position, size, color, etc. of the picture. These attribute information can be set by calling corresponding functions or setting specific variables.
[0195] A picture object is a data structure used in programming to represent a picture. It usually has some properties, such as the size, resolution, color format, etc. of the picture. By setting these properties, you can control the appearance and behavior of the picture. Therefore, setting the property information of the first picture object means setting the properties of the first picture object through programming code, such as setting its size to 100x100 pixels, resolution to 72dpi, etc. Similarly, setting the property information of the second picture object means setting the properties of the second picture object through programming code.
[0196] S1213. Call back the attribute information of the first picture object and the attribute information of the second picture object to generate a first target picture object code segment corresponding to the first picture object.
[0197] Among them, the first target picture object code segment is one of the M target object code segments.
[0198] It is understandable that the callback function may be a general image processing function, which accepts two picture objects as input and generates a corresponding target picture object code segment according to their attribute information. The callback function generates a corresponding target picture object code segment according to the attribute information of the first picture object. This target picture object code segment will be stored in the program's memory and can be used for subsequent image processing or display.
[0199] S1214. Call back the attribute information of the second picture object and the attribute information of the second picture object to generate a second target picture object code segment corresponding to the second picture object.
[0200] The second target picture object code segment is one of the M target object code segments.
[0201] It can be understood that, similarly, the callback function generates a corresponding target picture object code segment according to the attribute information of the second picture object.
[0202] The method provided in the embodiment of the present application enables the image object to work normally in the target operating environment and to be adaptively adjusted according to the requirements of the target operating environment, thereby improving the compatibility and portability of the program, while also improving the performance of the program and user experience.
[0203] In this application Figure 2 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Fig.11 , step S120 further includes sub-steps S1221 to S1223. Specifically:
[0204] S1221. Create a network request object.
[0205] The network request object is one of the M target objects.
[0206] It is understandable that the network request object can be any specific network request type, such as HTTP request, FTP request, etc.
[0207] S1222. Configure the properties of the network request object.
[0208] Among them, the properties of the network request object include event distribution and message acquisition.
[0209] It is understandable that after creating a network request object, its properties need to be configured. These properties may include the target address of the request, the request method (GET, POST, etc.), the request header, the request parameters, etc. In addition, some event distribution properties may need to be configured, such as the event that should be triggered when the request is completed.
[0210] S1223. Call back the properties of the network request object to generate a network request object code segment.
[0211] The network request object code segment is one of the M target object code segments.
[0212] It is understandable that callback refers to a function or method that is automatically called by the program when certain events or conditions occur. In this process, when the properties of the network request object change, it may be necessary to call the corresponding callback function for processing. According to the properties of the network request object and the processing results of the callback function, a corresponding code segment is generated. This code segment may be a program code or a requested URL string.
[0213] The method provided in the embodiment of the present application configures and calls back the properties of the network request object to generate corresponding code segments to realize automatic processing of the network request, which can improve the efficiency and reliability of the program and reduce the risk of errors in manual operations.
[0214] In this application Figure 2 In an optional embodiment of the data processing method provided in the corresponding embodiment, please refer to Fig.12 , step S120 further includes sub-steps S1231 to S1233. Specifically:
[0215] S1231. Create an event mechanism object.
[0216] Among them, the event mechanism object is one of the M target objects.
[0217] S1232. Obtain the object instance corresponding to the event mechanism object.
[0218] The object instance corresponding to the event mechanism object is obtained by running the event mechanism object in the target running environment.
[0219] It can be understood that by running the event mechanism object in the target operating environment, an instance of the event mechanism object is obtained. The event mechanism object represents a logic for processing events. When the event mechanism object is run in the target operating environment, a specific object instance is generated, which is the object instance corresponding to the event mechanism object. This object instance has the same functions and interfaces as the event mechanism object and can be used to process events in the target operating environment. Therefore, by obtaining this object instance, it can be used in the code to process events, thereby realizing the function of the event mechanism.
[0220] S1233. Generate an event mechanism object code segment according to the object instance corresponding to the event mechanism object, wherein the event mechanism object code segment is one of the M target object code segments.
[0221] It can be understood that a code segment is generated based on the instance of the event mechanism object. This code segment describes how to use the event mechanism object to handle events. The object instance corresponding to the event mechanism object refers to the event mechanism object actually running in the target operating environment, which is the basis for code generation. Generating the event mechanism object code segment means generating a code segment based on this object instance, and this code segment is used to implement functions related to the event mechanism.
[0222] The method provided in the embodiment of the present application creates an event mechanism object and generates a corresponding code segment, so that the event mechanism object can be run in the target operating environment and implement the corresponding event processing function. This can improve the readability and maintainability of the code, and also facilitate the reuse and expansion of the code.
[0223] To facilitate understanding of the data processing method provided in the embodiments of the present application, please refer to Fig.13 , Fig.13 This is a system architecture diagram of the data processing method provided in the embodiment of the present application. The data processing system is mainly composed of four parts: a third-party library acquisition layer, a virtual interface layer, a logic compatibility layer, and a mini-program API layer; among which, the third-party library acquisition layer and the virtual interface layer constitute an injection packaging module. Specifically:
[0224] (1) Virtual interface layer: mainly provides the runtime environment of the third-party library, and provides the necessary global variables for the operation of the third-party library. The global variables include window (browser window object), window mounting properties, this (method runtime context) definition, etc. Specifically:
[0225] For easier understanding, see Fig.14 , Fig.14 This is a logic flow chart of the virtual interface layer provided by the embodiment of the present application. The virtual interface layer provides the window object necessary for the operation of the third-party library, and creates an operation logic with the window as the context. The third-party library is injected into the operation logic in the form of code injection. The logic flow of the virtual interface layer includes:
[0226] 1) Import compatible object instances and build them as global variables. This allows subsequent injection logic to be used directly.
[0227] It is understandable that the purpose of step 1) is to provide some common object instances in the virtual interface layer, such as window objects, document objects, etc. These object instances can be used directly by other codes and are constructed as global variables to ensure that they are available in the entire virtual interface layer.
[0228] 2) Combine compatible objects to build a window instance. Through the above two steps, the effect of directly using the functions window.xxx and xxx in a browser-like environment can be achieved.
[0229] It is understandable that the purpose of step 2) is to provide a browser-like window object in the virtual interface layer. By combining compatible object instances, a global window object can be created, so that other codes can access these objects using the window.xxx method like in a browser.
[0230] 3) To achieve compatibility with this in third-party libraries, you need to build a context runtime environment. Build a runtime method and bind the window. Reserve a mark point in the runtime method for third-party code insertion and replacement.
[0231] It is understandable that the purpose of step 3) is to solve the compatibility problem caused by different interpretations of this when using third-party libraries. By building a context runtime environment, a unified this pointer can be provided for the third-party library, thus avoiding compatibility problems.
[0232] 4) The third-party code can be inserted and run normally. At this time, it is necessary to process the third-party library products under different packaging modes (libraryTarget) and make them as the return of runtime.
[0233] It is understandable that the purpose of step 4) is to support the insertion of third-party code in the virtual interface layer. After the third-party code is inserted, it can run normally in the virtual interface layer and can access the object instance and operating environment provided in the virtual interface layer.
[0234] 5) Return to continue exporting and use it normally in the mini program environment.
[0235] It is understandable that the purpose of step 5) is to export the return value in the virtual interface layer to the applet environment so that it can be used normally in the applet. By exporting the return value, the functions in the virtual interface layer can be used in the applet and can interact with other codes.
[0236] (2) Logical compatibility layer: It is the specific implementation of the virtual operating environment and the core module of the data processing system. It mainly solves the operation adaptation problem between the third-party library and the applet environment. The logical compatibility layer mainly includes: node management module (document object), event mechanism module (event object), media management module (media object), network request module (network object), and local storage module (storage object). The object instances required by the interface layer are provided by the compatibility layer, which simulates the general DOM API and BOM API.
[0237] Among them, the document object represents the currently loaded HTML document, and provides access to the document structure and content, such as obtaining elements, modifying styles, etc. Due to the limitations of the mini-program environment, it is impossible to create nodes by yourself in the mini-program environment. The functions of the document object in the browser can only be realized through the limited DOM nodes supported by the mini-program environment, such as canvas, image, audio, etc. For the compatible processing of the document object, taking the processing of canvas drawing as an example, the type attribute definition of canvas in the browser is determined when obtaining the Canvas Context, while the type attribute definition of canvas in the mini-program is specified through wx.createOffscreenCanva (mini-program call function) when the canvas is created. In addition, the display problem of pictures in the mini-program on the canvas requires distinguishing whether the canvas attributes are webgl canvas drawing or 2d canvas drawing. For details, please refer to Fig.15 and Fig.16 , Canvas compatibility is achieved through proxy and logic injection. The processing flow includes:
[0238] 1) Create a Canvas proxy object.
[0239] It is understandable that by creating a proxy object, the object will represent the actual Canvas object. The main function of the proxy object is to provide developers with a more convenient interface to operate Canvas without changing the actual Canvas object.
[0240] 2) When getting the canvas Context, use its type parameter to actually create the offscreenCanvas and solve the type specification problem.
[0241] It is understandable that when the developer obtains the Canvas Context through the proxy object, a real offscreenCanvas object will be created according to the type parameter passed in. OffscreenCanvas is a special Canvas object that can be drawn in the background without affecting the display effect of the foreground. In this way, the problem of specifying the type attribute of Canvas in the mini program can be solved.
[0242] 3) Rewrite the drawing method of the obtained canvas Context to solve the display compatibility problem of the applet.
[0243] It is understandable that the drawing method of the obtained Canvas Context object will be rewritten. The purpose of doing this is to solve the display compatibility problem of the mini program. Since the rendering mechanism of the mini program and the browser is different, this method is needed to ensure that the image drawn in the mini program can be displayed correctly.
[0244] 4) After this processing, you can create a canvas when obtaining the context and call the context method.
[0245] It is understandable that after the above processing, the developer can obtain the CanvasContext through the proxy object and call the Canvas Context method to perform drawing operations. In this way, the function of creating a Canvas and calling the Canvas Context method when obtaining the Canvas Context in the mini program is realized.
[0246] media object: provides access to media devices (such as cameras and microphones), which can be used to obtain media data and control devices. The compatibility processing of media objects includes the compatibility processing of Audio objects and the compatibility processing of Image objects. Among them, the Audio object is mainly compatible through the wx.createWebAudioContext() of the applet. The Image object is compatible through the object returned by createImage() of offscreenCanvas. However, the execution logic of using Image in the applet running environment is different from that in the browser environment, that is, the type of the source canvas of createImage in the applet environment must be consistent with the drawing canvas type. In the browser environment, because Image is a native object, there are no relevant restrictions. Because Image objects can be reused in multiple places, their type cannot be determined by one use. This method uses a dual-instance proxy to handle the compatibility issues of Image objects. Please refer to Fig.17 , Fig.17 This is the compatible processing process of the Image object provided by the embodiment of the present application: 1) When creating an Image, create two types of real instances of the webgl Image object and the 2d Image object respectively. 2) When setting the src, remember to set the two instances separately, and after waiting for both instances to callback successfully, return the mounted onload callback. 3) When drawing the Image object, select the real instance according to the type of canvas. 4) According to the selection logic in step 3), process the proxy logic.
[0247] Network object: provides access to the network status, which can be used to obtain network status information, such as the current network connection status, download speed, etc. In the browser running environment, network requests are issued using XMLHttpRequest (function), and XMLHttpRequest supports both relative path loading and http link loading. In the applet running environment, this is implemented through wx.getFileSystemManager and wx.request respectively. Specifically, the process of network request compatibility processing includes: 1) Creating a proxy XMLHttpRequest class. 2) Providing event distribution and data acquisition support. 3) Receive the request and determine the type of loading link. 4) Based on the link type, determine whether to distribute local file loading or network file loading. 5) Receive the callback and return the distribution result.
[0248] It should be noted that since the mini program environment does not support Blob data file objects, when the responseType in the XMLHttpRequest request header is of blob type, it is necessary to return and process it according to the arrybuffer data object, so that when the data file is subsequently processed, it can be converted through compatible processing of FileReader.
[0249] Event object: Represents a browser event and provides access to event handlers that can be used to obtain and respond to various events, such as mouse clicks, keyboard input, etc. See Fig.18 , Fig.18 This is a module diagram for event mechanism compatibility processing. The event mechanism is a typical feature of the DOM environment, and almost all objects have event sending and receiving. Therefore, this method creates the event mechanism base class BaseEvent, that is, all compatible instances inherit from BaseEvent.
[0250] Storage object: provides access to the browser's local storage, which can be used to store and read data, such as LocalStorage and SessionStorage. In general, in a virtual browser environment, there are many objects that need to be compatible. However, due to the dynamic and flexible characteristics of the JavaScript language, they can all be handled through proxy and rewriting.
[0251] (3) Packaging and injection module: mainly responsible for injecting the original third-party library into the virtual runtime environment and repackaging the mini-program compatible library. Fig.19In order to further reduce the development cost of adaptation, this method provides a packaging module to implement a complete set of processes for pulling down, injecting, packaging, obfuscating, and exporting remote libraries to generate files. Because this method transfers and exports the objects of the third-party library. Therefore, the usage of the packaged files is exactly the same as that of the original third-party library.
[0252] Mini Program is a lightweight application development framework based on a platform of related applications. It provides some specific APIs and restrictions, so that developers can develop feature-rich applications with good experience on the WeChat platform. However, since the environment of the mini program is very different from the traditional web development environment, some third-party libraries may not run properly in the mini program. In order to solve this problem, the method proposed in this application is needed to enable these third-party libraries to run in the mini program. Specifically: a virtual operating environment is provided for the third-party library through the virtual interface layer and the logical compatibility layer, so that the third-party library can run in this environment and adapt to the environment of the mini program. At the same time, by packaging the injection module, the original third-party library can be injected into this virtual environment and repackaged as a mini program compatible library for easy use in the WeChat mini program. By using the method proposed in this application, developers can use third-party libraries that were originally unable to run in the mini program in the mini program, expand the functions of the mini program, and improve development efficiency and user experience.
[0253] In the application scenario of the method provided in this application, the phaser compatible library can be used to implement dynamic effect display and gravity drop logic, thereby realizing the development of sports applets based on AI recognition.
[0254] The data processing device in this application is described in detail below. Fig. 20 . Fig. 20 1 is a schematic diagram of an embodiment of a data processing device 10 in an embodiment of the present application. The data processing device 10 includes: an original code library file acquisition module 110, a target object and target object code segment generation module 120, an object instance generation module 130, a global object and global object code segment generation module 140 and a target code library file generation module 150; specifically:
[0255] The original code library file acquisition module 110 is used to acquire the original code library file to be processed, wherein the original code library file is used in the original running environment, the original code library file includes M original objects and M original object code segments corresponding to the M original objects, the M original objects correspond to M functions, and the functions corresponding to the original objects are realized by running the original object code segments, where M is an integer greater than or equal to 1;
[0256] The target object and target object code segment generating module 120 is used to create M target objects, and generate M target object code segments corresponding to the M target objects according to the M original object code segments, wherein the M target objects have a corresponding relationship with the M original objects;
[0257] The object instance generation module 130 is used to run the M target object codes to generate an object instance combination, wherein the object instance combination includes M object instances;
[0258] A global object and global object code segment generating module 140 is used to create a global object according to the object instance combination, and to generate a global object code segment according to the global object, wherein the global object is used to implement access to M target objects;
[0259] The target code library file generation module 150 is used to merge the global object code segment with the original code library file to generate a target code library file, wherein the target code library file is used in the target operating environment.
[0260] The device provided in the embodiment of the present application converts multiple original objects in the original code library file into a target code library file suitable for the target operating environment, so that the code can be run in different environments, improving the portability and maintainability of the code; at the same time, the creation of global objects also facilitates the access and management of multiple target objects, improving the efficiency and readability of code operation.
[0261] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the target object and target object code segment generating module 120 is further used to:
[0262] Determine the document object programming interface information of the original operating environment according to the original code library file;
[0263] Create an agent operating environment based on the document object programming interface information;
[0264] Create M target objects in the agent running environment;
[0265] M target object code segments used by the M target objects in the proxy execution environment are generated according to the M original object code segments.
[0266] The device provided by the embodiment of the present application is a process of converting the original code library file into a target code suitable for the proxy operation environment so as to run the target object in the proxy operation environment. This process includes determining the document object programming interface information of the original operation environment, creating the proxy operation environment, creating the target object in the proxy operation environment, and generating the target object code segment according to the original object code segment. By converting the original code library file into a target code suitable for the proxy operation environment, the code can be made more portable, and the code can be run in different operation environments without a lot of modification or recompilation.
[0267] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the target object and target object code segment generating module 120 is further used to:
[0268] Obtaining M original logic information corresponding to the M original object code segments when they are running in the original running environment, wherein the original logic information is used to represent the running logic of the original object code segments in the original running environment;
[0269] Generate M target logic information according to the M original logic information, wherein the target logic information is used to represent the operation logic of the target object in the agent operation environment;
[0270] Generate M target object code segments according to the M target logic information.
[0271] The device provided by the embodiment of the present application converts the operation logic of the original object code segment in the original operation environment into the operation logic of the target object in the proxy operation environment, and generates a corresponding code segment. This is usually used to run the same code in different environments, or to add new functions to the original code without changing it. In this way, it can be ensured that the code can run normally in different environments, and new functions can be easily added or existing functions can be modified.
[0272] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the object instance generation module 130 is further used to:
[0273] Run the M target object codes in the proxy runtime environment to generate M object instances;
[0274] Merge M object instances to generate an object instance combination.
[0275] The device provided by the embodiment of the present application combines multiple target object code segments into an object instance combination so as to more conveniently process and use these objects. The object instance combination can provide a unified way to access and operate multiple objects, and can simplify the complexity of the code. In addition, by combining object instances, some more advanced functions, such as inheritance, polymorphism, etc., can also be implemented. These functions can make the code more flexible and easy to maintain, and can improve the reusability of the code.
[0276] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the object instance generation module 130 is further used to:
[0277] Create a context runtime function in the agent runtime;
[0278] Bind the following running environment function to the global object to generate a global object code segment.
[0279] The device provided in the embodiment of the present application can realize dynamic configuration and management of global objects by binding the context runtime function with the global object. For example, global variables can be set in the context runtime function, and these variables can be accessed and modified through the global object in other code modules. This method can improve the flexibility and scalability of the code, so that the program can be dynamically adjusted according to different needs and scenarios.
[0280] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the target code library file generating module 150 is further used for:
[0281] Determine the file insertion position in the global object code segment;
[0282] Insert the original code library file into the file insertion position to generate the target code library file.
[0283] The device provided in the embodiment of the present application can improve the flexibility and scalability of the code, so that the program can be dynamically adjusted according to different needs and scenarios.
[0284] In this application Fig. 20 In an optional embodiment of the data processing device provided in the corresponding embodiment, please refer to Fig.21 The data processing device further includes: an obfuscation module 160 and an export module 170; specifically:
[0285] The obfuscation module 160 is used to perform obfuscation processing on the target code library file to reduce the amount of code in the target code library file and generate a target code package file;
[0286] The export module 170 is used to export the target code package file.
[0287] The device provided in the embodiment of the present application can compress and encrypt the code by obfuscating and exporting the target code library file, thereby reducing the amount of code and improving the security of the code. At the same time, exporting the target code package file can also facilitate other users or systems to use or access the program, thereby improving the reusability and portability of the code.
[0288] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the target object and target object code segment generating module 120 is further used to:
[0289] Create a canvas object, where the canvas object is one of the M target objects;
[0290] Define the target type attribute of the canvas object corresponding to the target operating environment;
[0291] Get the original canvas object code segment in the original running environment of the canvas object;
[0292] The original canvas object code segment is updated according to the target type attribute to generate a target canvas object code segment corresponding to the canvas object, wherein the canvas object target code segment is one of the M target object code segments.
[0293] The device provided in the embodiment of the present application enables the canvas object to work normally in the target operating environment and can be adaptively adjusted according to the requirements of the target operating environment, thereby improving the compatibility and portability of the program, and also improving the performance of the program and user experience.
[0294] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the target object and target object code segment generating module 120 is further used to:
[0295] Creating a first picture object and a second picture object, wherein the first picture object is one of the M target objects, the second picture object is one of the M target objects, and the type corresponding to the first picture object is different from the type corresponding to the second picture object;
[0296] Setting attribute information of the first picture object, and setting attribute information of the second picture object, wherein the attribute information includes location information of the picture object;
[0297] Calling back the attribute information of the first picture object and the attribute information of the second picture object to generate a first target picture object code segment corresponding to the first picture object, wherein the first target picture object code segment is one of the M target object code segments;
[0298] The attribute information of the second picture object and the attribute information of the second picture object are called back to generate a second target picture object code segment corresponding to the second picture object, wherein the second target picture object code segment is one of the M target object code segments.
[0299] The device provided in the embodiment of the present application enables the image object to operate normally in the target operating environment and can be adaptively adjusted according to the requirements of the target operating environment, thereby improving the compatibility and portability of the program, and also improving the performance of the program and user experience.
[0300] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the target object and target object code segment generating module 120 is further used to:
[0301] Create a network request object, where the network request object is one of the M target objects;
[0302] Configure the properties of the network request object, where the properties of the network request object include event distribution and message acquisition;
[0303] The properties of the network request object are called back to generate a network request object code segment, wherein the network request object code segment is one of the M target object code segments.
[0304] The device provided in the embodiment of the present application configures and calls back the properties of the network request object to generate corresponding code segments to realize automatic processing of the network request, which can improve the efficiency and reliability of the program and reduce the risk of errors in manual operations.
[0305] In this application Fig. 20 In an optional embodiment of the data processing device provided by the corresponding embodiment, the target object and target object code segment generating module 120 is further used to:
[0306] Create an event mechanism object, where the event mechanism object is one of the M target objects;
[0307] Obtaining an object instance corresponding to the event mechanism object, wherein the object instance corresponding to the event mechanism object is obtained by running the event mechanism object in a target running environment;
[0308] An event mechanism object code segment is generated according to the object instance corresponding to the event mechanism object, wherein the event mechanism object code segment is one of the M target object code segments.
[0309] The device provided in the embodiment of the present application creates an event mechanism object and generates a corresponding code segment, so that the event mechanism object can run in the target operating environment and implement the corresponding event processing function. This can improve the readability and maintainability of the code, and also facilitate the reuse and expansion of the code.
[0310] Fig. 22 : is a schematic diagram of a server structure provided in an embodiment of the present application. The server 300 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 322 (for example, one or more processors) and memory 332, and one or more storage media 330 (for example, one or more mass storage devices) storing application programs 342 or data 344. Among them, the memory 332 and the storage medium 330 can be short-term storage or permanent storage. The program stored in the storage medium 330 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the server. Furthermore, the central processing unit 322 can be configured to communicate with the storage medium 330 to execute a series of instruction operations in the storage medium 330 on the server 300.
[0311] The server 300 may also include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input and output interfaces 358, and / or one or more operating systems 341, such as Windows Server 2000. TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM etc.
[0312] The steps performed by the server in the above embodiment can be based on the Fig. 22 The server structure shown.
[0313] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0314] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0315] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the method of this embodiment.
[0316] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0317] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the method of the present application is essentially or the part that contributes to the prior art or all or part of the method can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0318] The above embodiments are only used to illustrate the method of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the methods described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding method from the spirit and scope of the methods of the various embodiments of the present application.
Claims
1. A data processing method, characterized in that: include: Obtaining an original code library file to be processed, wherein the original code library file is used in an original running environment, the original code library file includes M original objects and M original object code segments corresponding to the M original objects, the M original objects correspond to M functions, and the functions corresponding to the original objects are implemented by running the original object code segments, where M is an integer greater than or equal to 1; Creating M target objects, and generating M target object code segments corresponding to the M target objects according to the M original object code segments, wherein the M target objects have a corresponding relationship with the M original objects; Running the M target object codes to generate an object instance combination, wherein the object instance combination includes M object instances; Creating a global object according to the object instance combination, and generating a global object code segment according to the global object, wherein the global object is used to implement access to the M target objects; The global object code segment is merged with the original code library file to generate a target code library file, wherein the target code library file is used in a target operating environment.
2. The data processing method according to claim 1, characterized in that: The creating M target objects and generating M target object code segments corresponding to the M target objects according to the M original object code segments include: Determining document object programming interface information of the original operating environment according to the original code library file; Creating an agent runtime environment according to the document object programming interface information; Creating M target objects in the agent execution environment; M target object code segments used by the M target objects in the proxy execution environment are generated according to the M original object code segments.
3. The data processing method according to claim 2, characterized in that: The step of generating, according to the M original object code segments, M target object code segments used by the M target objects in the proxy execution environment comprises: Acquire M original logic information corresponding to the M original object code segments when they are running in the original running environment, wherein the original logic information is used to represent the running logic of the original object code segments in the original running environment; Generate M target logic information according to the M original logic information, wherein the target logic information is used to represent the operation logic of the target object in the proxy operation environment; Generate M target object code segments according to the M target logic information.
4. The data processing method according to claim 2, characterized in that: The step of running the M target object codes to generate an object instance combination includes: Running the M target object codes in the proxy execution environment to generate M object instances; The M object instances are merged to generate an object instance combination.
5. The data processing method according to claim 4, characterized in that: According to the global object, a global object code segment is generated, including: Create a context runtime function in the agent runtime; Bind the following execution environment function to the global object to generate a global object code segment.
6. The data processing method according to claim 1, characterized in that: The step of merging the global object code segment with the original code library file to generate a target code library file includes: Determining a file insertion position in the global object code segment; Insert the original code library file into the file insertion position to generate a target code library file.
7. The data processing method according to claim 1, characterized in that: After generating the target code library file, the following steps are also included: Obfuscating the target code library file to reduce the amount of code in the target code library file and generate a target code package file; The target code is packaged into a file for export.
8. The data processing method according to claim 1, characterized in that: The creating M target objects and generating M target object code segments corresponding to the M target objects according to the M original object code segments include: Creating a canvas object, wherein the canvas object is one of the M target objects; Defining a target type attribute of the canvas object corresponding to the target operating environment; Obtaining an original canvas object code segment of the canvas object in the original running environment; The original canvas object code segment is updated according to the target type attribute to generate a target canvas object code segment corresponding to the canvas object, wherein the canvas object target code segment is one of the M target object code segments.
9. The data processing method according to claim 1, characterized in that: The creating M target objects and generating M target object code segments corresponding to the M target objects according to the M original object code segments include: Creating a first picture object and a second picture object, wherein the first picture object is one of the M target objects, the second picture object is one of the M target objects, and the type corresponding to the first picture object is different from the type corresponding to the second picture object; Setting attribute information of the first picture object, and setting attribute information of the second picture object, wherein the attribute information includes location information of the picture object; Calling back the attribute information of the first picture object and the attribute information of the second picture object to generate a first target picture object code segment corresponding to the first picture object, wherein the first target picture object code segment is one of the M target object code segments; The attribute information of the second picture object and the attribute information of the second picture object are called back to generate a second target picture object code segment corresponding to the second picture object, wherein the second target picture object code segment is one of the M target object code segments.
10. The data processing method according to claim 1, characterized in that: The creating M target objects and generating M target object code segments corresponding to the M target objects according to the M original object code segments include: Creating a network request object, wherein the network request object is one of the M target objects; Configuring properties of the network request object, wherein the properties of the network request object include event distribution and message acquisition; The properties of the network request object are called back to generate a network request object code segment, wherein the network request object code segment is one of the M target object code segments.
11. The data processing method according to claim 1, characterized in that: The creating M target objects and generating M target object code segments corresponding to the M target objects according to the M original object code segments include: Creating an event mechanism object, wherein the event mechanism object is one of the M target objects; Acquire an object instance corresponding to the event mechanism object, wherein the object instance corresponding to the event mechanism object is obtained by running the event mechanism object in the target running environment; An event mechanism object code segment is generated according to the object instance corresponding to the event mechanism object, wherein the event mechanism object code segment is one of the M target object code segments.
12. A data processing device, characterized in that: include: an original code library file acquisition module, used to acquire an original code library file to be processed, wherein the original code library file is used in an original running environment, the original code library file includes M original objects and M original object code segments corresponding to the M original objects, the M original objects correspond to M functions, and the functions corresponding to the original objects are implemented by running the original object code segments, where M is an integer greater than or equal to 1; A target object and target object code segment generating module, used for creating M target objects, and generating M target object code segments corresponding to the M target objects according to the M original object code segments, wherein the M target objects have a corresponding relationship with the M original objects; An object instance generation module, used for running the M target object codes to generate an object instance combination, wherein the object instance combination includes M object instances; A global object and global object code segment generation module, used to create a global object according to the object instance combination, and to generate a global object code segment according to the global object, wherein the global object is used to implement access to the M target objects; The target code library file generation module is used to merge the global object code segment with the original code library file to generate a target code library file, wherein the target code library file is used in a target operating environment.
13. A computer device, characterized in that: include: memories, transceivers, processors, and bus systems; Wherein, the memory is used to store programs; The processor is used to execute the program in the memory, including executing the data processing method according to any one of claims 1 to 11; The bus system is used to connect the memory and the processor so that the memory and the processor can communicate with each other.
14. A computer-readable storage medium comprising instructions, characterized in that: When the method is executed on a computer, the computer is enabled to execute the data processing method according to any one of claims 1 to 11.
15. A computer program product comprising a computer program, characterized in that The computer program is used by a processor to execute the data processing method according to any one of claims 1 to 11.