Code generation method and device, vehicle and storage medium
By classifying the data type of the requested fields in the contract file, and generating general contract code blocks and attribute code blocks, the problem of excessive amount of contract code generated in the prior art is solved, and the code volume is reduced and the accuracy is improved.
Patent Information
- Application Number
- CN202411763453.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2044-12-03
AI Technical Summary
When generating contract codes, the prior art will generate more duplicate codes, resulting in a large amount of generated contract codes.
By obtaining the contract files supported by the target client and server, the classification request field generates common contract code blocks and attribute code blocks according to the data type, and combines the contract code to avoid the generation of duplicate codes.
The generated contract code amount is reduced and the accuracy is improved, avoiding code redundancy and improving execution efficiency.
Smart Images

Figure CN119806496A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of vehicles, and more specifically, to a method, device, vehicle and storage medium for generating codes in the field of vehicles. Background Art
[0002] With the rapid development of information networks, multiple communication parties can communicate data through service calls. The party that initiates the call is called the service caller, and the party called is called the service provider. The service caller can be the client, and the service provider can be the server. When the client performs a task and needs to communicate 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.
[0003] A contract file is usually a file written in a specific format. In order to facilitate the client to understand and execute the contract file, the contract file is usually converted into contract code to achieve automatic execution and improve execution efficiency. In the related art, contract code is generated for each request field in the request content defined in the contract file, which will generate a lot of duplicate code, and ultimately lead to the generation of contract code with a large amount of code.
[0004] Therefore, a method for generating codes is urgently needed to reduce the amount of contract codes. Summary of the invention
[0005] The present application provides a method, device, vehicle and storage medium for generating codes, wherein the method can generate a small amount of accurate contract codes.
[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, and N being 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, the data type corresponding to each request field in each group of request fields being the same, and M being a positive integer greater than or equal to 1; taking any group of request fields as the target group request fields, Generate a general contract code block corresponding to the target group request field, the target group request field corresponds to a general contract code block, the general 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 general 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 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 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 blocks corresponding to each group of request fields can be determined. In other words, the common content in 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 codes. Furthermore, on the basis of the general contract code blocks corresponding to each group of request fields, attribute code blocks of the general contract code blocks corresponding to each group of request fields are generated, which retains the differences of the request fields in each group of request fields. Finally, the method 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. Therefore, the method can generate contract codes with small code volume and accuracy.
[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 request type corresponding to the target task and 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 writing structure of the request content corresponding to different request tasks and different request types is different. Therefore, the method combines the target task and the request type corresponding to the request content to accurately determine the writing structure of the request content. In this way, the distribution of multiple request fields specifically included in the request content can be clearly determined. On this basis, the method can accurately extract the data type corresponding to each request field from the request content with the help of the target extraction tool, so as to facilitate 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 group 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 a field name and a corresponding request order, and an attribute code block of a 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, and through the field name of each request field, an attribute code block of a 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 in 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 the method, the actual response value (N actual response values) corresponding to each request field in the N request fields can be extracted from the response content based on the response format by the target extraction tool. Further, in the method, based on the N actual response values and the data contract (contract code) to be followed, it is determined whether the interaction process between the target client and the target server is abnormal. This can determine that the interaction process may be attacked. When the interaction process is not abnormal, the method performs a base conversion on the N actual response values and further executes the target task. In other words, the method verifies the actual response value, and only executes the target task through the N actual response values when the state of the interaction process is used to reflect that the N actual response values are correct. The method can avoid the abnormal interaction process, and the target client also processes the abnormal actual response value, thereby causing an abnormal phenomenon to occur in the target client, and the abnormal phenomenon includes 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 interactive functions 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 within the time limit 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, based on the N actual response values and the contract code, the matching degree of the interactive function between the target client and the target server is determined, including: 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, a first matching degree is determined, 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; 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, a second matching degree is determined, 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; the first matching degree and the second matching degree are weightedly summed to obtain the matching degree.
[0019] In the above technical solution, the target client sends the request content to the target server, and the target server sends the response content to the target client to realize the interactive function between the target client and the target server. The response content is the response result (N actual response values) of 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, the device comprising: an acquisition module, used to acquire 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, N being a positive integer greater than 1; a determination module, used to classify the N request fields based on the data type corresponding to each request field, and determine 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, used to: use any group of request fields as a target A target group request field is generated, 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, which is the programming language code obtained by 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, which is 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 methods, in some possible implementation methods, the generation module is specifically used to generate an 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, the contract code is used by the target client to parse the received response content, and 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 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, and 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 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 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 data type when the target server responds 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; 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 used to store executable program code, and the processor is used to call and run the executable program code from the memory, so that the vehicle executes the method in 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 is a schematic flow chart of a method for generating code provided in an embodiment of the present application;
[0031] Figure 3 is a schematic diagram of a process of generating code provided by an embodiment of the present application;
[0032] Figure 4 is a schematic diagram of another process of generating code provided by an embodiment of the present application;
[0033] Figure 5 It is a structural schematic diagram 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 technical solution in the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present 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 the present application, "multiple" means two or more than two.
[0036] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0037] Figure 1 It 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 respectively request the service data they need from the server to perform specific tasks, wherein client 1 is specifically the vehicle terminal, client 2 is specifically the computer terminal, and client 3 is specifically the mobile terminal. It should be understood that when different clients perform different tasks, the service data is different, and the request content is also different. The 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] A contract file is usually a file written in a specific format. In order to facilitate the client to understand and execute the contract file, the contract file is usually converted into contract code to achieve automatic execution and improve execution efficiency. In the related art, contract code is generated for each request field in the request content defined in the contract file, which will generate a lot of duplicate code, and ultimately lead to the generation of contract code with a large amount of 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 It 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 codes can also be applied to a vehicle controller in a vehicle.
[0043] For example, Figure 2 As shown, the method 200 includes:
[0044] Step 201, the target client obtains a contract file supported by the target client and the corresponding target server, where the contract file is used to define the request content sent by the target client to the target server when executing the target task, where the request content includes N request fields, where the request field is a request code line after the request content is written in a specific format, and 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 the above step 201 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 accordance with the request format, and the target server sends a data response (i.e., response content) to the target client in accordance with the response format. In addition, the specific request format and the specific response format are related to the task performed by the target client.
[0047] It should also be understood that the "target task" in the above step 201 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 to update 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 language refers to 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 packet sent by the target client to the target server, including multiple request fields and related information, the related information including 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 performed, etc. 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, 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 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 an 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 an 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 an 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 an 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 of 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] Exemplarily, as in Example 2, taking the request content in Example 1 as an example, the process of determining the M groups of request fields is described. The request content includes 4 request fields, specifically: the first request field "optional int64 id=1", the second request field "optional string name=2", the third request field "optional int32 age=3" and the fourth request field "optional string address=4". Among them, 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 above 4 request fields, the determined M groups of request fields are: 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, and 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. Among them, the command request type is used to require 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. The difference between it and the written format is 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 scheme refers to a tool that can automatically extract code segments of a specific format from a contract file (request content), which can identify the extracted 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 writing structure of the request content corresponding to different request tasks and different request types is different. Therefore, the method combines the target task and the request type corresponding to the request content to accurately determine the writing structure of the request content. In this way, the distribution of multiple request fields specifically included in the request content can be clearly determined. On this basis, the method can accurately extract the data type corresponding to each request field from the request content with the help of the target extraction tool, so as to facilitate the subsequent generation of accurate general contract code blocks.
[0065] Step 203, the target client uses any group of request fields as the target group request field, generates a universal contract code block corresponding to the target group request field, and 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 the attribute code block in the present application, the above step 203 is described by taking any group of request fields (target group request fields) as an example. The process of determining the general contract code block and the attribute code block corresponding to other group request fields is similar to the process of determining the general contract code block and the 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 is used to indicate the commonality of the request fields in the target group request field" in the above step 203 refers to a contract code block generated by the common content of multiple request fields in the target group request field. In addition, the "commonality of the request fields" in the above step 203 is reflected in the data type corresponding to the request field.
[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 scheme is to schematically indicate that the target code content can 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 group 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 the request fields of which data types 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, 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 general contract code block corresponding to the second group of request fields is described. 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 group of request fields is string, "isArray=false" is used to indicate that the field name of the request field in the second group of request fields is not an array, "string" is the data type corresponding to the second group 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, a common code block corresponds to an 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 a field name and a corresponding request order, and an attribute code block of a 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, and through the field name of each request field, an attribute code block of a 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 arrangement order of the request fields 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, generate 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 field. 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 in 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] Exemplarily, 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 field name. 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] The property code block 2 is as follows:
[0094] public class Attribute{
[0095] column-name name(2), address(4);
[0096]
[0097] Among them, "name" in "name(2)" is a 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. "address" in "address(4)" is a 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.
[0098] Step 205, the target client combines the common 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, which 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] Exemplarily, as in Example 5, taking the multiple request fields included in the request content in Example 1 as an example, the process of determining the contract code of the contract document is described.
[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 extracts the actual response value corresponding to each of 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 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 performs 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.
[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 value" in the above scheme is a plurality of values directly extracted from the response content, and the plurality of values are original transmission values. In some embodiments, the plurality of 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 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 the response timing out.
[0107] In the above technical solution, the target server responds to the request content in a fixed format. Therefore, in the method, the actual response value (N actual response values) corresponding to each request field in the N request fields can be extracted from the response content based on the response format by the target extraction tool. Further, in the method, based on the N actual response values and the data contract (contract code) to be followed, it is determined whether the interaction process between the target client and the target server is abnormal. This can determine that the interaction process may be attacked. When the interaction process is not abnormal, the method performs a base conversion on the N actual response values and further executes the target task. In other words, the method verifies the actual response value, and only executes the target task through the N actual response values when the state of the interaction process is used to reflect that the N actual response values are correct. The method can avoid the abnormal interaction process, and the target client also processes the abnormal actual response value, thereby causing an abnormal phenomenon to occur in the target client, and the abnormal phenomenon includes 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 interactive functions 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 "determining 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" in the above scheme means determining 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 through N actual response values and the contract code. The response here refers to the response to the content. When the matching degree does not take into account the delay time of responding to the request content, the above scheme needs to further determine whether an abnormality occurs in the interactive process based on the delay time of 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 within the time limit 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: when 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 data type when the target server responds 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 response order when the target server responds 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 "weighted sum of the first matching degree and the second matching degree to obtain the matching degree" in the above solution specifically refers to multiplying the first matching degree by the first coefficient to obtain a first value, multiplying the second matching degree by the second coefficient to obtain a second value, and determining the sum of the first value and the second value as the matching degree. In some embodiments, the first coefficient is used to measure the contribution of the corresponding part of the data type when determining the matching degree, and the second coefficient is used to measure the contribution of the corresponding part of the arrangement order when determining the matching degree.
[0114] In the above technical solution, the target client sends the request content to the target server, and the target server sends the response content to the target client to realize the interactive function between the target client and the target server. The response content is the response result (N actual response values) of 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 match 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 number of request fields; the target client determines a second number 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 number and the first number as the first degree of match.
[0116] In some embodiments, the target client determines a second degree of match based on the response order corresponding to each of 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 match.
[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 a 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 converting the base of each of the N actual response values is the same. Therefore, the above scheme exemplarily takes any actual response value of the N actual response values as an example to describe the process of converting the base of the actual response value to obtain the corresponding target response value. Usually, the preset number of bits is 8 bits, and the highest bit is the sign bit. The processed binary value can be converted according to the target base type by 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 base conversion of 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 the processed binary value. This is to delete the influence of the sign bit in the base conversion process, and is used to more simply represent the actual response value. The base number system to be converted by the actual response value 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 base conversion of the processed binary value, an accurate target response value can be obtained. Further, 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 a decimal type 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 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. 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 It is a schematic diagram of a process of generating code provided in an embodiment of the present application.
[0127] For example, Figure 3As 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 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 the corresponding first contract code (i.e., through the 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 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 executing the target task; the target client generates the 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 the 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 It is a schematic diagram of another process of generating code 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 type corresponding to the request field 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 the contract code based on the expected response content in the contract file is similar to the process of generating the contract code based on the request content in the contract file, which will not be repeated here.
[0132] Figure 5 It is a structural diagram of a device for generating code provided in an embodiment of the present application.
[0133] For example, Figure 5 As shown, the device 500 includes:
[0134] Acquisition module 501: used to acquire 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, the request field is a request code line after the request content is written in a specific format, and N is a positive integer greater than 1;
[0135] A determination 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 for:
[0137] Taking any group of request fields as the target group request field, generating a general contract code block corresponding to the target group request field, the target group request field corresponds to a general contract code block, the general 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 general 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;
[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, which is 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 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.
[0142] Optionally, the contract file is also used to define the response format expected by the target client, the contract code is used by the target client to parse the received response content, and the extraction module is specifically used to extract the actual response value corresponding to each request field in 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 also specifically 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 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 the matching degree of the data type when the target server responds to the request content; determine a second matching degree based on a response order corresponding to each actual response value in the N actual response values and a corresponding arrangement order in the contract code, wherein 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 functional modules of the device can be divided according to the above method example. For example, each functional module can be corresponded, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0149] In the case of dividing each functional module according to each function, the device may also include an acquisition module, a determination module, a generation module, an extraction module, and a parsing module, etc. It should be noted that all relevant contents involved in the above method embodiment can be referred to the functional description of the corresponding functional module, which 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 applied to a vehicle, the processing module may be used to control and manage the actions of the vehicle. The storage module may be used to support the vehicle in executing related executable program codes, etc.
[0152] The processing module may be a processor or a controller, which may implement or execute various exemplary logic blocks, modules and circuits shown in conjunction with the disclosure of the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module may be a memory.
[0153] In addition, the device provided in the embodiments of the present application may specifically be a chip, a component or a module, and the chip may include a connected processor and a 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, in which executable program code is stored. When the executable program code is run 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 also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the above-mentioned related steps to implement a method for generating codes provided in the above embodiment.
[0156] Among them, the device, computer-readable storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method 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 assigned to 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 the present 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 only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, 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 contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for generating a code, characterized in that: The method comprises: Obtain 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, wherein the request fields are request code lines after the request content is written in a specific format, and N is a positive integer greater than 1; Based on the data type corresponding to each request field, the N request fields are classified to determine M groups of request fields, where the data type corresponding to each request field in each group of request fields is the same, 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 general contract code block corresponding to the target group request field, wherein the target group request field corresponds to a general contract code block, and the general contract code block is used to indicate the commonality of the request fields in the target group request field; Generate an attribute code block of the general contract code block corresponding to the target group request field, 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, which 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 data types corresponding to the various request fields are extracted from the request content based on the writing structure by a target extraction tool.
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, generate an annotation code line 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, wherein 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.
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, and 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 through the field name of each request field.
5. The method according to claim 1, characterized in that: 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 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; 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; In the case that no abnormality occurs in 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: Based on the N actual response values and the contract code, determining a matching degree of the interactive function between the target client and the target server 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 function between the target client and the target server includes: Determine 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 target server in terms of data type when responding to the request content; Determine a second matching degree based on a response order corresponding to each actual response value in the N actual response values and a corresponding arrangement order in the contract code, wherein the second matching degree is 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, used 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, wherein the request fields are request code lines after the request content is written in a specific format, and 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 general contract code block corresponding to the target group request field, wherein the target group request field corresponds to a general contract code block, and the general contract code block is used to indicate the commonality of the request fields in the target group request field; Generate an attribute code block of the general contract code block corresponding to the target group request field, 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, and the contract code is the 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 codes; A processor, 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
Data comparison method and system, electronic equipment and storage medium
CN118939671A
Method, apparatus, device, medium and product for application package generation
US20240329971A1
Data processing method, apparatus, and device, and computer readable storage medium
WO2022002030A1