Call interface data transmission method, system, computer equipment and storage medium
By using byte arrays for serialization and deserialization in mobile application development, the problems of low efficiency, loss of precision, and high maintenance costs in cross-language calls are solved, and efficient and accurate data transmission is achieved.
Patent Information
- Application Number
- CN202411056980.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2044-08-02
AI Technical Summary
In mobile application development, cross-language calling processes often encounter issues such as low calling efficiency, loss of data accuracy and types, and high maintenance costs. This is especially true when calling multiple language layers, as communication overhead increases and data type conversion impacts business logic.
By serializing and deserializing at the business request layer and implementation layer, the data is converted into byte array format, and the byte array is passed at the intermediate language layer, avoiding data structure conversion and using the byte array as an intermediate data type for cross-language transmission.
It improves cross-language calling efficiency, reduces communication overhead, ensures data accuracy and type invariance, reduces the interface maintenance workload of the intermediate language layer, and solves the problem of data type conversion.
Smart Images

Figure CN118819497B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of mobile application development, and in particular to a method, device, computer equipment and storage medium for transferring calling interface data. Background Art
[0002] Hybrid development techniques using multiple programming languages are widely used in mobile application development. In particular, the introduction of cross-platform scripting languages, such as Lua, has enhanced the dynamic nature of application development, enabling scripting capabilities and rapid iteration. When calling across different language layers, data must be exchanged smoothly between them. This typically involves using the data conversion functions provided by each language to convert the data format of the calling layer into a format understandable by the called layer.
[0003] In the related technology, the following problems exist in the existing calling process across different language layers: 1) Low calling efficiency: The two-way conversion of data structures in existing calls across different language layers will occur at the calling boundary of each two different languages, which adds additional communication overhead, and as the number of cross-language layers increases, the communication overhead will increase exponentially accordingly; 2) Data precision and data type may be lost in the intermediate language layer: Since each language has its own characteristics, due to the limitations of the intermediate language layer, the data type will cause changes in precision or data type during type conversion, thereby affecting business logic; 3) Increased maintenance costs: Each programming interface (API) has different types of parameters and return values, so code needs to be developed for each API separately to support the conversion of its data type. Summary of the Invention
[0004] In view of this, the present invention provides a calling interface data transmission method, system, computer device and storage medium to solve the problem of inconvenience caused by data conversion in cross-language calling.
[0005] In a first aspect, the present invention provides a method for transmitting call interface data, which is applied to a service request layer, and the method includes:
[0006] Get business call request data;
[0007] Serializing the service call request data and converting it to obtain first data, where the first data is a byte array;
[0008] Calling a transfer interface of an adjacent first language layer, inputting first data as an input parameter into the first language layer, until the first language layer transmits the first data to a business implementation layer through a second language layer, wherein the second language layer is a language layer adjacent to the business implementation layer, and the second language layer is directly connected to the first language layer, or the second language layer is connected to the first language layer through several intermediate language layers, so that the business implementation layer deserializes the first data to obtain second data corresponding to the first data in the business implementation layer, and determines a business function corresponding to the first data; calling the business function, processing the second data to obtain return value data; serializing and converting the return value data to obtain third data; and returning the third data to the second language layer as a return value after executing the transfer interface of the second language layer, until the second language layer returns the third data through the first language layer;
[0009] The third data returned by the first language layer is received, the third data is deserialized, and a structured return result corresponding to the third data is obtained to realize data transmission.
[0010] In the present invention, data is serialized and deserialized at the business request layer, and byte arrays are transmitted through the intermediate language layer, thereby realizing the transmission of business data. Since byte arrays are the basic data type common to all development languages, byte arrays are obtained by serializing and deserializing at the business request layer, and there is no need to perform data conversion during data transmission, thereby avoiding data structure conversion at the business request layer, the intermediate language layer, and the business implementation layer, and reducing communication overhead. The data transmitted in the intermediate language layer is a byte array, which can avoid the loss of data precision and data type caused by data conversion, solves the problem of conversion of various complex data types, and ensures that the data precision and data type do not change.
[0011] In an optional embodiment, the service call request data includes the name of the called service interface, the type of return value data of the service interface, and all input parameters of the service interface. The service call request data is serialized and converted to obtain the first data, including:
[0012] Encapsulate the name of the business interface, the type of the return value data of the business interface, and all input parameters of the business interface into a business call request data structure to obtain structured business call request data;
[0013] The structured business call request data is serialized and converted to obtain first data.
[0014] In this approach, the service call request data is serialized and converted into first data in a byte array format that is easily stored and transmitted, facilitating cross-language transmission of the first byte array format. Because byte arrays have a standard, unified support method, they can be easily transmitted across language layers without conversion. While maintaining the accuracy and format of the service call request data, there's no need to worry about whether the byte array contains structured data such as integers, strings, or arrays. This reduces the number of interfaces within each intermediate language layer.
[0015] In a second aspect, the present invention provides a method for transferring call interface data, which is applied to a business implementation layer and includes:
[0016] receiving first data transmitted by an adjacent second language layer, where the first data is obtained by the business request layer by obtaining business call request data and performing serialization conversion on the business call request data;
[0017] Deserialize the first data to obtain second data corresponding to the first data in the business implementation layer, and determine the business function corresponding to the first data;
[0018] Call the business function, process the second data, and obtain the return value data;
[0019] Serialize the return value data and convert it to obtain the third data;
[0020] The third data is returned to the second language layer as a return value after the transfer interface of the second language layer is executed, until the second language layer transmits the third data to the business request layer through the first language layer. The first language layer is a language layer adjacent to the business request layer. The first language layer is directly connected to the second language layer, or the first language layer is connected to the second language layer through several intermediate language layers, so that the business request layer deserializes the third data and obtains a structured return result corresponding to the third data, thereby realizing data transfer.
[0021] In the present invention, by deserializing and serializing data at the business implementation layer and transmitting byte arrays through the intermediate language layer, the business data is transmitted. Since the byte array is a basic data type common to all development languages, the byte array is obtained by deserializing and serializing at the business request layer, and there is no need to convert the data during the data transmission process, thereby avoiding the data structure conversion at the business request layer, the intermediate language layer and the business implementation layer, and reducing the communication overhead; the data transmitted in the intermediate language layer is a byte array, which can avoid the loss of data precision and data type caused by data conversion, solve the problem of conversion of various complex data types, and ensure that the data precision and data type do not change.
[0022] In an optional embodiment, the second data includes the name of the called business interface input by the business request layer, the type of the return value data of the business interface, and all input parameters of the business interface. The first data is deserialized to obtain the second data corresponding to the first data in the business implementation layer, including:
[0023] The first data is deserialized using a deserialization method corresponding to the serialization method adopted by the business request layer to obtain structured second data.
[0024] In this method, the byte array transmitted by the business request layer through the intermediate language layer is deserialized by the deserialization method corresponding to the business request layer to obtain the corresponding structured second data, without the need for data conversion in the intermediate language layer, thereby reducing communication overhead.
[0025] In an optional implementation, calling the business function, processing the second data, and obtaining the return value data includes:
[0026] Initiate an interface call request to the business module corresponding to the first data, input the second data into the business module, and obtain the initial return value data of the business interface call corresponding to the business module;
[0027] Get the expected return value of the business call, use the expected return value of the business call to verify the data type of the initial return value data, and obtain the return value data.
[0028] In this way, by calling the business function, business processing is performed on the structured data corresponding to the byte array to obtain the corresponding return value, thereby realizing business processing of the business request data. By verifying the return value data, the correctness of the data format of the returned data is further ensured.
[0029] In a third aspect, the present invention provides a method for transferring call interface data, which is applied to a language layer. The language layer includes at least a first language layer adjacent to a business request layer and a second language layer adjacent to a business implementation layer. The first language layer and the second language layer are directly connected, or the first language layer and the second language layer are connected through several intermediate language layers. The method includes:
[0030] The first language layer receives the first data input by the business request layer, uses the first data as an input parameter, calls the transfer interface of the next adjacent language layer, and passes the input parameter to the next adjacent language layer, until the first data is transmitted to the business implementation layer through the second language layer. The first data is obtained by the business request layer obtaining the business call request data and performing serialization conversion on the business call request data;
[0031] The second language layer receives the third data input by the business implementation layer, uses the third data as a return value, and returns the return value to the previous adjacent language layer until the third data is transmitted to the business request layer through the first language layer, so that the business request layer deserializes the third data and obtains a structured return result corresponding to the third data to realize data transmission. The third data is the business implementation layer deserializing the first data to obtain the second data corresponding to the first data in the business implementation layer, and determining the business function corresponding to the first data; calling the business function, processing the second data, and obtaining the return value data; and serializing and converting the return value data.
[0032] In the present invention, by utilizing the intermediate language layer to transmit byte arrays, data transmission without data conversion is achieved. The intermediate language layer transmits byte arrays, rather than a specific data type. Therefore, as long as the intermediate language layer supports the "byte array" type, it can be guaranteed that the data type and data precision will not be lost. Since each development language supports byte arrays, and byte arrays have the advantage of being lightweight when transmitted across language layers, the overhead of transmitting byte arrays when calling across language layers is extremely low, thereby improving the calling efficiency of the interface. By using byte arrays as the intermediate data type transmitted by the intermediate language layer, the problem of losing data type or data precision caused by unsupported data types in the intermediate language layer can be avoided. As long as the data type is supported by the business request layer and the business implementation layer, it can be transmitted to the other party regardless of whether the intermediate language layer supports it. With the help of byte arrays, the intermediate language layer only needs to provide a transmission interface to meet the request call and structure return of all different business interfaces, reducing the interface maintenance workload of the intermediate language layer and further improving the efficiency of data transmission.
[0033] In a fourth aspect, the present invention provides a call interface data transmission system, comprising: a business request layer, a business implementation layer, and a language layer, wherein the language layer comprises at least a first language layer adjacent to the business request layer and a second language layer adjacent to the business implementation layer, wherein the first language layer and the second language layer are directly connected, or the first language layer and the second language layer are connected via a plurality of intermediate language layers, and wherein the business request layer, the language layer, and the business implementation layer all use different languages;
[0034] The business request layer obtains business call request data; serializes the business call request data and converts it to obtain first data, where the first data is a byte array; calls the transfer interface of the first language layer and inputs the first data as an input parameter into the first language layer;
[0035] The first language layer receives the first data input by the business request layer, uses the first data as an input parameter, calls the transfer interface of the next adjacent language layer, and passes the input parameter to the next adjacent language layer, until the first data is transmitted to the business implementation layer through the second language layer;
[0036] The business implementation layer receives first data transmitted by the second language layer; deserializes the first data to obtain second data corresponding to the first data in the business implementation layer, and determines the business function corresponding to the first data; calls the business function, processes the second data, and obtains return value data; serializes the return value data and converts it to obtain third data; and returns the third data to the second language layer as the return value after the transfer interface of the second language layer is executed;
[0037] The second language layer receives the third data input by the business implementation layer, takes the third data as a return value, and returns the return value to the previous adjacent language layer until the third data is transmitted to the business request layer through the first language layer;
[0038] The business request layer receives the third data returned by the first language layer, deserializes the third data, and obtains a structured return result corresponding to the third data to implement data transmission.
[0039] In the present invention, by utilizing the intermediate language layer to transmit byte arrays in a call interface data transmission system, data transmission without data conversion is achieved. The intermediate language layer transmits byte arrays, rather than a specific data type. Therefore, as long as the intermediate language layer supports the "byte array" type, the data type and data precision will not be lost. Since each development language supports byte arrays, and byte arrays have the advantage of being lightweight when transmitted across language layers, the overhead of transmitting byte arrays when calling across language layers is extremely low, thereby improving the efficiency of interface calls. By using byte arrays as the intermediate data type transmitted by the intermediate language layer, the problem of losing data type or data precision due to unsupported data types in the intermediate language layer can be avoided. As long as the data type is supported by the service request layer and the service implementation layer, it can be transmitted to the other party regardless of whether the intermediate language layer supports it. With the help of byte arrays, the intermediate language layer only needs to provide a transmission interface to meet the request calls and structure returns of all different service interfaces, reducing the interface maintenance workload of the intermediate language layer and further improving the efficiency of data transmission.
[0040] In a fifth aspect, the present invention provides a computer device comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, computer instructions being stored in the memory, and the processor executing the computer instructions to thereby execute the calling interface data transmission method of the first aspect or any corresponding embodiment thereof, or the calling interface data transmission method of the second aspect or any corresponding embodiment thereof, or the calling interface data transmission method of the third aspect.
[0041] In the sixth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the calling interface data transmission method of the above-mentioned first aspect or any corresponding embodiment thereof, or to execute the calling interface data transmission method of the second aspect or any corresponding embodiment thereof, or to execute the calling interface data transmission method of the third aspect.
[0042] In the seventh aspect, the present invention provides a computer program product, including computer instructions, which are used to enable a computer to execute the calling interface data transmission method of the above-mentioned first aspect or any corresponding embodiment, or execute the calling interface data transmission method of the second aspect or any corresponding embodiment, or execute the calling interface data transmission method of the third aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 2 is a schematic diagram of the structure of a calling interface data transmission system according to an embodiment of the present invention.
[0045] Figure 2 2 is an interactive diagram of a calling interface data transmission system according to an embodiment of the present invention.
[0046] Figure 3 The present invention is a flowchart of a method for transmitting data when calling an interface across three or more language layers in a mobile application according to an embodiment of the present invention.
[0047] Figure 4 The figure is a flowchart of a method for transferring interface data according to an embodiment of the present invention.
[0048] Figure 5 It is a flowchart of another method for calling interface data transmission according to an embodiment of the present invention.
[0049] Figure 6 The figure is a flowchart of a cross-language calling method for layers 3 and above according to an embodiment of the present invention.
[0050] Figure 7 Schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0051] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present invention.
[0052] In the related technology, the following problems exist in the existing calling process across different language layers: 1) Low calling efficiency: The two-way conversion of data structures in existing calls across different language layers will occur at the calling boundary of each two different languages, which adds additional communication overhead, and as the number of cross-language layers increases, the communication overhead will increase exponentially accordingly; 2) Data precision and data type may be lost in the intermediate language layer: Since each language has its own characteristics, due to the limitations of the intermediate language layer, the data type will cause changes in precision or data type during type conversion, thereby affecting business logic; 3) Increased maintenance costs: Each programming interface (API) has different types of parameters and return values, so code needs to be developed for each API separately to support the conversion of its data type.
[0053] To address the above-mentioned issues, embodiments of the present invention provide a call interface data transmission system suitable for use in mobile application development scenarios involving mixed development using multiple programming languages and across three or more different language layers. The present invention provides a call interface data transmission system that utilizes an intermediate language layer to transmit byte arrays, achieving data transmission without data conversion. The intermediate language layer transmits byte arrays, rather than a specific data type. Therefore, as long as the intermediate language layer supports the "byte array" type, data type and data precision are guaranteed not to be lost. Since every development language supports byte arrays, and byte arrays are lightweight when transmitted across language layers, the overhead of transmitting byte arrays is minimal when making calls across language layers, improving interface call efficiency. By using byte arrays as the intermediate data type transmitted by the intermediate language layer, the problem of data type or data precision being lost due to unsupported data types in the intermediate language layer can be avoided. As long as the data type is supported by the service request layer and the service implementation layer, it can be transmitted to the other party regardless of whether the intermediate language layer supports it. With the help of byte arrays, the intermediate language layer only needs to provide a transfer interface to meet the request calls and structure returns of all different business interfaces, reducing the interface maintenance workload of the intermediate language layer and further improving the efficiency of data transmission.
[0054] In this embodiment, a calling interface data transmission system is provided. Figure 1FIG. 1 is a schematic diagram of a structure of a calling interface data transmission system according to an embodiment of the present invention. Figure 1 As shown, the system includes: a business request layer 1, a business implementation layer 4 and a language layer. The language layer includes at least a first language layer 2 adjacent to the business request layer 1 and a second language layer 3 adjacent to the business implementation layer 4. The first language layer 2 is directly connected to the second language layer 3, or the first language layer 2 and the second language layer 3 are connected through several intermediate language layers. The languages of the business request layer 1, the language layer and the business implementation layer 4 are all different.
[0055] Figure 2 Schematic diagram of the interaction of the calling interface data transmission system according to an embodiment of the present invention. In this embodiment, a calling interface data transmission method is provided, which can be used in the calling interface data transmission system, such as Figure 2 As shown, the business request layer 1 is used to execute steps S101 to S104, the business implementation layer 4 is used to execute steps S401 to S405, the first language layer 2 is used to execute step S201, and the second language layer 3 is used to execute step S301.
[0056] Step S101: Obtain service call request data.
[0057] Step S102: Serialize the service call request data and convert it into first data.
[0058] In the embodiment of the present invention, the first data is a byte array.
[0059] Step S103: calling the transfer interface of the first language layer and inputting the first data as an input parameter into the first language layer.
[0060] Step S201: Receive first data input from the business request layer, use the first data as input parameters, call the transfer interface of the next adjacent language layer, and pass the input parameters to the next adjacent language layer until the first data is transmitted to the business implementation layer through the second language layer.
[0061] Step S401: Receive first data transmitted by a second language layer.
[0062] Step S402: Deserialize the first data to obtain second data corresponding to the first data in the business implementation layer, and determine the business function corresponding to the first data.
[0063] Step S403: calling the business function, processing the second data, and obtaining return value data.
[0064] Step S404: Serialize the return value data and convert it into third data.
[0065] Step S405: Return the third data to the second language layer as a return value after the transfer interface of the second language layer is executed.
[0066] Step S301: Receive the third data input by the business implementation layer, use the third data as a return value, call the transfer interface of the previous adjacent language layer, and return the return value to the previous adjacent language layer until the third data is transmitted to the business request layer through the first language layer.
[0067] Step S104: receiving the third data returned by the first language layer, deserializing the third data, and obtaining a structured return result corresponding to the third data to implement data transfer.
[0068] In one implementation scenario, Figure 3 1 is a flow chart of a method for transmitting data when calling an interface across three or more layers of language in a mobile application according to an embodiment of the present invention. Figure 3 As shown, at the top-level business request layer A of the cross-language call, the interface location to be called, the structured data of the call, and the return value type are serialized (Marshal) according to a pre-selected serialization method. This converts the structured data in the language of the business request layer into a binary byte array Request, i.e., the first data. In the present invention, the serialization method can use any mature technology or a custom implementation, such as the open source library JSON, MsgPack, or ProtolBuffer.
[0069] Serialization converts structured data in a language into a format that is easy to store and transmit (typically in the form of a binary byte array, hereinafter referred to as a byte array). Byte arrays offer advantages such as ease of network transmission, protocol interpretation, and data storage. Serialization also facilitates cross-language transfer. While various development languages have different implementations for various data types (such as strings, integers, and arrays), they all have standardized, unified support for byte arrays. Therefore, byte arrays can be easily transferred between language layers without conversion.
[0070] Another benefit of introducing byte arrays as an intermediate data type is that it reduces the amount of business interface maintenance required at the intermediate language layer. Because the serialized byte array already contains the necessary information for the business interface being called, such as the interface name, return value type, and parameters, the intermediate language layer only needs a standard interface, called a transfer interface, to transmit requests and responses containing all the business interface information.
[0071] Therefore, serializing business data into byte arrays serves two purposes: first, to eliminate the need for data type conversion within the transfer interfaces of each intermediate language layer. Instead, the transfer interface of the intermediate language layer simply passes the byte array directly to the next language layer, regardless of whether the byte array contains structured data such as integers, strings, or arrays. Second, to reduce the number of interfaces within each intermediate language layer. Regardless of how many business interfaces are implemented (e.g., adding users, querying users, adding devices, querying devices, etc.), the intermediate language layer only needs one transfer interface, which accepts a single byte array input parameter and returns a single byte array return value, to satisfy all business interface requests.
[0072] At the top-level call initiation language layer (business request layer), the implementation steps of the transfer interface are:
[0073] 1) Encapsulate a specific business interface call request into a data structure, which includes: {business interface name, business interface return value type, business interface first input parameter, business interface second input parameter, ..., business interface nth input parameter}.
[0074] Taking the request to add a user as an example, the interface name for adding a user is "AddUser". The parameters required for the call are: user name, email address, and phone number. The return result after the call is the data structure <new user information>. The encapsulated data structure is such as: {"AddUser", <new user information>, user name, user email address, user phone number}.
[0075] 2) Use any serialization method to convert the above data structure into a byte array, and use it as the input parameter for calling the next language layer's interface. For example, using MsgPack to serialize the above data structure yields the following: "83a4 6e61 6d 65 61 6d 65a5 41 6c a5 41 6c 69 63 65 61 6d 65a5 416c a3 61 67 65le aa69 73 5f 73 74 75 64 65 6e 74c2 63 65a3 61 67 65le aa" This is converted into a binary byte array. Byte array data is easily passed to the next layer across languages. The next language layer no longer cares about fields such as the user name and email address, nor does it need to care whether each field is a string or integer.
[0076] 3) In the implementation of the transfer interface of the next language layer, the received byte array is used as an input parameter to call the transfer interface of the next language layer.
[0077] 4) Repeat the above steps until the byte array of the above input parameters is deserialized into the original data structure in the transmission interface of the lowest language layer, namely: {"AddUser", <new user information>, user name, user email, user phone number}, and the original business request information is obtained.
[0078] 5) At the lowest language layer (business implementation layer), based on the business request, the "AddUser" business interface is called, passing in all the business parameters from the request: user name, email address, and phone number. The result value returned from calling the "AddUser" interface should be the expected <new user information> type of data. For example, the <new user information> data returned from calling AddUser might be: {new user ID, new user creation time, and the server partition to which the new user belongs}.
[0079] 6) At the lowest language layer (the business implementation layer), the return value of the <new user information> type is serialized and converted into a byte array. This is then used as the return value of the language layer's interface and returned to the previous language layer in the call stack. For example, the serialized byte array of <new user information> is: "65a5 41 6c a541 6c 69 63 65 61 6d 65a5 41 6ca3 61 67 65le aa 69 73 5f 73".
[0080] 7) In the upper language layer, the byte array returned by the interface is passed to the upper layer as the return value.
[0081] 8) In the transfer interface of the top-level language layer (business request layer), the returned byte array is deserialized into structured data, for example: {new user ID, new user creation time, new user's server partition}. At this point, the call result is obtained at the top-level (business request layer), completing a cross-language call process.
[0082] From the above description, we can conclude that each language layer has a transfer interface for receiving and returning data of a byte array type, and this transfer interface will provide the "upload and download" data transfer function for all business interfaces, thereby reducing the overhead of the intermediate language layer in transferring call requests, solving the problem of data type loss and reduced precision due to insufficient support capabilities of the intermediate language layer, and reducing the workload of maintaining business interfaces.
[0083] Exemplarily, the method provided by the next language layer T1 is called: Response forwardCall(Request), wherein: Response and Request are both data of byte array type, and the forwardCall interface is the above-mentioned transfer interface, and each language layer will implement this interface.
[0084] In all intermediate language layers Ti (i=1...n) (intermediate transfer layers) for cross-language calls, a method called Response forwardCall(Request) is provided. Its implementation transparently passes the sole parameter Request and returns the call result Response, without parsing the meaning of the Request and Response data. In the transfer interface implementation of the intermediate language layer Ti, only a single input parameter of byte array type is accepted and only a single return value of byte array type is returned. In the present invention, the content and format of this byte array are not parsed.
[0085] Since every development language supports byte arrays, and byte arrays offer the advantage of portability when transferred across language layers—some development languages even provide zero-memory copy methods for transferring byte arrays—cross-language layer calls incur minimal overhead when transferring byte arrays, improving interface call efficiency. Furthermore, using byte arrays as the intermediate data type transferred by the intermediate language layer avoids the problem of data type loss or data precision during traditional data type conversions due to data types not supported by the intermediate language layer. As long as the top-level service request layer A and the bottom-level service implementation layer Z support the data type, they can be transferred to the other end, regardless of whether the intermediate language layer supports them. This is because the intermediate language layer transfers packaged byte arrays, not a specific data type. Therefore, as long as the intermediate language layer supports the byte array type, data type and data precision are guaranteed not to be lost. As can be seen from the above embodiments, byte arrays are a data type supported by nearly all mobile application development languages. Finally, using byte arrays allows the intermediate language layer to provide only one transfer interface to satisfy the request calls and structure returns of all different service interfaces, reducing the interface maintenance workload of the intermediate language layer.
[0086] In the cross-language call business implementation layer Z, the byte array Request is deserialized (Unmarshal) and converted into structured data in the business implementation layer. Based on the interface location, call data, and return value type contained in this structured data, specific business functions are called and the return results are obtained. Structured data is easy to read and easy to develop software. For example, the following example shows the structured data for adding a user request:
[0087] {
[0088] "api":"AddUser",
[0089] "result":"NewUserInfo",
[0090] "name":"Alice",
[0091] "email":"alice@google.com"
[0092] }
[0093] Correspondingly, binary byte arrays facilitate cross-language transmission, cross-network transmission, and storage. For example, the above structured data, after serialization using MsgPack technology, obtains the following result: "83a4 6e 61 6d 65a5 416c 69 63 65a3 61 67 65le aa 69 73 5f 73 74 75 64 65 6e 74c263 65a3 61 67 65leaa". This byte array can be converted into the above structured data structure using "deserialization", an operation opposite to "serialization". The present invention does not include new serialization and deserialization technologies, so the serialization technology is not limited. Serialization is only used as one of the implementation technologies of the present invention.
[0094] At the intermediate language layer Ti, a serialized byte array is passed. However, at the business implementation layer Z, this byte array needs to be deserialized into structured data. For example, after deserializing the byte array into structured data, based on the "api" contained in it being "AddUser," the AddUser interface of the user management module is called, passing in the parameters "name" and "email," thus achieving the purpose of calling the business interface (adding a user). After calling the "AddUser" interface, the return value type should be "NewUserInfo." This field serves to verify the result type and prepare for serialization of the returned result.
[0095] The result data after the business function call is also serialized (Marshal) into a binary byte array Response using the pre-selected serialization method, and is returned to the A layer in the opposite direction as the return value of the forwardCall() function of the Ti (i=1..n) layer.
[0096] Each two layers of the cross-language layer call described in the present invention belong to different development languages. Each development language has its own different data type set and implementation method. When calling across language layers, it is necessary to perform corresponding type conversion for each data type. For example, when JAVA calls C language, it is necessary to convert JAVA's java.lang.String type to C language's const char* type. This data type conversion will cause runtime overhead. Similarly, in the opposite direction, when the cross-language layer function call returns, this data type conversion must also be performed, which also has overhead. In existing technical implementations, this conversion needs to be performed one by one for all fields contained in each parameter. For example, taking the aforementioned "AddUser" interface as an example, the string types of name, email, and api need to be converted separately. When the call returns, all fields in the "NewUserInfo" structure need to be converted separately.
[0097] Therefore, only at the top layer, A, is the structured data serialized into a byte array. When the byte array is passed through the various language layers, it does not need to be converted individually for each data type contained in it (such as the string-type user name and user email address contained in the aforementioned user interface). This reduces the type conversion overhead of the intermediate language layer and avoids the problem of losing data type and data precision due to the data type restrictions of the intermediate language layer. Finally, at the bottom layer, Z, the byte array is deserialized into structured data to complete the identification and calling of the business interface. After that, the return value of the business interface is called, serialized and converted into a byte array, and then returned to the A layer in the opposite direction. After deserialization and conversion into structured data, it reaches the application layer to implement subsequent business functions.
[0098] Layer A deserializes (Unmarshal) the received Response data, converts it into structured business data, and obtains the final result.
[0099] The call interface data transmission method provided in this embodiment achieves data transmission without data conversion by utilizing an intermediate language layer to transmit byte arrays within the call interface data transmission system. The intermediate language layer transmits byte arrays, not a specific data type. Therefore, as long as the intermediate language layer supports the "byte array" type, data type and data precision are guaranteed not to be lost. Since every development language supports byte arrays, and byte arrays are lightweight when transmitted across language layers, the overhead of transmitting byte arrays during cross-language layer calls is minimal, improving interface call efficiency. By using byte arrays as the intermediate data type transmitted by the intermediate language layer, the problem of data type or data precision loss caused by unsupported data types in the intermediate language layer is avoided. As long as the data type is supported by the service request layer and the service implementation layer, it can be transmitted to the other party regardless of whether the intermediate language layer supports it. With byte arrays, the intermediate language layer only needs to provide a single transmission interface to satisfy all different service interface request calls and structure returns, reducing the interface maintenance workload of the intermediate language layer and further improving data transmission efficiency.
[0100] In this embodiment, a method for transferring data through a calling interface is provided, which can be used in the above-mentioned service request layer. Figure 4 FIG. 1 is a flow chart of a method for transferring interface data according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:
[0101] Step S101: Obtain service call request data.
[0102] Step S102: Serialize the service call request data and convert it into first data.
[0103] In the embodiment of the present invention, the first data is a byte array.
[0104] Specifically, the service call request data includes the name of the called service interface, the type of return value data of the service interface, and all input parameters of the service interface. The service call request data is serialized and converted to obtain the first data. The above step S102 includes:
[0105] Step S1021 : Encapsulate the name of the service interface, the type of the return value data of the service interface, and all input parameters of the service interface into a service call request data structure to obtain structured service call request data.
[0106] Step S1022: Serialize the structured service call request data and convert it into first data.
[0107] In this approach, the service call request data is serialized and converted into first data in a byte array format that is easily stored and transmitted, facilitating cross-language transmission of the first byte array format. Because byte arrays have a standard, unified support method, they can be easily transmitted across language layers without conversion. While maintaining the accuracy and format of the service call request data, there's no need to worry about whether the byte array contains structured data such as integers, strings, or arrays. This reduces the number of interfaces within each intermediate language layer.
[0108] Step S103: Call the transfer interface of the adjacent first language layer, input the first data as an input parameter into the first language layer, until the first language layer transmits the first data to the business implementation layer through the second language layer, so that the business implementation layer deserializes the first data, obtains the second data corresponding to the first data in the business implementation layer, and determines the business function corresponding to the first data; calls the business function, processes the second data, and obtains return value data; serializes the return value data, and converts it to obtain third data; calls the transfer interface of the adjacent second language layer, and returns the third data to the second language layer as the return value after the execution of the transfer interface of the second language layer, until the second language layer returns the third data through the first language layer.
[0109] In the embodiment of the present invention, the second language layer is a language layer adjacent to the business implementation layer. The second language layer is directly connected to the first language layer, or the second language layer is connected to the first language layer through several intermediate language layers.
[0110] Step S104: receiving the third data returned by the first language layer, deserializing the third data, and obtaining a structured return result corresponding to the third data to implement data transfer.
[0111] In one example, the main functions implemented in the transfer interface of the top-level language layer (call initiation layer, i.e., business request layer A) are:
[0112] a. Downward call: Encapsulate the name of the business interface to be called, the return value data type of the business interface, and all input parameters of the business interface into a business call request data structure, and serialize the data structure into a byte array using a certain serialization method; call the transfer interface of the next language layer and pass in the byte array.
[0113] b. Return from the business layer: Deserialize the byte array type result value returned by the next language layer transfer interface into structured data. The structured data contains all the result values returned after the business interface is called, and return the structured data to the upper application layer.
[0114] The call interface data transmission method provided in this embodiment serializes the service call request data and converts it into first data in a byte array format that is easy to store and transmit, thereby facilitating cross-language transmission of the first byte array data. Because byte arrays have a standard and unified support method, byte arrays can be easily transmitted across language layers without conversion. While maintaining the accuracy and data format of the service call request data, there is no need to worry about whether the byte array contains structured data such as integers, strings, and arrays. This can reduce the number of interfaces in each intermediate language layer.
[0115] In this embodiment, a method for transferring data through a calling interface is provided, which can be used in the above-mentioned business implementation layer. Figure 5 is a flowchart of another method for transferring interface data according to an embodiment of the present invention. Figure 5 As shown, the process includes the following steps:
[0116] Step S401: Receive first data transmitted by an adjacent second language layer.
[0117] In the embodiment of the present invention, the first data is obtained by the service request layer acquiring the service call request data and performing serialization conversion on the service call request data.
[0118] Step S402: Deserialize the first data to obtain the second data corresponding to the first data in the business implementation layer, and determine the business function corresponding to the first data.
[0119] Specifically, the second data includes the name of the called business interface input by the business request layer, the type of return value data of the business interface, and all input parameters of the business interface. The above step S402 includes:
[0120] Step S4021 : Deserialize the first data using a deserialization method corresponding to the serialization method adopted by the business request layer to obtain structured second data.
[0121] In this method, the byte array transmitted by the business request layer through the intermediate language layer is deserialized by the deserialization method corresponding to the business request layer to obtain the corresponding structured second data, without the need for data conversion in the intermediate language layer, thereby reducing communication overhead.
[0122] Step S403: calling the business function, processing the second data, and obtaining return value data.
[0123] Specifically, the above step S403 includes:
[0124] Step S4031: Initiate an interface call request to the business module corresponding to the first data, input the second data into the business module, and obtain the initial return value data of the business interface call corresponding to the business module.
[0125] Step S4032: Obtain the expected return value of the business call, and use the expected return value of the business call to verify the data type of the initial return value data to obtain the return value data.
[0126] Step S404: Serialize the return value data and convert it into third data.
[0127] Step S405: Return the third data to the second language layer as the return value after the transfer interface of the second language layer is executed, until the second language layer transmits the third data to the business request layer through the first language layer, so that the business request layer deserializes the third data and obtains a structured return result corresponding to the third data to realize data transfer.
[0128] In the embodiment of the present invention, the first language layer is a language layer adjacent to the service request layer. The first language layer is directly connected to the second language layer, or the first language layer is connected to the second language layer through several intermediate language layers.
[0129] In one example, the functions implemented by the transfer interface at the lowest language layer (call receiving layer, i.e., business implementation layer Z) are:
[0130] a. Calling the business layer: The byte array type input parameter received from the upper language layer is deserialized into structured data using the corresponding deserialization method. The data structure contains the business call request data passed in by the top-level language layer: the business interface name, the return value data type of the business interface, and all input parameters of the business interface.
[0131] Based on this information, an interface call is initiated to the corresponding business module, all parameters are input, the return value of the business interface call is obtained, and the return value is verified with the expected return value data type in the business call request.
[0132] b. Return upward: Serialize the structured return value data returned by the above interface call into a byte array and return it to the upper language layer as the return value of the interface passed at this layer.
[0133] The calling interface data transmission method provided in this embodiment processes the byte array transmitted by the business request layer through the intermediate language layer through the deserialization method corresponding to the business request layer, and obtains the corresponding structured second data. There is no need to perform data conversion in the intermediate language layer, thereby reducing communication overhead.
[0134] In one implementation scenario, Figure 6 : is a flowchart of a cross-language calling method for three layers and above according to an embodiment of the present invention, such as Figure 6 As shown, cross-language calls for layers three and above include:
[0135] 1) The main functions implemented in the transfer interface of the top-level language layer (the call initiation layer, i.e., the business request layer A) are: a. Downward call: The name of the business interface to be called, the return value data type of the business interface, and all input parameters of the business interface are encapsulated into a business call request data structure, and this data structure is serialized into a byte array using a serialization method; the transfer interface of the next language layer is called and the byte array is passed in. b. Return from the business layer: The result value of the byte array type returned by the transfer interface of the next language layer is deserialized into structured data containing all the result values returned after the business interface call, and this structured data is returned to the upper application layer.
[0136] 2) The functions implemented in the transfer interface of one or more intermediate language layers (calling transit layer Ti) include: a. Downward call: the transfer interface of the next language layer is called by passing the byte array type input parameter received from the previous language layer as the input parameter in the form of a memory block. b. Upward return: the result value of the byte array type returned by the transfer interface of the next language layer is returned to the transfer interface of the previous language layer in the form of a memory block as the return value.
[0137] 3) The functions implemented by the transfer interface at the lowest language layer (call receiving layer, i.e. business implementation layer Z) are as follows: a. Calling the business layer: using the corresponding deserialization method to deserialize the byte array input parameters received from the previous language layer into structured data. The data structure contains the business call request data passed in by the top language layer: the business interface name, the return value data type of the business interface, and all input parameters of the business interface. Based on this information, an interface call is initiated to the corresponding business module, all parameters are input, and the return value of the business interface call is obtained. The return value is then verified against the expected return value data type in the business call request. b. Returning upward: the structured return value data returned by the above interface call is serialized and converted into a byte array, which is returned to the upper language layer as the return value of the transfer interface at this layer.
[0138] The embodiment of the present invention also provides a computer device. Figure 7 , Figure 7 is a structural diagram of a computer device provided by an optional embodiment of the present invention, such as Figure 7As shown, the computer device includes: one or more processors 10, memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components utilize different buses to communicate with each other and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in the memory or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Equally, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.
[0139] The processor 10 may be a central processing unit, a network processor, or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic, or any combination thereof.
[0140] The memory 20 stores instructions that can be executed by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.
[0141] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created based on the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0142] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0143] The computer device further includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 7 The bus connection is taken as an example.
[0144] The input device 30 can receive input digital or character information and generate key signal input related to user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a trackpad, a touch pad, an indicator stick, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 can include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor). The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display, and a plasma display. In some optional embodiments, the display device can be a touch screen.
[0145] The embodiment of the present invention also provides a computer-readable storage medium. The above-mentioned method according to the embodiment of the present invention can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the method shown in the above embodiment is implemented.
[0146] A portion of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the form in which the computer program instruction exists in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc. Accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium that can be accessed by the computer.
[0147] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A method for transferring data by calling an interface, characterized in that: Applied to the service request layer, the method includes: Get business call request data; Serializing the service call request data to obtain first data, where the first data is a byte array; Calling a transfer interface of an adjacent first language layer, inputting the first data as an input parameter into the first language layer, until the first language layer transmits the first data to a business implementation layer through a second language layer, wherein the second language layer is a language layer adjacent to the business implementation layer, and the second language layer is directly connected to the first language layer, or the second language layer is connected to the first language layer through several intermediate language layers, so that the business implementation layer deserializes the first data to obtain second data corresponding to the first data in the business implementation layer, and determines a business function corresponding to the first data; calling the business function, processing the second data to obtain return value data; serializing the return value data and converting it to obtain third data; returning the third data to the second language layer as the return value after executing the transfer interface of the second language layer, until the second language layer returns the third data through the first language layer; the languages of the business request layer, the language layer, and the business implementation layer are all different; The third data returned by the first language layer is received, the third data is deserialized, and a structured return result corresponding to the third data is obtained to realize data transmission.
2. The method according to claim 1, characterized in that The service call request data includes the name of the called service interface, the type of return value data of the service interface, and all input parameters of the service interface. The serializing the service call request data to obtain the first data includes: Encapsulate the name of the service interface, the type of the return value data of the service interface, and all input parameters of the service interface into a service call request data structure to obtain structured service call request data; The structured service call request data is serialized and converted to obtain the first data.
3. A method for transferring data by calling an interface, characterized in that: Applied to the business implementation layer, the method includes: receiving first data transmitted by an adjacent second language layer, where the first data is obtained by a service request layer by serializing and converting service call request data; the first data is a byte array; Deserialize the first data to obtain second data corresponding to the first data in the business implementation layer, and determine a business function corresponding to the first data; Calling the business function, processing the second data, and obtaining return value data; Serializing the return value data to obtain third data; The third data is returned to the second language layer as a return value of the transfer interface of the second language layer until the second language layer transmits the third data to the business request layer through the first language layer. The first language layer is a language layer adjacent to the business request layer. The first language layer is directly connected to the second language layer, or the first language layer is connected to the second language layer through several intermediate language layers, so that the business request layer deserializes the third data and obtains a structured return result corresponding to the third data, thereby realizing data transfer. The languages of the business request layer, the language layer, and the business implementation layer are all different.
4. The method according to claim 3, characterized in that The second data includes the name of the called business interface input by the business request layer, the type of the return value data of the business interface, and all input parameters of the business interface. The deserialization of the first data to obtain the second data corresponding to the first data in the business implementation layer includes: The first data is deserialized using a deserialization method corresponding to the serialization method adopted by the business request layer to obtain structured second data.
5. The method according to claim 4, characterized in that The calling of the business function and processing of the second data to obtain the return value data includes: Initiate an interface call request to the business module corresponding to the first data, input the second data into the business module, and obtain the initial return value data of the business interface call corresponding to the business module; The expected return value of the service call is obtained, and the data type of the initial return value data is verified using the expected return value of the service call to obtain the return value data.
6. A method for transferring data by calling an interface, characterized in that: Applied to a language layer, the language layer includes at least a first language layer adjacent to a service request layer and a second language layer adjacent to a service implementation layer, the first language layer and the second language layer being directly connected, or the first language layer and the second language layer being connected via several intermediate language layers, the method comprising: The first language layer receives first data input by the business request layer, uses the first data as an input parameter, calls a transfer interface of a next adjacent language layer, and passes the input parameter to the next adjacent language layer, until the first data is transmitted to the business implementation layer through the second language layer. The first data is obtained by the business request layer by obtaining business call request data and serializing and converting the business call request data; the first data is a byte array. The second language layer receives the third data input by the business implementation layer, uses the third data as a return value, and returns the return value to the previous adjacent language layer until the third data is transmitted to the business request layer through the first language layer, so that the business request layer deserializes the third data and obtains a structured return result corresponding to the third data to realize data transmission. The third data is the first data deserialized by the business implementation layer to obtain the second data corresponding to the first data in the business implementation layer, and determine the business function corresponding to the first data; call the business function, process the second data, and obtain return value data; the return value data is obtained by serializing and converting, and the languages between the business request layer, language layer and business implementation layer are different.
7. A calling interface data transmission system, characterized in that: The system includes: a service request layer, a service implementation layer, and a language layer, wherein the language layer includes at least a first language layer adjacent to the service request layer and a second language layer adjacent to the service implementation layer, the first language layer and the second language layer being directly connected, or connected via several intermediate language layers, and the service request layer, the language layer, and the service implementation layer all being in different languages; The service request layer obtains service call request data; serializes the service call request data and converts it into first data, where the first data is a byte array; calls the transfer interface of the first language layer and inputs the first data as an input parameter into the first language layer; The first language layer receives the first data input by the business request layer, uses the first data as an input parameter, calls a transfer interface of a next adjacent language layer, and passes the input parameter to the next adjacent language layer, until the first data is transmitted to the business implementation layer through the second language layer; The business implementation layer receives the first data transmitted by the second language layer; deserializes the first data to obtain second data corresponding to the first data in the business implementation layer, and determines a business function corresponding to the first data; calls the business function to process the second data to obtain return value data; serializes the return value data to convert it to obtain third data; and returns the third data to the second language layer as a return value after the transfer interface of the second language layer is executed; The second language layer receives the third data input by the business implementation layer, takes the third data as a return value, and returns the return value to the previous adjacent language layer until the third data is transmitted to the business request layer through the first language layer; The business request layer receives the third data returned by the first language layer, deserializes the third data, and obtains a structured return result corresponding to the third data to achieve data transfer.
8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the calling interface data transmission method according to any one of claims 1 to 6 by executing the computer instructions.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the calling interface data transmission method according to any one of claims 1 to 6.
10. A computer program product, characterized in that The method comprises computer instructions for causing a computer to execute the method for transmitting calling interface data according to any one of claims 1 to 6.
Citation Information
Patent Citations
Virtualization technology and method for environment execution during cross-language running of an application program
CN109871284A
Interface transmission method, apparatus and device
WO2019105010A1