Method, device, vehicle and storage medium for generating code

By classifying the request fields in the contract file to generate general and attribute code blocks, the problem of large amount of generated code is solved, and small and accurate contract code is achieved, which improves the efficiency of code generation and the reliability of the interaction process.

CN119806496BActive Publication Date: 2025-09-26GREAT WALL MOTOR CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411763453.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-09-26
Estimated Expiration
2044-12-03

AI Technical Summary

Technical Problem

In the existing technology, when generating contract code, there is a problem of large code volume, resulting in low efficiency.

Method used

By classifying the request fields in the contract file, generating common contract code blocks and attribute code blocks, combining the commonalities and differences of the request fields, and reducing duplicate code.

Benefits of technology

The generated contract code is small and accurate, which improves the efficiency and accuracy of code generation and avoids abnormal phenomena of the target client during the interaction process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119806496B_ABST
    Figure CN119806496B_ABST
Patent Text Reader

Abstract

The present application provides a method, device, vehicle and storage medium for generating codes. The method classifies N request fields in the request content in the contract file to obtain M groups of request fields. For any group of request fields, the data types corresponding to the multiple request fields therein are the same, and the contract code (universal contract code block) can be generated based on the same code conversion strategy. That is, a universal contract code block is generated by the common content in multiple request fields. In this way, the generation of duplicate codes can be avoided. Furthermore, on the basis of the universal contract code block, an attribute code block of the universal contract code block corresponding to each group of request fields is generated, which retains the differences of the request fields in each group of request fields. Finally, the universal contract code block and the attribute code block corresponding to each group of request fields in the M groups of request fields are combined to obtain the contract code. Therefore, the method can generate a small amount of code and accurate contract code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of vehicles, and more particularly, to a method, device, vehicle, and storage medium for generating a code in the field of vehicles. Background Art

[0002] With the rapid development of information networks, data communication between multiple communicating parties can be achieved through service calls. The party initiating the call is called the service caller, and the party being called is called the service provider. The service caller can be the client, and the service provider can be the server. When a client performs a task and needs to communicate structured data with the server, the client must comply with the contract document and send data to the server according to the content defined in the contract document.

[0003] Contract files are typically written in a specific format. To facilitate client understanding and execution, they are typically converted into contract code to automate execution and improve efficiency. Related technologies generate contract code for each request field within the request content defined in the contract file. This results in a significant amount of duplicated code and, ultimately, a large amount of generated contract code.

[0004] Therefore, a method for generating code is urgently needed to reduce the amount of contract code. Summary of the Invention

[0005] The present application provides a method, device, vehicle and storage medium for generating codes, which can generate contract codes with small code volume and accuracy.

[0006] In a first aspect, a method for generating code is provided, the method comprising: obtaining a contract file supported by a target client and a corresponding target server, the contract file being used to define the request content sent by the target client to the target server when executing a target task, the request content comprising N request fields, the request field being a request code line after the request content is written in a specific format, where N is a positive integer greater than 1; classifying the N request fields based on the data type corresponding to each request field, determining M groups of request fields, where the data type corresponding to each request field in each group of request fields is the same, where M is a positive integer greater than or equal to 1; and using any group of request fields as the target group of request fields. Generate a universal contract code block corresponding to the target group request field, the target group request field corresponds to a universal contract code block, the universal contract code block is used to indicate the commonality of the request fields in the target group request field; generate an attribute code block corresponding to the universal contract code block of the target group request field, the target group request field corresponds to an attribute code block, the attribute code block is used to indicate the difference of the request fields in the target group request field; combine the universal contract code blocks and attribute code blocks corresponding to each group of request fields in the M groups of request fields to obtain the contract code of the contract file, the contract code is the programming language code obtained after converting the request content written in a specific format in the contract file.

[0007] In the above technical solution, in the process of generating the corresponding contract code for the contract file, the method classifies the N request fields in the request content in the contract file to obtain M groups of request fields. For any group of request fields, the data types corresponding to the multiple request fields therein are the same, and the contract code can be generated based on the same code conversion strategy, so that the general contract code block corresponding to each group of request fields can be determined. In other words, the common content in the multiple request fields is extracted by the data type, and a general contract code block is generated based on the common content. In this way, the method avoids the generation of duplicate code. Furthermore, on the basis of the general contract code block corresponding to each group of request fields, an attribute code block of the general contract code block corresponding to each group of request fields is generated, which retains the differences of the request fields in each group of request fields. Finally, the method combines the general contract code block and the attribute code block corresponding to each group of request fields in the M groups of request fields to obtain the contract code of the contract file. Therefore, the method can generate a small amount of code and accurate contract code.

[0008] In combination with the first aspect, in some possible implementations, the method for determining the data type corresponding to each request field includes: determining the writing structure of the request content based on the target task and the request type corresponding to the request content; and extracting the data type corresponding to each request field from the request content based on the writing structure through a target extraction tool.

[0009] In the above technical solution, the written structure of the request content corresponding to different request tasks and different request types is different. Therefore, this method accurately determines the written structure of the request content by combining the target task and the request type corresponding to the request content. In this way, the distribution of the multiple request fields specifically included in the request content can be clearly determined. On this basis, the method can use the target extraction tool to accurately extract the data type corresponding to each request field from the request content, thereby facilitating the subsequent generation of accurate general contract code blocks.

[0010] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, a general contract code block corresponding to the target group request field is generated, including: based on the data type corresponding to the target group request field, generating an annotation code line corresponding to the target group request field; based on the data type, target keyword and target code content corresponding to the target group request field, generating a content code line corresponding to the target group request field, the target keyword is used to indicate the request level corresponding to each request field in the target group request field, and the target code content corresponds to the code content in the attribute code block; the annotation code line and the content code line are combined to generate a general contract code block corresponding to the target group request field.

[0011] In the above technical solution, for each request field in any group of request fields, the generation process of the corresponding contract code is similar. Therefore, the above method takes any group of request fields (target group request fields) in the M groups of request fields as an example to describe the generation process of the universal contract code corresponding to the target group request field. In this method, based on the data type corresponding to the target group request field, the annotation code line corresponding to the target group request field is generated, and based on the data type, target keyword and target code content corresponding to the target group request field, the content code line corresponding to the target group request field is generated. Further, the annotation code line and the content code line are combined to generate a universal contract code block corresponding to the target group request field. This makes it possible to understand which data types of request fields the universal contract code block is applicable to, based on the annotation code line, and which positions of the code in the universal contract code block correspond to the attribute code block, that is, it is related to the code in the attribute code block used to indicate the difference of the request field.

[0012] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the attribute information of each request field includes the field name and the corresponding request order, and the attribute code block of the general contract code block corresponding to the target group request field is generated, including: based on the request order corresponding to each request field in the target group request field, through the field name of each request field, the attribute code block of the general contract code block corresponding to the target group request field is generated.

[0013] In the above technical solution, for the target group request field, based on the request order corresponding to each request field in the target group request field, the attribute code block of the general contract code block corresponding to the target group request field is generated through the field name of each request field. In this way, the attribute code block includes code content corresponding to the target code content, and the code content can be at least one field name. Of course, in this method, the specific target code content is only schematically represented by the code content in the attribute code block, and no real replacement operation is performed. In this way, not only can the differences of the request fields in the target group request field be characterized, but also unnecessary code volume can be avoided after the code is substituted.

[0014] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the contract file is also used to define the response format expected by the target client, and the contract code is used by the target client to parse the received response content. The method also includes: using a target extraction tool, extracting the actual response value corresponding to each of the N request fields from the response content based on the response format to obtain N actual response values; based on the N actual response values ​​and the contract code, determining whether an abnormality occurs in the interaction process between the target client and the target server; if no abnormality occurs in the interaction process, performing base-to-base conversion on the N actual response values ​​to obtain a target response value corresponding to each actual response value, and the target response value is used to execute the target task.

[0015] In the above technical solution, the target server responds to the request content in a fixed format. Therefore, in this method, the target extraction tool can extract the actual response value (N actual response values) corresponding to each of the N request fields from the response content based on the response format. Furthermore, based on the N actual response values ​​and the data contract (contract code) to be complied with, the method determines whether an abnormality has occurred in the interaction process between the target client and the target server. This can determine whether the interaction process may be under attack. If the interaction process is not abnormal, the method converts the N actual response values ​​into a base and further executes the target task. In other words, the method verifies the actual response values ​​and only executes the target task using the N actual response values ​​when the status of the interaction process indirectly reflects that the N actual response values ​​are correct. This method can avoid the target client processing the abnormal actual response values ​​when the interaction process is abnormal, thereby causing abnormal phenomena on the target client, which include at least one of system crash, data resource leakage, attack, data corruption, and consumption of additional computing resources in the target client.

[0016] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, based on the N actual response values ​​and the contract code, it is determined whether an abnormality occurs in the interaction process between the target client and the target server, including: based on the N actual response values ​​and the contract code, determining the matching degree of the interaction function between the target client and the target server to verify the target server; when the matching degree is greater than or equal to the preset matching degree, determining whether an abnormality occurs in the interaction process based on the delay duration of the response content.

[0017] In the above technical solution, if the matching degree of the interactive function between the target client and the target server is higher, it indicates that the target server is more capable of responding to the request content in accordance with the data contract. Therefore, the method determines the matching degree based on the N actual response values ​​and the contract code. When the matching degree is large, it indicates that the target server has complied with the data contract, but the target server may not respond to the request content in time, and the interaction process is abnormal. Therefore, when the matching degree is greater than or equal to the preset matching degree, it is also necessary to judge the delay duration of the response content. The above process can avoid the situation where the target server responds to the request content with a timeout, but complies with the data contract. Therefore, the method can accurately determine whether the interaction process between the target client and the target server is abnormal through the above two stages.

[0018] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the matching degree of the interactive function between the target client and the target server is determined based on the N actual response values ​​and the contract code, including: determining a first matching degree based on the actual data type corresponding to each actual response value in the N actual response values ​​and the corresponding data type in the contract code, and the first matching degree is used to measure the matching degree of the data type when the target server responds to the request content; determining a second matching degree based on the response order corresponding to each actual response value in the N actual response values ​​and the corresponding arrangement order in the contract code, and the second matching degree is used to measure the matching degree of the response order when the target server responds to the N request fields; and performing weighted summation of the first matching degree and the second matching degree to obtain the matching degree.

[0019] In the above technical solution, the target client sends a request content to the target server, and the target server sends a response content to the target client, so as to realize the interactive function between the target client and the target server. The response content is the response result (N actual response values) to the N request fields in the request content, and each request field has a corresponding arrangement order and data type. Therefore, it is necessary to comprehensively determine the matching degree based on the two attributes of arrangement order and data type. Specifically, based on the actual data type corresponding to each actual response value in the N actual response values ​​and the corresponding data type in the data contract (contract code), the first matching degree is determined; based on the response order corresponding to each actual response value in the N actual response values ​​and the corresponding arrangement order in the contract code, the second matching degree is determined, and the first matching degree and the second matching degree are weighted and summed to determine the matching degree. This method can avoid the low accuracy when determining the matching degree based on a single attribute.

[0020] In a second aspect, a device for generating code is provided, which includes: an acquisition module for acquiring a contract file supported by a target client and a corresponding target server, the contract file being used to define the request content sent by the target client to the target server when executing a target task, the request content including N request fields, the request field being a request code line after the request content is written in a specific format, N being a positive integer greater than 1; a determination module for classifying the N request fields based on the data type corresponding to each request field, determining M groups of request fields, the data type corresponding to each request field in each group of request fields being the same, M being a positive integer greater than or equal to 1; a generation module for: using any group of request fields as a target A target group request field is generated, and a universal contract code block corresponding to the target group request field is generated. The target group request field corresponds to a universal contract code block, and the universal contract code block is used to indicate the commonality of the request fields in the target group request field; an attribute code block is generated for the universal contract code block corresponding to the target group request field. The target group request field corresponds to an attribute code block, and the attribute code block is used to indicate the difference of the request fields in the target group request field; a combination module is used to combine the universal contract code blocks and attribute code blocks corresponding to each group of request fields in the M groups of request fields to obtain the contract code of the contract file, and the contract code is the programming language code obtained after converting the request content written in a specific format in the contract file.

[0021] In combination with the second aspect, in some possible implementations, the determination module is specifically used to determine the writing structure of the request content based on the target task and the request type corresponding to the request content; the device also includes: an extraction module, used to extract the data type corresponding to each request field from the request content based on the writing structure through a target extraction tool.

[0022] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the generation module is specifically used to: generate an annotation code line corresponding to the target group request field based on the data type corresponding to the target group request field; generate a content code line corresponding to the target group request field based on the data type, target keyword and target code content corresponding to the target group request field, the target keyword is used to indicate the request level corresponding to each request field in the target group request field, and the target code content corresponds to the code content in the attribute code block; combine the annotation code line and the content code line to generate a general contract code block corresponding to the target group request field.

[0023] In combination with the second aspect and the above-mentioned implementation method, in some possible implementation methods, the generation module is specifically used to generate the attribute code block of the general contract code block corresponding to the target group request field based on the request order corresponding to each request field in the target group request field and through the field name of each request field.

[0024] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the contract file is also used to define the response format expected by the target client, and the contract code is used by the target client to parse the received response content. The extraction module is specifically used to extract the actual response value corresponding to each request field in the N request fields from the response content based on the response format through a target extraction tool to obtain N actual response values; the determination module is specifically further used to determine whether an abnormality occurs in the interaction process between the target client and the target server based on the N actual response values ​​and the contract code; the device also includes: a parsing module, which is used to convert the N actual response values ​​into base 1 when no abnormality occurs in the interaction process, to obtain a target response value corresponding to each actual response value, and the target response value is used to execute the target task.

[0025] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the determination module is further specifically used to: determine the matching degree of the interactive function between the target client and the target server based on the N actual response values ​​and the contract code, so as to verify the target server; when the matching degree is greater than or equal to the preset matching degree, determine whether an abnormality occurs in the interaction process based on the delay duration of the response content.

[0026] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the determination module is further specifically used to: determine a first matching degree based on the actual data type corresponding to each actual response value in the N actual response values ​​and the corresponding data type in the contract code, and the first matching degree is used to measure the matching degree of the target server in data type when responding to the request content; determine a second matching degree based on the response order corresponding to each actual response value in the N actual response values ​​and the corresponding arrangement order in the contract code, and the second matching degree is used to measure the matching degree of the response order when the target server responds to the N request fields; and perform weighted summation of the first matching degree and the second matching degree to obtain the matching degree.

[0027] In a third aspect, a vehicle is provided, comprising a memory and a processor. The memory is configured to store executable program code, and the processor is configured to retrieve and execute the executable program code from the memory, so that the vehicle executes the method of the first aspect or any possible implementation of the first aspect.

[0028] In a fourth aspect, a computer-readable storage medium is provided, which stores an executable program code. When the executable program code runs on a computer, the computer executes the method in the above-mentioned first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 This is a schematic diagram of a scenario of interaction between a client and a server provided in an embodiment of the present application;

[0030] Figure 2 This is a schematic flow chart of a method for generating code provided in an embodiment of the present application;

[0031] Figure 3 This is a schematic diagram of a code generation process provided by an embodiment of the present application;

[0032] Figure 4 This is a schematic diagram of another code generation process provided by an embodiment of the present application;

[0033] Figure 5 This is a schematic diagram of the structure of a device for generating code provided in an embodiment of the present application;

[0034] Figure 6 It is a structural schematic diagram of a vehicle provided in an embodiment of the present application. DETAILED DESCRIPTION

[0035] The following will clearly and thoroughly describe the technical solutions in this application in conjunction with the accompanying drawings. In the description of the embodiments of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of this application, "multiple" means two or more than two.

[0036] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to imply or suggest relative importance or implicitly indicate the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.

[0037] Figure 1 This is a schematic diagram of a scenario of interaction between a client and a server provided in an embodiment of the present application.

[0038] For example, Figure 1 As shown, Client 1, Client 2, and Client 3 can each request the service data they need from the server to perform specific tasks, where Client 1 is specifically the vehicle side, Client 2 is specifically the computer side, and Client 3 is specifically the mobile phone side. It should be understood that when different clients perform different tasks, the service data is different, and the request content is also different. Service data is structured data. When the client (Client 1 or Client 2 or Client 3) communicates structured data with the server, the client needs to follow the contract file and send data to the server according to the content defined in the contract file.

[0039] Contract files are typically written in a specific format. To facilitate client understanding and execution, they are typically converted into contract code to automate execution and improve efficiency. Related technologies generate contract code for each request field within the request content defined in the contract file. This results in a significant amount of duplicated code and, ultimately, a large amount of generated contract code.

[0040] In order to solve the above problems, this application proposes a method for generating codes. The specific implementation process of the method for generating codes can be found in Figure 2 .

[0041] Figure 2 This is a schematic flowchart of a method for generating code provided in an embodiment of the present application.

[0042] It should be understood that the method for generating a code provided in the embodiment of the present application can be applied to Figure 1Any client shown (eg, client 1, specifically any vehicle). Specifically, the method for generating code can also be applied to a vehicle controller in a vehicle.

[0043] For example, Figure 2 As shown, the method 200 includes:

[0044] In step 201, the target client obtains a contract file supported by the target client and the corresponding target server. The contract file is used to define the request content sent by the target client to the target server when executing the target task. The request content includes N request fields, which are request code lines after the request content is written in a specific format. N is a positive integer greater than 1.

[0045] It should be understood that there is a corresponding relationship between the “target client” and the “target server” in the above step 201 , which specifically refers to the target server being used to respond to the request of the target client.

[0046] It should also be understood that the "contract file supported by the target client and the corresponding target server" in step 201 above refers to the contract file complied with by both the target client and the target server. Specifically, the target client sends a data request (i.e., request content) to the target server in a request format, and the target server sends a data response (i.e., response content) to the target client in a response format. In addition, the specific request format and specific response format are related to the task performed by the target client.

[0047] It should also be understood that the "target task" in step 201 above refers to a specific function or specific operation that the target client needs to complete. In some embodiments, the target task is an e-commerce application in the target client updating the user's shopping cart information.

[0048] In some embodiments, the request content is defined using the Protobuff language.

[0049] It should be understood that Protobuff is a data description language used to define the writing format of the request content. The writing format mainly focuses on the layout rules of the request content.

[0050] It should also be understood that the "request content" in the above step 201 refers to the complete information package sent by the target client to the target server, which contains multiple request fields and related information. The related information includes the field name of the request field, the corresponding data type and the corresponding arrangement order, annotation information, the request type of this request and the target task to be executed. By parsing the multiple request fields, the target server can determine which data information the target client needs to request. The arrangement order corresponding to the request fields is used to define the construction order of the request fields when constructing the request content and the order in which the request fields are responded to. The data type corresponding to the request field refers to the data type of the field name in the request field.

[0051] For example, as in Example 1, the request content is as follows:

[0052]

[0053] optional string address=4; / / address

[0054] };

[0055] Among them, the request content is defined by the JAVA code language, the request package name java_package corresponding to the request content is com.lxl.servlet.pbmodel, message DemoRequest is used to indicate the request content, and "optional int64 id=1" can be regarded as a request field. It can be seen that: the request content includes 4 request fields, the first request field "optional int64 id=1" corresponds to the arrangement order of 1, the field name is id, and the data type corresponding to the first request field is int64; the second request field "optional string name=2" corresponds to the arrangement order of 2, the field name is name, and the data type corresponding to the second request field is string; the third request field "optional int32 age=3" corresponds to the arrangement order of 3, the field name is age, and the data type corresponding to the third request field is int32; the fourth request field "optional string address=4" corresponds to the arrangement order of 4, the field name is address, and the data type corresponding to the fourth request field is string.

[0056] In some embodiments, the target client in step 201 obtains the contract file supported by the target client and the corresponding target server, including: the target client compares the target task with multiple tasks in the contract sharing server, and determines a candidate task that matches the target task from the multiple tasks; the target client determines the candidate contract file corresponding to the candidate task as the contract file supported by the target client and the target server.

[0057] In step 202 , the target client classifies the N request fields based on the data types corresponding to the request fields, and determines M groups of request fields, where the data types corresponding to the request fields in each group of request fields are the same, and M is a positive integer greater than or equal to 1.

[0058] It should be understood that, under normal circumstances, the number N of request fields included in the request content in the contract document is relatively large, and among the data types corresponding to the N request fields, at least two request fields have the same data type. In special cases, the data types corresponding to each request field in the N request fields are the same. Therefore, the maximum value of M is N-1, and the minimum value of M is 1.

[0059] For example, in Example 2, the request content in Example 1 is used as an example to describe the process of determining M groups of request fields. The request content includes four request fields: a first request field "optional int64 id=1", a second request field "optional string name=2", a third request field "optional int32 age=3", and a fourth request field "optional string address=4". The data type corresponding to the first request field is int64, the data type corresponding to the second request field is string, the data type corresponding to the third request field is int32, and the data type corresponding to the fourth request field is string. After classifying the four request fields, the M groups of request fields are determined as follows: the first group of request fields is {first request field}, the second group of request fields is {second request field, fourth request field}, and the third group of request fields is {third request field}.

[0060] In one possible implementation, the method for determining the data type corresponding to each request field in step 202 includes: the target client determines the writing structure of the request content based on the target task and the request type corresponding to the request content; the target client extracts the data type corresponding to each request field from the request content based on the writing structure through a target extraction tool.

[0061] It should be understood that the "request type" in the above scheme refers to the type of request sent by the target client to the target server. The request type is used to define the type of operation that the target client wants the target server to perform. In some embodiments, the request type includes a command request type and a query request type. The command request type is used to request the target server to complete certain operations.

[0062] It should also be understood that the "written structure" in the above solution mainly focuses on the logical order of the request content. It differs from the written format in that the written structure focuses on the internal logic, while the written format focuses on the external.

[0063] It should also be understood that the "target extraction tool" in the above solution refers to a tool that can automatically extract code segments of a specific format from a contract file (request content), and can identify and extract content based on regular expressions. In some embodiments, the target extraction tool is a Code Search tool or a QueryInst tool.

[0064] In the above technical solution, the written structure of the request content corresponding to different request tasks and different request types is different. Therefore, this method accurately determines the written structure of the request content by combining the target task and the request type corresponding to the request content. In this way, the distribution of the multiple request fields specifically included in the request content can be clearly determined. On this basis, the method can use the target extraction tool to accurately extract the data type corresponding to each request field from the request content, thereby facilitating the subsequent generation of accurate general contract code blocks.

[0065] In step 203, the target client uses any group of request fields as the target group request field and generates a universal contract code block corresponding to the target group request field. The target group request field corresponds to a universal contract code block, which is used to indicate the commonality of the request fields in the target group request field.

[0066] It should be understood that, in order to more clearly understand the process of generating the general contract code block and attribute code block in this application, the above step 203 is described using any group of request fields (target group request field) as an example. The process of determining the general contract code block and attribute code block corresponding to other group request fields is similar to that of determining the general contract code block and attribute code block corresponding to the target group request field, and will not be repeated here.

[0067] It should also be understood that the "common contract code block for indicating the commonality of request fields in the target group request fields" in step 203 above refers to a contract code block generated based on the common content of multiple request fields in the target group request fields. Furthermore, the "commonality of request fields" in step 203 above is reflected in the data types corresponding to the request fields.

[0068] In one possible implementation, the target client in step 203 generates a general contract code block corresponding to the target group request field, including: the target client generates an annotation code line corresponding to the target group request field based on the data type corresponding to the target group request field; the target client generates a content code line corresponding to the target group request field based on the data type, target keyword and target code content corresponding to the target group request field, the target keyword is used to indicate the request level corresponding to each request field in the target group request field, and the target code content corresponds to the code content in the attribute code block; the target client combines the annotation code line and the content code line to generate a general contract code block corresponding to the target group request field.

[0069] It should be understood that the "annotated code lines" in the above scheme are used to better understand the content code lines, understand the data types corresponding to the request fields in the content code lines, and understand the request fields of which data types the general contract code blocks apply.

[0070] It should also be understood that the "target keyword" in the above solution is specifically used to indicate the request level of the field name of each request field in the target group request field. In some embodiments, the target keyword is public.

[0071] It should also be understood that the “target code content corresponds to the code content in the attribute code block” in the above solution is to schematically indicate that the target code content may be the code content, without performing a real replacement operation.

[0072] In the above technical solution, for each request field in any group of request fields, the generation process of the corresponding contract code is similar. Therefore, the above method takes any group of request fields (target group request fields) in the M groups of request fields as an example to describe the generation process of the universal contract code corresponding to the target group request field. In this method, based on the data type corresponding to the target group request field, the annotation code line corresponding to the target group request field is generated, and based on the data type, target keyword and target code content corresponding to the target group request field, the content code line corresponding to the target group request field is generated. Further, the annotation code line and the content code line are combined to generate a universal contract code block corresponding to the target group request field. This makes it possible to understand which data types of request fields the universal contract code block is applicable to based on the annotation code line, and which positions of the code in the universal contract code block correspond to the attribute code block, that is, it is related to the code in the attribute code block used to indicate the difference of the request field.

[0073] For example, in Example 3, the second group of request fields in Example 2 is {second request field, fourth request field} as an example to describe the process of determining the general contract code block corresponding to the second group of request fields. The general contract code block is as follows:

[0074] public class GenericClass{

[0075] @ProtoAnno(type=ProtoAnno.Label.STRING, isArray=false)

[0076] public string code content 1;

[0077] };

[0078] Among them, "@ProtoAnno(tag=2, type=ProtoAnno.Label.STRING, isArray=false)" is the annotation code line in the general contract code block, and "public string name" is the content code line in the general contract code block. Among them, "type=ProtoAnno.Label.STRING" is used to explain that the data type corresponding to the second set of request fields is string, "isArray=false" is used to indicate that the field name of the request field in the second set of request fields is not an array, "string" is the data type corresponding to the second set of request fields, "public" is the target keyword, and "Code Content 1" is an example of target code content.

[0079] Step 204 : The target client generates an attribute code block corresponding to the general contract code block of the target group request field. The target group request field corresponds to an attribute code block, and the attribute code block is used to indicate the difference of the request field in the target group request field.

[0080] It should be understood that in the above step 204, the same set of request fields corresponds to a common code block and an attribute code block, that is, one common code block corresponds to one attribute code block. The attribute code block includes code content corresponding to the target code content.

[0081] It should also be understood that the “difference in request fields” in the above step 204 is reflected in the field names of the request fields and the corresponding request order.

[0082] In one possible implementation, the attribute information of each request field includes the field name and the corresponding request order, and the attribute code block of the general contract code block corresponding to the target group request field is generated, including: based on the request order corresponding to each request field in the target group request field, through the field name of each request field, the attribute code block of the general contract code block corresponding to the target group request field is generated.

[0083] It should be understood that the “request order corresponding to the request fields” in the above solution refers to the order in which the request fields are arranged in multiple request fields when the target client sends multiple request fields to the target server.

[0084] It should also be understood that the above scheme "based on the request order corresponding to each request field in the target group request field, through the field name of each request field, generates the attribute code block of the general contract code block corresponding to the target group request field" means that the arrangement order of multiple field names in the attribute code block is consistent with the request order of the corresponding request fields. That is to say, for the second request field and the fourth request field included in the second group of request fields, the request order corresponding to the second request field is 2, the request order corresponding to the fourth request field is 4, the arrangement order of the field name name in the attribute code block is 1, and the arrangement order of the field name address is 2, the field name name is the field name of the second request field, and the field name address is the field name of the fourth request field, wherein the arrangement order of the field name name in the attribute code block is before the field name address, and the request order corresponding to the second request field is before the fourth request field.

[0085] In the above technical solution, for the target group request field, based on the request order corresponding to each request field in the target group request field, the attribute code block of the general contract code block corresponding to the target group request field is generated through the field name of each request field. In this way, the attribute code block includes code content corresponding to the target code content, and the code content can be at least one field name. Of course, in this method, the specific target code content is only schematically represented by the code content in the attribute code block, and no real replacement operation is performed. In this way, not only can the differences of the request fields in the target group request field be characterized, but also unnecessary code volume can be avoided after the code is substituted.

[0086] For example, as in Example 4, taking the second group of request fields in Example 2 as {second request field, fourth request field} as an example, the process of determining the attribute code block of the general contract code block corresponding to the second group of request fields is described.

[0087] The property code block 1 is as follows:

[0088] public class Attribute{

[0089] column-name name=2;

[0090] column-name address=4;

[0091] };

[0092] Among them, "column-name" is the name of the field. The "name" in "name=2" is the code in the attribute code block used to indicate the difference of the request field, specifically the field name name, and "2" is the arrangement order of the corresponding second request field in the N request fields. The "address" in "address=4" is the code in the attribute code block used to indicate the difference of the request field, specifically the field name address, and "4" is the arrangement order of the corresponding fourth request field in the N request fields. In addition, "name" and "address" correspond to the target code content in the aforementioned scheme.

[0093] Property code block 2 is as follows:

[0094] public class Attribute{

[0095] column-name name(2), address(4);

[0096]

[0097] In "name(2)", "name" is a code in the attribute code block used to indicate the difference of the request field, specifically the field name, and "2" is the arrangement order of the corresponding second request field in the N request fields. In "address(4)", "address" is a code in the attribute code block used to indicate the difference of the request field, specifically the field name, and "4" is the arrangement order of the corresponding fourth request field in the N request fields.

[0098] In step 205, the target client combines the general contract code blocks and attribute code blocks corresponding to each group of request fields in the M groups of request fields to obtain the contract code of the contract file. The contract code is the programming language code obtained by converting the request content written in a specific format in the contract file.

[0099] In some embodiments, the specific format is a JAVA language format.

[0100] For example, as in Example 5, the process of determining the contract code of the contract document is described by taking the multiple request fields included in the request content in Example 1 as an example.

[0101]

[0102]

[0103] In one possible implementation, the contract file is also used to define the response format expected by the target client, and the contract code is used by the target client to parse the received response content. The method also includes: the target client uses a target extraction tool to extract the actual response value corresponding to each request field in the N request fields from the response content based on the response format to obtain N actual response values; the target client determines whether an abnormality occurs in the interaction process between the target client and the target server based on the N actual response values ​​and the contract code; if no abnormality occurs in the interaction process, the target client converts the N actual response values ​​into base 1 to obtain a target response value corresponding to each actual response value, and the target response value is used to execute the target task.

[0104] It should be understood that when the target server supports the contract file and the contract file is also used to define the response format expected by the target client, the target server should respond to the request content according to the response format, that is, respond to the request field in the response content according to the response format.

[0105] It should also be understood that the "actual response values" in the above scheme are multiple values ​​extracted directly from the response content, and these multiple values ​​are the original transmission values. In some embodiments, the multiple actual response values ​​are binary values. The contract code defines the field name, corresponding arrangement order and corresponding data type of each request field, and also implicitly defines the field name, corresponding arrangement order and corresponding data type of the response value expected by the target client. In some embodiments, the field name, corresponding arrangement order and corresponding data type of the request field defined in the contract code are respectively the same as the field name, corresponding arrangement order and corresponding data type of the response value expected by the target client. Therefore, the method can determine whether an abnormality occurs in the interaction process between the target client and the target server based on the N actual response values ​​and the contract code (equivalent to based on the N actual response values ​​and the expected response values). In some embodiments, when an abnormality occurs in the interaction process, the data type of the actual response value is different from the corresponding data type in the contract code.

[0106] It should also be understood that anomalies in the interaction process between the target client and the target server include the target server failing to respond to the request content according to the contract code and response timeout.

[0107] In the above technical solution, the target server responds to the request content in a fixed format. Therefore, in this method, the target extraction tool can extract the actual response value (N actual response values) corresponding to each of the N request fields from the response content based on the response format. Furthermore, based on the N actual response values ​​and the data contract (contract code) to be complied with, the method determines whether an abnormality has occurred in the interaction process between the target client and the target server. This can determine whether the interaction process may be under attack. If the interaction process is not abnormal, the method converts the N actual response values ​​into a base and further executes the target task. In other words, the method verifies the actual response values ​​and only executes the target task using the N actual response values ​​when the status of the interaction process indirectly reflects that the N actual response values ​​are correct. This method can avoid the target client processing the abnormal actual response values ​​when the interaction process is abnormal, thereby causing abnormal phenomena on the target client, which include at least one of system crash, data resource leakage, attack, data corruption, and consumption of additional computing resources in the target client.

[0108] In one possible implementation, the target client determines whether an abnormality occurs in the interaction process between the target client and the target server based on the N actual response values ​​and the contract code, including: the target client determines the matching degree of the interaction function between the target client and the target server based on the N actual response values ​​and the contract code to verify the target server; when the matching degree is greater than or equal to the preset matching degree, the target client determines whether an abnormality occurs in the interaction process based on the delay duration of the response content.

[0109] It should be understood that the phrase "determining the degree of matching of the interactive functions between the target client and the target server based on the N actual response values ​​and the contract code" in the above scheme refers to determining, through the N actual response values ​​and the contract code, the degree of cooperation of the target server in responding to the request content after the target client sends the request content to the target server. The response here refers to the response to the content. When the degree of matching does not take into account the delay in responding to the request content, the above scheme needs to further determine whether an abnormality has occurred in the interactive process based on the delay in the response content.

[0110] In the above technical solution, if the matching degree of the interactive function between the target client and the target server is higher, it indicates that the target server is more capable of responding to the request content in accordance with the data contract. Therefore, the method determines the matching degree based on the N actual response values ​​and the contract code. When the matching degree is large, it indicates that the target server has complied with the data contract, but the target server may not respond to the request content in time, and the interaction process is abnormal. Therefore, when the matching degree is greater than or equal to the preset matching degree, it is also necessary to judge the delay duration of the response content. The above process can avoid the situation where the target server responds to the request content with a timeout, but complies with the data contract. Therefore, the method can accurately determine whether the interaction process between the target client and the target server is abnormal through the above two stages.

[0111] In some embodiments, after the target client determines the matching degree of the interactive functions between the target client and the target server, the method 200 further includes: if the matching degree is less than a preset matching degree, the target client does not execute the target task.

[0112] In one possible implementation, the target client determines the degree of matching of the interactive function between the target client and the target server based on the N actual response values ​​and the contract code, including: the target client determines a first degree of matching based on the actual data type corresponding to each actual response value in the N actual response values ​​and the corresponding data type in the contract code, and the first degree of matching is used to measure the degree of matching of the target server in data type when responding to the request content; the target client determines a second degree of matching based on the response order corresponding to each actual response value in the N actual response values ​​and the corresponding arrangement order in the contract code, and the second degree of matching is used to measure the degree of matching of the target server in response to the N request fields; the target client performs weighted summation of the first degree of matching and the second degree of matching to obtain the degree of matching.

[0113] It should be understood that the phrase "taking a weighted sum of the first and second matching degrees to obtain the matching degree" in the above solution specifically refers to multiplying the first matching degree by a first coefficient to obtain a first value, multiplying the second matching degree by a second coefficient to obtain a second value, and determining the matching degree as the sum of the first and second values. In some embodiments, the first coefficient is used to measure the contribution of the data type when determining the matching degree, and the second coefficient is used to measure the contribution of the arrangement order when determining the matching degree.

[0114] In the above technical solution, the target client sends a request content to the target server, and the target server sends a response content to the target client, so as to realize the interactive function between the target client and the target server. The response content is the response result (N actual response values) to the N request fields in the request content, and each request field has a corresponding arrangement order and data type. Therefore, it is necessary to comprehensively determine the matching degree based on the two attributes of arrangement order and data type. Specifically, based on the actual data type corresponding to each actual response value in the N actual response values ​​and the corresponding data type in the data contract (contract code), the first matching degree is determined; based on the response order corresponding to each actual response value in the N actual response values ​​and the corresponding arrangement order in the contract code, the second matching degree is determined, and the first matching degree and the second matching degree are weighted and summed to determine the matching degree. This method can avoid the low accuracy when determining the matching degree based on a single attribute.

[0115] In some embodiments, the target client determines a first degree of matching based on the actual data type corresponding to each of the N actual response values ​​and the corresponding data type in the contract code, including: the target client obtains a first quantity of request fields; the target client determines a second quantity of actual data types corresponding to the N actual response values ​​that are the same as the corresponding data type in the contract code; the target client determines the ratio between the second quantity and the first quantity as the first degree of matching.

[0116] In some embodiments, the target client determines a second degree of matching based on the response order corresponding to each actual response value in the N actual response values ​​and the corresponding arrangement order in the contract code, including: the target client determines a third number of matches between the response order corresponding to the N actual response values ​​and the corresponding arrangement order in the contract code; the target client determines the ratio between the third number and the first number as the second degree of matching.

[0117] In one possible implementation, each actual response value is a binary value, and the target client performs base conversion on the N actual response values ​​to obtain a target response value corresponding to each actual response value, including: for any actual response value among the N actual response values, the target client divides the actual response value according to a preset number of bits to obtain P groups of binary values, where P is a positive integer greater than 1; the target client deletes the highest bit value in each group of binary values ​​in the P groups of binary values ​​to obtain a processed binary value; the target client determines the target base type based on the corresponding data type in the contract code; the target client performs base conversion on the processed binary value according to the target base type to obtain a target response value corresponding to the actual response value.

[0118] It should be understood that the principle of performing base conversion on each of the N actual response values ​​is the same. Therefore, the above scheme exemplarily uses any one of the N actual response values ​​as an example to describe the process of performing base conversion on the actual response value to obtain the corresponding target response value. Typically, the preset number of bits is 8, and the highest bit is the sign bit. The processed binary value can be converted to the base type according to the target base type using the bit weight expansion method to obtain the target response value corresponding to the actual response value.

[0119] In the above technical solution, each actual response value is a binary value, and the principle of converting each actual response value into the same base value is the same. Therefore, the method takes any actual response value among the N actual response values ​​as an example to describe the process of performing base conversion on the N actual response values. Specifically, the method divides the actual response value according to the preset number of bits to obtain P groups of binary values; the highest bit value in each group of binary values ​​in the P groups of binary values ​​is deleted to obtain a processed binary value. This is to delete the influence of the sign bit in the base conversion process, and to more simply represent the actual response value. The base number system to which the actual response value is to be converted is related to the corresponding data type in the contract code. Based on the data type, the method can accurately determine the target base type of the actual response value, and then after performing base conversion on the processed binary value, an accurate target response value can be obtained. Furthermore, the target client can perform the target task based on the target response value.

[0120] In some embodiments, when the data type is int64, the target base type is a decimal type.

[0121] For example, the actual response value is 1000000100000001, and its corresponding data type is int64. The target client divides the actual response value into 8 bits to obtain two sets of binary values. 1000000100000001 ; The target client deletes the highest digit value in each group of binary values ​​and obtains 00000010000001 The target client determines that the target base type is decimal based on the data type (int64); the target client converts 00000010000001 into a decimal number based on the following formula (1), that is, the target response value is 129;

[0122] 2 7 +2 0 =129 (1)

[0123] Among them, 7 represents the bit weight power corresponding to the first "1" in 00000010000001, and 0 represents the bit weight power of the second "1" in 00000010000001.

[0124] In some embodiments, the target server obtains a contract file supported by the target client and the corresponding target server, and the contract file is used to define the request content sent by the target client to the target server when performing the target task; the target server determines the field name, corresponding initial value, corresponding arrangement order and corresponding data type of each request field in the request content based on the request content; the target server generates a corresponding first contract code based on the field name, corresponding initial value, corresponding arrangement order and corresponding data type of each request field and stores it in the target server, and the first contract code is used by the target server to respond to the received request content during the actual interaction process, and the first contract code is a programming language code obtained by converting the request content written in a specific format in the contract file.

[0125] In the above technical solution, the target server adopts the traditional solution to generate the first contract code to respond to the received request content during the actual interaction process. The first contract code is generated based on the field name of each request field, the corresponding initial value, the corresponding arrangement order and the corresponding data type. When responding to the request content, the initial value has extremely little reference significance for the target server to respond to the request content. The target server can respond to the request content based on the data type. However, the method 200 combines the general contract code block and the attribute code block corresponding to each group of request fields in the M groups of request fields to obtain the contract code of the contract file. Therefore, compared with method 200, the first contract code generated by the traditional solution has a larger code volume, and the contract code in the method 200 has a smaller code volume, and the storage space it occupies is smaller.

[0126] Figure 3 This is a schematic diagram of a code generation process provided in an embodiment of the present application.

[0127] For example, Figure 3As shown, the target server obtains a contract file supported by the target client and the corresponding target server, and the contract file is used to define the request content sent by the target client to the target server when executing the target task; the target server determines the field name, corresponding initial value, corresponding arrangement order, and corresponding data type of each request field in the request content based on the request content; the target server generates a corresponding first contract code (i.e., through a traditional solution) based on the field name, corresponding initial value, corresponding arrangement order, and corresponding data type of each request field and stores it in the target server; the target client obtains a contract file supported by the target client and the corresponding target server, and the contract file is used to define the request content sent by the target client to the target server when executing the target task; the target client generates a contract code corresponding to the contract file based on steps 202 to 205 and stores it in the target client. Finally, the target client and the target server perform a structured data interaction process based on the first contract code and the contract code, respectively.

[0128] It should be understood that the target server can also obtain the contract file supported by the target client and the corresponding target server, and the contract file is used to define the request content sent by the target client to the target server when performing the target task; the target server generates a second contract code based on steps 202 to 205 and stores it in the target server, and the second contract code is used by the target server to respond to the received request content during the actual interaction process.

[0129] Figure 4 This is a schematic diagram of another code generation process provided in an embodiment of the present application.

[0130] For example, Figure 4 As shown, the target server obtains the contract file supported by the target client and the corresponding target server, and the contract file is used to define the request content sent by the target client to the target server when performing the target task; the target server generates a second contract code corresponding to the contract file based on steps 202 to 205 and stores it in the target server; the target client obtains the contract file supported by the target client and the corresponding target server, and the contract file is used to define the request content sent by the target client to the target server when performing the target task; the target client generates a contract code corresponding to the contract file based on steps 202 to 205 and stores it in the target client. Finally, the target client and the target server perform a structured data interaction process based on the second contract code and the contract code, respectively. It should be understood that the second contract code is the same as the contract code.

[0131] It should be understood that the contract file in this application also includes the expected response content (including the data types corresponding to the request fields of the response, the response order, etc.) after the target client sends the request content to the target server when executing the target task. In this way, the target client can directly verify the actual response content based on the expected response content. In addition, the process of generating contract code based on the expected response content in the contract file is similar to the process of generating contract code based on the request content in the contract file, and will not be repeated here.

[0132] Figure 5 Schematic diagram of a device for generating code according to an embodiment of the present invention.

[0133] For example, Figure 5 As shown, the device 500 includes:

[0134] Acquisition module 501: used to obtain a contract file supported by a target client and a corresponding target server. The contract file is used to define the request content sent by the target client to the target server when executing a target task. The request content includes N request fields, which are request code lines with the request content written in a specific format. N is a positive integer greater than 1.

[0135] Determining module 502, configured to classify the N request fields based on the data types corresponding to the respective request fields, and determine M groups of request fields, wherein the data types corresponding to the respective request fields in each group of request fields are the same, and M is a positive integer greater than or equal to 1;

[0136] The generating module 503 is used to:

[0137] Taking any group of request fields as the target group request field, generating a universal contract code block corresponding to the target group request field, wherein the target group request field corresponds to a universal contract code block, and the universal contract code block is used to indicate the commonality of the request fields in the target group request field; generating an attribute code block corresponding to the universal contract code block of the target group request field, wherein the target group request field corresponds to an attribute code block, and the attribute code block is used to indicate the difference of the request fields in the target group request field;

[0138] The combination module 504 is used to combine the general contract code blocks and attribute code blocks corresponding to each group of request fields in the M groups of request fields to obtain the contract code of the contract file. The contract code is the programming language code obtained by converting the request content written in a specific format in the contract file.

[0139] Optionally, the determination module 502 is specifically used to determine the writing structure of the request content based on the target task and the request type corresponding to the request content; the device 500 also includes: an extraction module, used to extract the data type corresponding to each request field from the request content based on the writing structure through a target extraction tool.

[0140] Optionally, the generation module 503 is specifically used to: generate an annotation code line corresponding to the target group request field based on the data type corresponding to the target group request field; generate a content code line corresponding to the target group request field based on the data type, target keyword and target code content corresponding to the target group request field, the target keyword is used to indicate the request level corresponding to each request field in the target group request field, and the target code content corresponds to the code content in the attribute code block; combine the annotation code line and the content code line to generate a general contract code block corresponding to the target group request field.

[0141] Optionally, the generation module 503 is further configured to generate an attribute code block of a general contract code block corresponding to the target group request field based on the request order corresponding to each request field in the target group request field and using the field name of each request field.

[0142] Optionally, the contract file is also used to define the response format expected by the target client, and the contract code is used by the target client to parse the received response content. The extraction module is specifically used to extract the actual response value corresponding to each request field in the N request fields from the response content based on the response format through a target extraction tool to obtain N actual response values; the determination module 502 is specifically further used to determine whether an abnormality occurs in the interaction process between the target client and the target server based on the N actual response values ​​and the contract code; the device 500 also includes: a parsing module, which is used to convert the N actual response values ​​into base 1 when no abnormality occurs in the interaction process to obtain a target response value corresponding to each actual response value, and the target response value is used to execute the target task.

[0143] Optionally, the determination module 502 is further specifically used to: determine the matching degree of the interactive function between the target client and the target server based on the N actual response values ​​and the contract code, so as to verify the target server; when the matching degree is greater than or equal to the preset matching degree, determine whether an abnormality occurs in the interaction process based on the delay duration of the response content.

[0144] Optionally, the determination module 502 is further specifically used to: determine a first matching degree based on the actual data type corresponding to each actual response value in the N actual response values ​​and the corresponding data type in the contract code, and the first matching degree is used to measure the matching degree of the target server in data type when responding to the request content; determine a second matching degree based on the response order corresponding to each actual response value in the N actual response values ​​and the corresponding arrangement order in the contract code, and the second matching degree is used to measure the matching degree of the response order when the target server responds to the N request fields; and perform weighted summation of the first matching degree and the second matching degree to obtain the matching degree.

[0145] Figure 6 It is a structural schematic diagram of a vehicle provided in an embodiment of the present application.

[0146] For example, Figure 6 As shown, the vehicle 600 includes: a memory 601 and a processor 602, wherein the memory 601 stores an executable program code 603, and the processor 602 is used to call and execute the executable program code 603 to perform a method for generating code.

[0147] In addition, an embodiment of the present application also protects a device, which may include a memory and a processor, wherein the memory stores executable program code, and the processor is used to call and execute the executable program code to perform a method for generating code provided in an embodiment of the present application.

[0148] In this embodiment, the device can be divided into functional modules based on the above-described method examples. For example, each functional module can be mapped to a specific functional module, or two or more functions can be integrated into a single processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and represents only a logical functional division. In actual implementation, other division methods may be used.

[0149] In the case of dividing the functional modules into corresponding modules, the device may further include an acquisition module, a determination module, a generation module, an extraction module, and a parsing module. It should be noted that all relevant contents involved in the above method embodiments can be referred to the functional description of the corresponding functional modules and will not be repeated here.

[0150] It should be understood that the device provided in this embodiment is used to execute the above-mentioned method for generating code, and thus can achieve the same effect as the above-mentioned implementation method.

[0151] In the case of an integrated unit, the device may include a processing module and a storage module. When the device is used in a vehicle, the processing module may be used to control and manage the vehicle's movements. The storage module may be used to support the vehicle's execution of relevant executable program code, etc.

[0152] The processing module may be a processor or controller that implements or executes the various exemplary logic blocks, modules, and circuits described in conjunction with the present disclosure. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a digital signal processing (DSP) and a microprocessor, and the storage module may be a memory.

[0153] In addition, the device provided in the embodiments of the present application can specifically be a chip, component or module, and the chip may include a connected processor and memory; wherein the memory is used to store instructions, and when the processor calls and executes the instructions, the chip can execute a method for generating code provided in the above embodiment.

[0154] This embodiment also provides a computer-readable storage medium, which stores executable program code. When the executable program code runs on a computer, the computer executes the above-mentioned related method steps to implement a method for generating code provided in the above embodiment.

[0155] This embodiment further provides a computer program product. When the computer program product is run on a computer, the computer is caused to execute the above-mentioned related steps to implement a method for generating code provided in the above embodiment.

[0156] Among them, the device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0157] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0158] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, 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 through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0159] The above content is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A method for generating a code, characterized in that: The method comprises: Obtain a contract file supported by the target client and the corresponding target server. The contract file is used to define the request content sent by the target client to the target server when executing the target task. The request content includes N request fields, each of which is a request code line with the request content written in a specific format. N is a positive integer greater than 1. Classify the N request fields based on the data type corresponding to each request field to determine M groups of request fields, where each request field in each group of request fields has the same data type, and M is a positive integer greater than or equal to 1; Taking any group of request fields as a target group request field, generating a universal contract code block corresponding to the target group request field, wherein the target group request field corresponds to one universal contract code block, and the universal contract code block is used to indicate the commonality of the request fields in the target group request field; Generating an attribute code block of the general contract code block corresponding to the target group request field, wherein the target group request field corresponds to one attribute code block, and the attribute code block is used to indicate the difference of the request field in the target group request field; The general contract code blocks and attribute code blocks corresponding to each group of request fields in the M groups of request fields are combined to obtain the contract code of the contract file. The contract code is the programming language code obtained by converting the request content written in a specific format in the contract file.

2. The method according to claim 1, characterized in that The method for determining the data type corresponding to each request field includes: Determining a writing structure of the request content based on the target task and the request type corresponding to the request content; The target extraction tool extracts the data types corresponding to the various request fields from the request content based on the written structure.

3. The method according to claim 1, characterized in that The generating of the general contract code block corresponding to the target group request field includes: Based on the data type corresponding to the target group request field, generating an annotation code line corresponding to the target group request field; generating a content code line corresponding to the target group request field based on a data type, a target keyword, and a target code content corresponding to the target group request field, wherein the target keyword is used to indicate a request level corresponding to each request field in the target group request field, and the target code content corresponds to the code content in the attribute code block; The annotation code line and the content code line are combined to generate a general contract code block corresponding to the target group request field.

4. The method according to claim 3, characterized in that The attribute information of each request field includes a field name and a corresponding request order. The attribute code block for generating the general contract code block corresponding to the target group request field includes: Based on the request order corresponding to each request field in the target group request field, an attribute code block of the general contract code block corresponding to the target group request field is generated using the field name of each request field.

5. The method according to claim 1, wherein The contract file is further used to define the response format expected by the target client, and the contract code is used by the target client to parse the received response content. The method further includes: extracting, by a target extraction tool, actual response values ​​corresponding to each of the N request fields from the response content based on the response format, to obtain N actual response values; Determining whether an abnormality occurs in an interaction process between the target client and the target server based on the N actual response values ​​and the contract code; When no abnormality occurs during the interaction process, the N actual response values ​​are converted into bases to obtain target response values ​​corresponding to the respective actual response values, and the target response values ​​are used to execute the target task.

6. The method according to claim 5, characterized in that The determining, based on the N actual response values ​​and the contract code, whether an abnormality occurs in the interaction process between the target client and the target server, includes: Determining a matching degree of interaction functions between the target client and the target server based on the N actual response values ​​and the contract code, so as to verify the target server; When the matching degree is greater than or equal to a preset matching degree, it is determined whether an abnormality occurs in the interaction process based on the delay duration of the response content.

7. The method according to claim 6, characterized in that The determining, based on the N actual response values ​​and the contract code, a matching degree of the interactive functions between the target client and the target server includes: Determining a first matching degree based on an actual data type corresponding to each actual response value in the N actual response values ​​and a corresponding data type in the contract code, wherein the first matching degree is used to measure a matching degree of the data type when the target server responds to the request content; Determining a second matching degree based on a response order corresponding to each of the N actual response values ​​and a corresponding arrangement order in the contract code, the second matching degree being used to measure a matching degree in a response order when the target server responds to the N request fields; The first matching degree and the second matching degree are weightedly summed to obtain the matching degree.

8. A device for generating a code, characterized in that: The device comprises: an acquisition module, configured to acquire a contract file supported by a target client and a corresponding target server, wherein the contract file is used to define the request content sent by the target client to the target server when executing a target task, wherein the request content includes N request fields, each of which is a request code line containing the request content in a specific format, where N is a positive integer greater than 1; a determination module, configured to classify the N request fields based on the data types corresponding to the respective request fields, and determine M groups of request fields, wherein the data types corresponding to the respective request fields in each group of request fields are the same, and M is a positive integer greater than or equal to 1; Generate modules for: Taking any group of request fields as a target group request field, generating a universal contract code block corresponding to the target group request field, wherein the target group request field corresponds to one universal contract code block, and the universal contract code block is used to indicate the commonality of the request fields in the target group request field; Generating an attribute code block of the general contract code block corresponding to the target group request field, wherein the target group request field corresponds to one attribute code block, and the attribute code block is used to indicate the difference of the request field in the target group request field; A combination module is used to combine the general contract code blocks and attribute code blocks corresponding to each group of request fields in the M groups of request fields to obtain the contract code of the contract file. The contract code is a programming language code obtained by converting the request content written in a specific format in the contract file.

9. A vehicle, characterized in that: The vehicle comprises: a memory for storing executable program code; A processor is configured to call and run the executable program code from the memory, so that the vehicle executes the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores an executable program code, and when the executable program code is executed, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Data forgery method, apparatus, and computer storage medium

    CN109086145A

  • Form page implementation method and device based on parameter configuration

    CN115328457A