Data processing method, device, apparatus, storage medium and program product
By automating the conversion of Java class objects to Protobuf messages, the heavy encoding problem when developing GRPC services is solved, the development difficulty and cost are reduced, and efficient code generation is achieved.
Patent Information
- Application Number
- CN202111486619.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-07
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2041-12-07
AI Technical Summary
When developing GRPC services, developers need to define the Protobuf message format and the corresponding Java class objects at the same time, resulting in heavy and redundant encoding work, increasing development difficulty and cost.
By obtaining the object to be converted, converting fields, content and types according to the correspondence between the message and the data type of the class object, generating the conversion target object, and automatically completing the conversion of Java class object to Protobuf message using plug-in, reducing the redundant code written by developers, reducing the number of developers to write redundant code demand.
It greatly reduces the workload and code redundancy of developers, simplifies the conversion process of Java class objects to Protobuf messages, and makes development more efficient.
Smart Images

Figure CN114385128B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data processing method, device, apparatus, storage medium and program product. Background Art
[0002] GRPC is a cross-language, cross-platform, open source remote procedure call system developed by Google. It is a high-performance, open source and universal remote procedure call (RPC) framework designed for mobile and HTTP / 2. It provides different language versions, such as C, Java and Go. In GRPC, client applications can directly call methods of server applications on different machines just like calling local objects. Based on this, when developing GRPC services, you need to specify the methods that can be called remotely as well as the parameters and return value types of the methods.
[0003] During the data exchange between the client application and the server application, GRPC uses the data transmission format protocol (Google Protocol Buffers, Protobuf) developed by Google to encode and decode data. Taking the Java language development environment as an example, the server can implement the interface of the GRPC service and define the message format of Protobuf to convert Java class objects into Protobuf messages that GRPC can recognize when processing the client's call request. Define a method stub like the server on the client, which can convert the Protobuf message returned by the server into a Java program that the client can execute according to the Protobuf message format.
[0004] In fact, Protobuf messages and their corresponding Java class objects implement the same functions in different forms. When developing GRPC services, in order to realize the conversion between Java class objects and Protobuf messages, it is necessary to define the Protobuf message format and write the Java class objects corresponding to the Protobuf messages. For developers, the coding work is heavy. Summary of the invention
[0005] The present application provides a data processing method, device, apparatus, storage medium and program product to at least reduce the coding workload of developers when developing GRPC services and reduce development costs.
[0006] An embodiment of the present application provides a data processing method, the method comprising: obtaining an object to be converted; the object to be converted comprises a message or a class object in a preset programming language program; according to the data type correspondence between the message and the class object, respectively converting the field of the object to be converted and the content corresponding to the field and the type corresponding to the field to obtain field conversion information, content conversion information and type conversion information; obtaining a conversion target object corresponding to the object to be converted according to the field conversion information, content conversion information and type conversion information; wherein, when the object to be converted comprises a class object in the preset programming language program, the conversion target object comprises the message; when the object to be converted comprises the message, the conversion target object comprises the class object in the preset programming language program.
[0007] In an optional embodiment, the object to be converted includes a class object in the preset programming language program, and the method further includes: parsing the class object to obtain detailed information of the class object; the detailed information includes the fields of the class object and the content corresponding to the fields and the type corresponding to the fields.
[0008] In an optional embodiment, the detailed information of the class object also includes annotation information corresponding to the field, and the method further includes: using the annotation information corresponding to the field of the class object as the annotation information corresponding to the corresponding field in the conversion target object.
[0009] In an optional embodiment, according to the data type correspondence between the message and the class object, the fields of the object to be converted and the contents corresponding to the fields and the types corresponding to the fields are respectively converted to obtain field conversion information, content conversion information and type conversion information, including: calling a target plug-in so that the target plug-in converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence to obtain the type conversion information, and converts the fields and the contents corresponding to the fields into the fields of the message and the contents corresponding to the fields to obtain the field conversion information and content conversion information.
[0010] In an optional embodiment, the calling of the target plug-in includes: generating a target file recognizable by the target plug-in according to the field and the content, quantity and type of the field; and passing the target file to the target plug-in in response to a plug-in selection operation.
[0011] In an optional embodiment, the method further includes: if the field naming method of the class object is different from the field naming method corresponding to the message format, adjusting the converted fields of the class object according to the naming method corresponding to the message format.
[0012] In an optional embodiment, the preset programming language includes the Java programming language, the class object includes a Java class object, and the message includes a Protobuf message; converting the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence includes: determining the data type correspondence between the Protobuf message and the Java class object according to the Protobuf message format and the grammatical rules of the Java programming language; determining the target data type in the Protobuf message corresponding to the type of the field in the Java class object according to the data type correspondence; converting the type of the field in the Java class object into the target data type corresponding to the Protobuf message as the data type adapted to the Protobuf message format.
[0013] In an optional embodiment, determining the target data type corresponding to the type of the field in the Java class object in the Protobuf message includes: if the type of the field in the Java class object is a basic data type of the Java programming language or an encapsulation type corresponding to the basic data type, determining that the basic data type in the Protobuf message format has the same data structure as the type of the field as the target data type; if the type of the field in the Java class object is a class object type in the Java programming language, determining that the message body type in the Protobuf message format is the target data type; if the type of the field in the Java class object is a collection type in the Java programming language, determining that the collection type in the Protobuf message format has the same data structure as the type of the field as the target data type; if the type of the field in the Java class object is a string or character array type in the Java programming language, determining that the data type in the Protobuf message format has the same data structure as the type of the field as the target data type.
[0014] In an optional embodiment, after determining that the collection type in the Protobuf message format has the same data structure as the type of the field is the target data type, it also includes: for each collection field element in the collection type field, according to the data type correspondence between the Protobuf message and the Java class object, converting the type corresponding to each collection field element into a data type adapted to the Protobuf message format, and converting each collection field element and the content corresponding to each collection field element into each collection field element and the content corresponding to each collection field element in the target data type.
[0015] In an optional embodiment, the method further includes: calling a copy and paste manager to copy and paste the content conversion information and type conversion information to a clipboard; in response to a paste operation on the content conversion information and type conversion information, pasting the content conversion information and type conversion information on the clipboard to a corresponding storage object to obtain the conversion target object.
[0016] An embodiment of the present application also provides a data processing device, comprising: a processor and a memory storing a computer program; the processor is used to execute the computer program to: obtain an object to be converted; the object to be converted includes a message or a class object in a preset programming language program; according to the data type correspondence between the message and the class object, the field of the object to be converted and the content corresponding to the field and the type corresponding to the field are converted respectively to obtain field conversion information, content conversion information and type conversion information; according to the field conversion information, the content conversion information and the type conversion information, a conversion target object corresponding to the object to be converted is obtained; wherein, when the object to be converted includes the class object in the preset programming language program, the conversion target object includes the message; when the object to be converted includes the message, the conversion target object includes the class object in the preset programming language program.
[0017] In an optional embodiment, the object to be converted includes a class object in a preset programming language program, and the processor is further used to: parse the class object to obtain detailed information of the class object; the detailed information includes the fields of the class object and the content corresponding to the fields and the types corresponding to the fields.
[0018] In an optional embodiment, the detailed information of the class object also includes annotation information corresponding to the field, and the processor is further configured to: use the annotation information corresponding to the field of the class object as the annotation information corresponding to the corresponding field in the conversion target object.
[0019] In an optional embodiment, when the processor converts the fields of the object to be converted and the contents corresponding to the fields and the types corresponding to the fields respectively according to the data type correspondence between the message and the class object to obtain field conversion information, content conversion information and type conversion information, it is used to: call the target plug-in so that the target plug-in converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence to obtain type conversion information, and converts the fields and the contents corresponding to the fields into the fields of the message and the contents corresponding to the fields respectively to obtain field conversion information and content conversion information.
[0020] In an optional embodiment, when calling the target plug-in, the processor is used to: generate a target file recognizable by the target plug-in based on the fields and the content, quantity and type of the fields; and pass the target file to the target plug-in in response to the plug-in selection operation.
[0021] In an optional embodiment, the processor is further configured to: if the field naming method of the class object is different from the field naming method corresponding to the message format, adjust the converted field of the class object according to the naming method corresponding to the message format.
[0022] In an optional embodiment, the preset programming language includes the Java programming language, the class object includes the Java class object, and the message includes the Protobuf message; when the processor converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence, it is used to: determine the data type correspondence between the Protobuf message and the Java class object according to the Protobuf message format and the grammatical rules of the Java programming language; determine the target data type in the Protobuf message corresponding to the type of the field in the Java class object according to the data type correspondence; convert the type of the field in the Java class object into the target data type corresponding to the Protobuf message as the data type adapted to the Protobuf message format.
[0023] In an optional embodiment, when determining the target data type corresponding to the type of a field in a Java class object in a Protobuf message, the processor is used to: if the type of the field in the Java class object is a basic data type of the Java programming language or an encapsulation type corresponding to the basic data type, then determine the basic data type with the same data structure as the type of the field in the Protobuf message format as the target data type; if the type of the field in the Java class object is a class object type of the Java programming language, then determine the message body type in the Protobuf message format as the target data type; if the type of the field in the Java class object is a collection type of the Java programming language, then determine the collection type with the same data structure as the type of the field in the Protobuf message format as the target data type; if the type of the field in the Java class object is a string or character array type of the Java programming language, then determine the data type with the same data structure as the type of the field in the Protobuf message format as the target data type.
[0024] In an optional embodiment, after determining that the collection type having the same data structure as the type of the field in the Protobuf message format is the target data type, the processor is further used to: for each collection field element in the collection type field, according to the data type correspondence between the Protobuf message and the Java class object, convert the type corresponding to each collection field element into a data type adapted to the Protobuf message format, and convert each collection field element and the content corresponding to each collection field element into each collection field element and the content corresponding to each collection field element in the target data type.
[0025] In an optional embodiment, the processor is also used to: call the copy and paste manager to copy and paste the content conversion information and the type conversion information to the clipboard; in response to the paste operation on the content conversion information and the type conversion information, paste the content conversion information and the type conversion information on the clipboard to the corresponding storage object to obtain a conversion target object.
[0026] An embodiment of the present application also provides a data processing device, including: an acquisition module, a first processing module and a second processing module; the acquisition module acquires an object to be converted; the object to be converted includes a message or a class object in a preset programming language program; the first processing module is used to convert the fields of the object to be converted and the contents corresponding to the fields and the types corresponding to the fields according to the data type correspondence between the message and the class object, respectively, to obtain field conversion information, content conversion information and type conversion information; the second processing module is used to obtain a conversion target object corresponding to the object to be converted according to the field conversion information, content conversion information and type conversion information; wherein, when the object to be converted includes a class object in the preset programming language program, the conversion target object includes the message; when the object to be converted includes the message, the conversion target object includes the class object in the preset programming language program.
[0027] In an optional embodiment, the object to be converted includes a class object in a preset programming language program, and the first processing module is further used to: parse the class object to obtain detailed information of the class object; the detailed information includes the fields of the class object and the content corresponding to the fields and the types corresponding to the fields.
[0028] In an optional embodiment, the detailed information of the class object also includes annotation information corresponding to the field, and the first processing module is further used to: use the annotation information corresponding to the field of the class object as the annotation information corresponding to the corresponding field in the conversion target object.
[0029] In an optional embodiment, when the first processing module converts the fields of the object to be converted and the contents corresponding to the fields and the types corresponding to the fields respectively according to the data type correspondence between the message and the class object to obtain field conversion information, content conversion information and type conversion information, it is used to: call the target plug-in so that the target plug-in converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence to obtain type conversion information, and converts the fields and the contents corresponding to the fields into the fields of the message and the contents corresponding to the fields respectively to obtain field conversion information and content conversion information.
[0030] In an optional embodiment, when calling the target plug-in, the first processing module is used to: generate a target file recognizable by the target plug-in based on the fields and the content, quantity and type of the fields; and pass the target file to the target plug-in in response to a plug-in selection operation.
[0031] In an optional embodiment, the first processing module is further used to: if the field naming method of the class object is different from the field naming method corresponding to the message format, adjust the converted field of the class object according to the naming method corresponding to the message format.
[0032] In an optional embodiment, the preset programming language includes the Java programming language, the class object includes the Java class object, and the message includes the Protobuf message; when the first processing module converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence, it is used to: determine the data type correspondence between the Protobuf message and the Java class object according to the Protobuf message format and the grammatical rules of the Java programming language; determine the target data type in the Protobuf message corresponding to the type of the field in the Java class object according to the data type correspondence; convert the type of the field in the Java class object into the target data type corresponding to the Protobuf message as a data type adapted to the Protobuf message format.
[0033] In an optional embodiment, when determining the target data type corresponding to the type of a field in a Java class object in a Protobuf message, the first processing module is used to: if the type of the field in the Java class object is a basic data type of the Java programming language or an encapsulation type corresponding to the basic data type, then determine the basic data type with the same data structure as the type of the field in the Protobuf message format as the target data type; if the type of the field in the Java class object is a class object type of the Java programming language, then determine the message body type in the Protobuf message format as the target data type; if the type of the field in the Java class object is a collection type of the Java programming language, then determine the collection type with the same data structure as the type of the field in the Protobuf message format as the target data type; if the type of the field in the Java class object is a string or character array type of the Java programming language, then determine the data type with the same data structure as the type of the field in the Protobuf message format as the target data type.
[0034] In an optional embodiment, after determining that the collection type having the same data structure as the type of the field in the Protobuf message format is the target data type, the first processing module is further used to: for each collection field element in the collection type field, according to the data type correspondence between the Protobuf message and the Java class object, convert the type corresponding to each collection field element into a data type adapted to the Protobuf message format, and convert each collection field element and the content corresponding to each collection field element into each collection field element and the content corresponding to each collection field element in the target data type.
[0035] In an optional embodiment, the second processing module is also used to: call the copy and paste manager to copy and paste the content conversion information and the type conversion information to the clipboard; in response to the paste operation on the content conversion information and the type conversion information, paste the content conversion information and the type conversion information on the clipboard to the corresponding storage object to obtain a conversion target object.
[0036] An embodiment of the present application also provides a computer-readable storage medium. When instructions in the computer-readable storage medium are executed by a processor of a data processing device, the data processing device is enabled to execute the data processing method.
[0037] An embodiment of the present application also provides a computer program product, including a computer program / instructions, which implement the data processing method when executed by a processor.
[0038] In an embodiment of the present application, for a message in a preset message format to be converted or a class object in a preset programming language program, the fields of the message or class object to be converted and the content and type of the field can be converted respectively according to the data type correspondence between the message and the class object, and the corresponding field conversion information, content conversion information and type conversion information can be obtained; based on this, according to the field conversion information, content conversion information and type conversion information obtained by the conversion, the conversion target object corresponding to the message to be converted and the class object can be obtained. In this way, it is possible to convert a message with a preset message format into a class object in a preset programming language program, or to convert a class object in a preset programming language program into a message with a preset message format. Taking the conversion of a Java class object into a Protobuf message as an example, when developers write Java programs, they only need to write Java class objects that implement specified functions, without having to write functional codes for converting Java class objects to Protobuf messages, which greatly reduces the workload of developers and the redundancy of code.
[0039] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application, and do not constitute an improper limitation on the present application.
[0041] Figure 1a is a flow chart of a data processing method according to an embodiment of the present application;
[0042] Figure 1b is a schematic diagram showing an execution process of a data processing method according to an exemplary embodiment;
[0043] Figure 1c It is a flowchart of a method for converting a data type from a Java class object to a Protobuf message according to an exemplary embodiment;
[0044] Figure 2 is a structural schematic diagram of a data processing device provided in an embodiment of the present application;
[0045] Figure 3 It is a structural diagram of a data processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] In order to enable ordinary persons in the art to better understand the technical solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0047] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices, apparatuses, and methods consistent with some aspects of the present application as detailed in the attached claims.
[0048] In the process of developing application services, in many scenarios, it is necessary to convert one object into another object for processing in order to reduce development costs or processing difficulty. For example, when it is difficult to directly process a message with a preset message format, the message can be converted into a class object in a preset programming language program, and the processing difficulty can be reduced by processing the object of this class; for another example, when it is difficult to directly process a class object in a preset programming language program, the class object can be converted into a message with a preset message format, and the converted message can be processed, which is simple and quick to implement, and so on. In order to realize the conversion between different objects, it is usually necessary to define the conversion rules between different objects. For example, in the process of GRPC service development, in order to realize the conversion between Java class objects and Protobuf messages, developers must write both the Protobuf message format and the Java class object corresponding to the Protobuf message. In this way, not only the difficulty of the developer's work is increased, but also the redundancy of the code is increased.
[0049] In view of this situation, an embodiment of the present application provides a data processing method for realizing automatic conversion between different objects to reduce the work difficulty and code redundancy of developers.
[0050] Figure 1a A flowchart of a data processing method provided in an embodiment of the present application, such as Figure 1a As shown, the method includes:
[0051] S1. Obtain an object to be converted, where the object to be converted includes a message or a class object in a preset programming language program;
[0052] S2. According to the data type correspondence between the message and the class object, the field of the object to be converted, the content corresponding to the field, and the type corresponding to the field are converted to obtain field conversion information, content conversion information, and type conversion information;
[0053] S3. Obtain a conversion target object corresponding to the object to be converted according to the field conversion information, the content conversion information and the type conversion information; wherein, when the object to be converted is a class object in a preset programming language program, the conversion target object is a message; when the object to be converted is a message, the conversion target object is a class object in a preset programming language program.
[0054] In the embodiment of the present application, the object to be converted is a class object in a preset programming language program as an example for explanation. Regarding the case where the object to be converted is a message with a preset message format, you can refer to the embodiment of the present application, and the specific implementation process will not be described in detail for the time being.
[0055] In an embodiment of the present application, when a class object to be converted is obtained, the class object can be parsed to obtain detailed information of the class object; optionally, the detailed information of the class object includes at least the fields of the class object and the contents corresponding to the fields and the types corresponding to the fields; further optionally, the detailed information of the class object can also include annotation information corresponding to the fields, then when the class object is converted into a message having a preset message format, the annotation information corresponding to the fields of the class object can also be used as annotation information corresponding to the corresponding fields in the message.
[0056] In the embodiment of the present application, the specific method of converting the fields of the class object to be converted, the content corresponding to the fields, and the type corresponding to the fields to obtain field conversion information, content conversion information, and type conversion information is not limited. Optionally, the target plug-in can be called to enable the target plug-in to convert the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence relationship to obtain type conversion information; and convert the field and the content corresponding to the field into the field of the message and the content corresponding to the field to obtain field conversion information and content conversion information.
[0057] Further optionally, before calling the target plug-in, a target file recognizable by the target plug-in can be generated based on the fields of the class object and the content, quantity and type of the fields, and in response to the plug-in selection operation, the target file can be passed to the target plug-in so that the target plug-in can convert the fields of the class object and the corresponding content and types of the fields according to the target file.
[0058] In the embodiment of the present application, in addition to converting the fields of the class object and the content and type of the fields, in order to make the converted message more readable, the naming method of the fields in the class object can also be converted. Optionally, if the field naming method of the class object is different from the field naming method corresponding to the message format, the converted fields of the class object are adjusted according to the naming method corresponding to the message format to obtain a field naming method that conforms to the message format, so that the converted message can be self-explanatory and easy to read.
[0059] Below, taking the class object in the preset programming language program as a Java class object and the message with a preset message format as a Protobuf message as an example, the process of converting a Java class object into a Protobuf message in the embodiment of the present application is described in detail. In the embodiment of the present application, the implementation form of the execution subject of the data processing method is not limited. It can be a plug-in such as a Java archive file (Java ARchive, Jar) applied to a program editing tool, or it can be a separate executable program file. The embodiment of the present application takes the plug-in form as an example, combined with the plug-in installed in the scenario of the program editing tool, the execution process of the data processing method provided in the embodiment of the present application is described.
[0060] In the embodiment of the present application, the specific implementation form of the program editing tool is not limited, and any program editing tool with plug-in expansion capability and applicable to the Java development environment is applicable to the embodiment of the present application. In the embodiment of the present application, the program editing tool is Intellij Idea applied to the integrated development environment (IDE) as an example, and the IDE plug-in that implements the Java class object to Protobuf message conversion function is used as the target plug-in in the embodiment of the present application. Based on this, the developer can install the target plug-in in Intellij Idea, use the program editing interface provided by Intellij Idea to write a Java program and generate a Java class object; optionally, the generated Java class object can be a simple ordinary Java class object (Plain Ordinary Java Object, POJO), or it can be a class object with certain logical functions, which is not limited here. Further, after obtaining the Java class object, the target plug-in can be used to convert the Java class object to obtain a Protobuf message that conforms to the Protobuf message format. During the entire development process, developers only need to write the Java class objects required to implement business functions, without having to write the message format of the Protobuf message. The conversion from Java class objects to Protobuf messages is done by the plug-in, which not only reduces the workload of developers, but also reduces code redundancy.
[0061] Figure 1b This is a schematic diagram of the process of combining the program editing tool and the target plug-in to implement the above data processing method in the embodiment of the present application. Figure 1bAs shown, the program editing tool 10 includes a program editing interface 01 and a program editing tool core 02. Developers can use the program editing interface 01 to write Java programs and generate Java class objects. Further, when the Java class objects are obtained, the developer can perform a plug-in selection operation for each Java class object to select a target plug-in 03, so that the target plug-in 03 can convert the detailed information of the Java class object according to the correspondence between the data type of the Java class object and the data type of the Protobuf message, and obtain a Protobuf message that conforms to the Protobuf message format.
[0062] Optionally, the developer can select a target Java class object from multiple Java class objects, display a plug-in list by triggering a plug-in display operation, and select a target plug-in 03 from the plug-in list. Further optionally, the developer can trigger a plug-in display operation by clicking a separate control or by right-clicking a mouse, and select a target plug-in 03 from the displayed plug-in list, and execute the target plug-in 03 to convert the selected target Java class object.
[0063] Further, when the program editing tool kernel 02 senses that the developer has selected the target plug-in 03, it can identify the target Java class object selected by the developer and parse the detailed information in the Java class object, obtain the fields in the Java class object and the content and type of the fields, and pass the parsed detailed information to the target plug-in 03. Further, the target plug-in 03 can convert the type of the field in the Java class object into a data type adapted to the Protobuf message format, and convert the fields in the Java class and the content of the fields into the fields and the content of the fields of the Protobuf message, according to the correspondence between the data type of the Java class object and the data type of the Protobuf message, to obtain a Protobuf message that conforms to the Protobuf message format.
[0064] In an optional embodiment of the present application, the target plug-in 03 can determine the target data type corresponding to the type of the field in the Java class object in the Protobuf message according to the correspondence between the data type of the Java class object and the data type of the Protobuf message, and convert the type of the field in the Java class object to the corresponding target data type in the Protobuf message. Optionally, the correspondence between the data type of the Java class object and the data type of the Protobuf message is shown in Table 1, wherein sequence numbers 1-5 are the basic data types of the Java class object, sequence numbers 6-10 are the encapsulation types corresponding to the basic data types of the Java class object, sequence numbers 11 and 12 are the collection types of the Java class object, sequence number 13 is the class object type corresponding to the Java class object, sequence number 14 is the string type in the Java class object, and sequence number 15 is a Java type defined in the Protobuf message format, corresponding to the bytes type in the Protobuf message format, used to represent a binary byte array. It should be noted that the correspondence in Table 1 is only an exemplary description and is not limited to this. According to different business needs, the number of data types of the Java class object and the corresponding data types in the Protobuf message in Table 1 can also be more or less, which is not limited here.
[0065] As shown in Table 1, the basic data types of Java class objects and their encapsulation types have the same data structure in the Protobuf message and correspond to the same data type. Based on this, when the target plug-in determines the target data type corresponding to the type of the field in the Java class object in the Protobuf message according to the correspondence between the data type of the Java class object and the data type of the Protobuf message, the type of the field in the Java class object can be used as the primitive data type, and it is determined whether the primitive data type is any one of the basic data type of the Java class object or the encapsulation type of the basic data type, object type, collection type, string type, or character array type. Further, when determining the primitive data type, the data type corresponding to the primitive data type in the Protobuf message can be determined as the target data type according to the correspondence in Table 1.
[0066] Figure 1c A flowchart for determining the original data type for the target plug-in 03 and determining the target data type according to the correspondence between the data type of the Java class object and the data type of the Protobuf message. Figure 1cAs shown, the target plug-in 03 traverses the fields in the Java class object and identifies the types of the fields in the Java class object when the detailed information of the Java class object is obtained. Further, for the original type corresponding to each field, it is determined whether the original data type is the basic data type of the Java class object or the encapsulation type of the basic data type. If so, the basic data type with the same data structure as the original data type in the Protobuf message is determined as the target data type; otherwise, it continues to determine whether the original data type is the class object type. If so, the message body type in the Protobuf message is determined as the target data type; otherwise, it continues to determine whether the original data type is the collection type of the Java class object. If so, the collection type with the same data structure as the original data type in the Protobuf message is determined as the target data type; otherwise, it continues to determine whether the original data type is the string or character array type of the Java class object. If so, the data type with the same data structure as the original data type in the Protobuf message is determined as the target data type; otherwise, an exception is handled for the data type that is not identified as data, and the fields in the Java class object are continued to be traversed for subsequent conversion.
[0067] In the embodiments of the present application, Figure 1c As shown, in the case where the original data type is a collection type of Java class objects, the data type conversion can also be performed for each collection field element in the collection type according to the data type correspondence between the Protobuf message and the Java class object, so as to convert the field type of each collection field element into a data type adapted to the Protobuf message format. Further optionally, each collection field element and the content corresponding to each collection field element can also be converted into each collection field element and the content corresponding to each collection field element in the target data type.
[0068] Combined with the corresponding relationship in Table 1, it can be seen that Figure 1cIn the process shown, if the original data type is int type or Integer type, the target type is determined to be int32 type in Protobuf; if the original data type is boolean type or Boolean type, the target type is determined to be bool type in Protobuf; if the original data type is Class type, the target type is determined to be message type in Protobuf; if the original data type is List type, the target type is determined to be repeated type in Protobuf; if the original data type is Map type, the target type is determined to be map type in Protobuf; if the original data type is String type, the target type is determined to be string type in Protobuf; if the original data type is ByteString type, the target type is determined to be bytes type in Protobuf, and of course it is not limited to this.
[0069] Table 1
[0070] Serial number Java Data Types Protobuf Data Types 1 long int64 2 int int32 3 double double 4 float float 5 boolean bool 6 java.lang.Long int64 7 java.lang.Integer int32 8 java.lang.Double double 9 java.lang.Float float 10 java.lang.Boolean bool 11 java.util.List repeated 12 java.util.Map map 13 java.lang.Class message 14 java.lang.String string 15 com.google.protobuf.ByteString bytes
[0071] In an embodiment of the present application, the program editing tool kernel 02 can also generate a target file recognizable by the target plug-in 03 according to the content and number of fields and the type of fields when parsing the Java class object and obtaining the detailed information of the Java class object. For example, the target file can be a PisClass class object recognizable by Intellij Idea, which includes the name of the Java class object, the number of fields of the Java class object, and the name, content and type of the field. Further optionally, the program editing tool kernel 02 can determine the target plug-in 03 for implementing the conversion of the Java class object to the Protobuf message in response to the developer performing the plug-in selection operation, and pass the target file to the target plug-in 03. When the target plug-in 03 receives the target file, it can identify the information of the target file, and convert the field type in the target file into a type adapted to the Protobuf message format according to the corresponding relationship shown in Table 1, and convert the fields in the target file and the content of the fields into the fields and the content of the fields of the Protobuf message.
[0072] Further optionally, the detailed information of the Java class object parsed by the program editing tool kernel 02 may also include annotation information corresponding to the field, and the program editing tool kernel 02 may also include annotation information corresponding to the field of the Java class object in the target file generated according to the detailed information of the Java class object. Further, after converting the information of the target file according to the corresponding relationship in Table 1, the target plug-in 03 may also use the annotation information corresponding to the field of the Java class object as the annotation information corresponding to the field of the converted Protobuf message.
[0073] Further optionally, after converting the information of the target file, the target plug-in 03 can also identify the naming method corresponding to the converted field of the Java object class. If the naming method is different from the naming method corresponding to the field of the Protobuf message, the naming method corresponding to the converted field of the Java class object is adjusted according to the naming method corresponding to the field of the Protobuf message. For example, in the Java class object, the field is usually named in camel case, while in the Protobuf message, the field is usually named in dot-separation or underscore-separation. Based on this, the target plug-in 03 can identify the naming method corresponding to the field name in the Java class object, and when it is determined that it is not a dot-separation or underscore-separation naming method, the converted field name is renamed according to the naming method corresponding to the field in the dot Protobuf message to obtain a naming method that conforms to the Protobuf message format. Of course, the above-mentioned renaming method is only an exemplary description and is not limited to this. According to the difference between the original naming method and the target naming method, the conversion method may also be different, which is not limited here.
[0074] Based on the above, the following example is used to illustrate the conversion method from Java class objects to Protobuf messages.
[0075] Assume that the details of the Java class object are as follows:
[0076]
[0077]
[0078] When determining the detailed information of the Java class object, the program editing tool kernel 02 may parse it, identify the content, type, name and number of the fields in the Java class object, and generate a target file recognizable by the program editing tool kernel 02 based on the obtained information. For example, the target file may include the following information:
[0079] Class name: Student;
[0080] Number of fields: 3;
[0081] Field type, name and comment:
[0082] String name; / / Student name
[0083] int age; / / student age
[0084] int stuNum; / / student number
[0085] Based on the above, when the target plug-in obtains the information of the target file, it can convert the above information according to the correspondence between the data type of the Java class object and the data type of the Protobuf message, and rename the field name after the Java class object is converted according to the naming method of the field in the Protobuf message. Assuming that the naming method of the field in the Protobuf message is underscore separation, the following information is obtained:
[0086]
[0087] It should be noted that the above embodiment uses Java's POJO class object as an example to illustrate the conversion process from Java class object to Protobuf message, but is not limited to this. Further explanation: since the get method and set method in Java's POJO class object can be derived from the field name in Java, when converting the Java class object, only the Java field information can be converted without processing the get method and set method corresponding to each field, and the program code is more concise.
[0088] Further, if Figure 1b As shown, when the converted information is obtained, the target plug-in 03 can call the system copy and paste manager 04 to copy and paste the information line converted by the target plug-in 03 to the system clipboard, and in response to the developer performing a paste operation on the information in the clipboard, paste the information on the clipboard into the storage object 05 corresponding to the GRPC service to obtain a Protobuf message; wherein the storage object 05 can be a file in a specified directory. Based on this, the developer can apply the file to the GRPC service to implement the specified function in the GRPC service.
[0089] In an embodiment of the present application, for the Java class object obtained by programming, the field type in the Java class object can be converted into a data type adapted to the Protobuf message format through a plug-in for realizing the conversion of the Java class object to the Protobuf message, and the Java field and the content of the field and the annotation information can be converted into the field and the field content and the annotation information of the Protobuf message; and the naming method corresponding to the field of the converted Java class object can also be adjusted to a naming method that conforms to the Protobuf message format, so as to generate a Protobuf message according to the converted Java class object, which is used to implement the GRPC service of the specified function. In this way, the developer only needs to write the Java class object that implements the specified function, and there is no need to write the functional code for converting the Java class object to the Protobuf message. The conversion work is automatically completed by the plug-in, which greatly reduces the workload of the developer and the redundancy of the code.
[0090] It should be noted that the embodiment of the present application is explained by taking the conversion of Java class objects to Protobuf messages as an example. In specific application scenarios, the embodiment of the present application can also be applied to the conversion scenarios of class objects corresponding to C, C++, PHP and other programming languages to Protobuf messages or other format messages, which are not limited here. The execution subjects of each step of the method provided in the above embodiment can be the same device, or the method can be executed by different devices. For example, the execution subject of steps S1 to S3 can be device A; for another example, the execution subject of step S1 can be device A, and the execution subjects of steps S2 and S3 can be device B; and so on.
[0091] In addition, in some of the processes described in the above embodiments and the accompanying drawings, multiple operations that appear in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this article or executed in parallel, and the sequence numbers of the operations, such as S1, S2, etc., are only used to distinguish between different operations, and the sequence numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in this article are used to distinguish different messages, devices, modules, etc., do not represent the order of precedence, and do not limit the "first" and "second" to be different types.
[0092] The present application also provides a data processing device, Figure 2 The processor of the embodiment of the present application uses a structural diagram of a data processing device, such as Figure 2As shown, the data processing device includes: a processor 21 and a memory 22 storing a computer program. The processor 21 and the memory 22 may be one or more.
[0093] The memory 22 is mainly used to store computer programs, which can be executed by the processor, so that the processor controls the processor 21 to use the data processing device to implement corresponding functions, complete corresponding actions or tasks. In addition to storing computer programs, the memory can also be configured to store various other data to support operations on the data processing device used by the processor 21, examples of which include instructions for any application or method used to operate on the data processing device used by the processor 21.
[0094] The memory 22 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.
[0095] In the embodiments of the present application, the implementation form of the processor 21 is not limited, for example, it can be but not limited to a CPU, a GPU or an MCU. The processor 21 can be regarded as a control unit of a data processing device, which can be used to execute a computer program stored in the memory 22 to control the data processing device to implement corresponding functions and complete corresponding actions or tasks. It is worth noting that, depending on the implementation form of the data processing device and the different scenarios in which it is located, the functions to be implemented, the actions or tasks to be completed will be different; accordingly, the computer programs stored in the memory 22 will also be different, and the processor 21 can control the data processing device to implement different functions and complete different actions or tasks by executing different computer programs.
[0096] In some optional embodiments, such as Figure 2 As shown, the data processing device may further include other components such as a communication component 23 , a display 24 , and a power supply component 25 . Figure 2 Only some components are shown schematically, which does not mean that the data processing device only includes Figure 2 The data processing device may further include other components according to different application requirements, which may depend on the product form of the data processing device.
[0097] In the embodiments of the present application, the use scenarios and implementation forms of the data processing device are not limited, and the implementation forms of the data processing device may be different in different use scenarios. For example, in the IoT scenario, taking the vehicle use scenario as an example, the data processing device may be one of the vehicle-mounted devices; for another example, in the Internet or other scenarios, the data processing device may be a separate terminal device, a computer device, or a cloud server, etc., which are not limited here.
[0098] In an embodiment of the present application, when the processor 21 executes the computer program in the memory 22, it is used to: obtain an object to be converted, the object to be converted includes a message or a class object in a preset programming language program; according to the data type correspondence between the message and the class object, the field of the object to be converted and the content corresponding to the field and the type corresponding to the field are respectively converted to obtain field conversion information, content conversion information and type conversion information; according to the field conversion information, the content conversion information and the type conversion information, a conversion target object corresponding to the object to be converted is obtained; wherein, when the object to be converted includes a class object in the preset programming language program, the conversion target object includes a message; when the object to be converted includes the message, the conversion target object includes a class object in the preset programming language program.
[0099] In an optional embodiment, the object to be converted includes a class object in a preset programming language program, and the processor 21 is further used to: parse the class object to obtain detailed information of the class object; the detailed information includes the fields of the class object and the content corresponding to the fields and the types corresponding to the fields.
[0100] In an optional embodiment, the detailed information of the class object also includes annotation information corresponding to the field, and the processor 21 is further configured to: use the annotation information corresponding to the field of the class object as the annotation information corresponding to the corresponding field in the conversion target object.
[0101] In an optional embodiment, when the processor 21 converts the fields of the object to be converted and the contents corresponding to the fields and the types corresponding to the fields respectively according to the data type correspondence between the message and the class object to obtain field conversion information, content conversion information and type conversion information, it is used to: call the target plug-in so that the target plug-in converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence to obtain type conversion information, and converts the fields and the contents corresponding to the fields into the fields of the message and the contents corresponding to the fields respectively to obtain field conversion information and content conversion information.
[0102] In an optional embodiment, when calling the target plug-in, the processor 21 is used to: generate a target file recognizable by the target plug-in according to the fields and the content, quantity and type of the fields; and pass the target file to the target plug-in in response to the plug-in selection operation.
[0103] In an optional embodiment, the processor 21 is further configured to: if the field naming method of the class object is different from the field naming method corresponding to the message format, adjust the converted field of the class object according to the naming method corresponding to the message format.
[0104] In an optional embodiment, the preset programming language includes the Java programming language, the class object includes the Java class object, and the message includes the Protobuf message; when the processor 21 converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence, it is used to: determine the data type correspondence between the Protobuf message and the Java class object according to the Protobuf message format and the grammatical rules of the Java programming language; determine the target data type in the Protobuf message corresponding to the type of the field in the Java class object according to the data type correspondence; convert the type of the field in the Java class object into the target data type corresponding to the Protobuf message as a data type adapted to the Protobuf message format.
[0105] In an optional embodiment, when determining the target data type corresponding to the type of a field in a Java class object in a Protobuf message, the processor 21 is used to: if the type of the field in the Java class object is a basic data type of the Java programming language or an encapsulation type corresponding to the basic data type, then determine the basic data type with the same data structure as the type of the field in the Protobuf message format as the target data type; if the type of the field in the Java class object is a class object type of the Java programming language, then determine the message body type in the Protobuf message format as the target data type; if the type of the field in the Java class object is a collection type of the Java programming language, then determine the collection type with the same data structure as the type of the field in the Protobuf message format as the target data type; if the type of the field in the Java class object is a string or character array type of the Java programming language, then determine the data type with the same data structure as the type of the field in the Protobuf message format as the target data type.
[0106] In an optional embodiment, after determining that the collection type having the same data structure as the type of the field in the Protobuf message format is the target data type, the processor 21 is further used to: for each collection field element in the collection type field, according to the data type correspondence between the Protobuf message and the Java class object, convert the type corresponding to each collection field element into a data type adapted to the Protobuf message format, and convert each collection field element and the content corresponding to each collection field element into each collection field element and the content corresponding to each collection field element in the target data type.
[0107] In an optional embodiment, the processor 21 is also used to: call the copy and paste manager to copy and paste the content conversion information and the type conversion information to the clipboard; in response to the paste operation on the content conversion information and the type conversion information, paste the content conversion information and the type conversion information on the clipboard to the corresponding storage object to obtain a conversion target object.
[0108] The present application also provides a data processing device. For example, the data processing device can be implemented as a virtual device in a communication controller (Communication Control Unit, CCU), such as an application. Figure 3 As shown, the data processing device includes an acquisition module 301, a first processing module 302 and a second processing module 303; wherein the acquisition module 301 is used to acquire an object to be converted, and the object to be converted includes a message or a class object in a preset programming language program; the first processing module 302 is used to convert the fields of the object to be converted, the contents corresponding to the fields, and the types corresponding to the fields according to the data type correspondence between the message and the class object, respectively to obtain field conversion information, content conversion information, and type conversion information; the second processing module 303 is used to obtain a conversion target object corresponding to the object to be converted according to the field conversion information, the content conversion information, and the type conversion information; wherein, when the object to be converted includes a class object in a preset programming language program, the conversion target object includes a message; when the object to be converted includes a message, the conversion target object includes a class object in the preset programming language program.
[0109] In an optional embodiment, the object to be converted includes a class object in a preset programming language program, and the first processing module 302 is further used to: parse the class object to obtain detailed information of the class object; the detailed information includes the fields of the class object and the content corresponding to the fields and the types corresponding to the fields.
[0110] In an optional embodiment, the detailed information of the class object also includes annotation information corresponding to the field, and the first processing module 302 is further used to: use the annotation information corresponding to the field of the class object as the annotation information corresponding to the corresponding field in the conversion target object.
[0111] In an optional embodiment, when the first processing module 302 converts the fields of the object to be converted and the contents corresponding to the fields and the types corresponding to the fields respectively according to the data type correspondence between the message and the class object to obtain field conversion information, content conversion information and type conversion information, it is used to: call the target plug-in so that the target plug-in converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence to obtain type conversion information, and converts the fields and the contents corresponding to the fields into the fields of the message and the contents corresponding to the fields respectively to obtain field conversion information and content conversion information.
[0112] In an optional embodiment, when calling the target plug-in, the first processing module 302 is used to: generate a target file recognizable by the target plug-in according to the fields and their contents, quantity and types; and pass the target file to the target plug-in in response to a plug-in selection operation.
[0113] In an optional embodiment, the first processing module 302 is further configured to: if the field naming method of the class object is different from the field naming method corresponding to the message format, adjust the converted field of the class object according to the naming method corresponding to the message format.
[0114] In an optional embodiment, the preset programming language includes the Java programming language, the class object includes the Java class object, and the message includes the Protobuf message; when the first processing module 302 converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence, it is used to: determine the data type correspondence between the Protobuf message and the Java class object according to the Protobuf message format and the grammatical rules of the Java programming language; determine the target data type in the Protobuf message corresponding to the type of the field in the Java class object according to the data type correspondence; convert the type of the field in the Java class object into the target data type corresponding to the Protobuf message as a data type adapted to the Protobuf message format.
[0115] In an optional embodiment, when determining the target data type corresponding to the type of a field in a Java class object in a Protobuf message, the first processing module 302 is used to: if the type of the field in the Java class object is a basic data type of the Java programming language or an encapsulation type corresponding to the basic data type, then determine the basic data type with the same data structure as the type of the field in the Protobuf message format as the target data type; if the type of the field in the Java class object is a class object type of the Java programming language, then determine the message body type in the Protobuf message format as the target data type; if the type of the field in the Java class object is a collection type of the Java programming language, then determine the collection type with the same data structure as the type of the field in the Protobuf message format as the target data type; if the type of the field in the Java class object is a string or character array type of the Java programming language, then determine the data type with the same data structure as the type of the field in the Protobuf message format as the target data type.
[0116] In an optional embodiment, after determining that the collection type having the same data structure as the type of the field in the Protobuf message format is the target data type, the first processing module 302 is further used to: for each collection field element in the collection type field, according to the data type correspondence between the Protobuf message and the Java class object, convert the type corresponding to each collection field element into a data type adapted to the Protobuf message format, and convert each collection field element and the content corresponding to each collection field element into each collection field element and the content corresponding to each collection field element in the target data type.
[0117] In an optional embodiment, the second processing module 303 is also used to: call the copy and paste manager to copy and paste the content conversion information and the type conversion information to the clipboard; in response to the paste operation on the content conversion information and the type conversion information, paste the content conversion information and the type conversion information on the clipboard to the corresponding storage object to obtain the conversion target object.
[0118] It should be noted that the specific manner in which the processor of the above-mentioned data processing device and the modules of the data processing apparatus perform operations has been described in detail in the embodiments of the relevant methods and will not be elaborated on here.
[0119] Accordingly, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, which, when executed, can implement the steps that can be executed by a data processing device in the above method embodiment.
[0120] Accordingly, an embodiment of the present application further provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements each step that can be executed by a data processing device in the above method embodiment.
[0121] The communication component in the above-mentioned embodiment is configured to facilitate wired or wireless communication between the device where the communication component is located and other devices. The device where the communication component is located can access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G / LTE, 5G and other mobile communication networks, or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0122] The display in the above-mentioned embodiment includes a screen, and the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
[0123] The power supply assembly in the above embodiments provides power to various components of the device where the power supply assembly is located. The power supply assembly may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device where the power supply assembly is located.
[0124] The audio component in the above embodiments may be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC), and when the device where the audio component is located is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal may be further stored in a memory or sent via a communication component. In some embodiments, the audio component also includes a speaker for outputting an audio signal.
[0125] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0126] The present application is described with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, and the combination of the process and / or box in the flowchart and / or block diagram can be realized by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for realizing the function specified in one process or multiple processes in the flowchart and / or one box or multiple boxes in the block diagram.
[0127] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0128] These computer program instructions may also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0129] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0130] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0131] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0132] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0133] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
[0134] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0135] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A data processing method, characterized in that: The method comprises: Obtaining an object to be converted; the object to be converted includes a message or a class object in a preset programming language program; According to the correspondence between the message and the data type of the class object, the field of the object to be converted, the content corresponding to the field, and the type corresponding to the field are converted to obtain field conversion information, content conversion information, and type conversion information; Obtaining a conversion target object corresponding to the object to be converted according to the field conversion information, the content conversion information and the type conversion information; Wherein, when the object to be converted includes a class object in the preset programming language program, the conversion target object includes the message; when the object to be converted includes the message, the conversion target object includes a class object in the preset programming language program; The object to be converted includes a class object in the preset programming language program, and the method further includes: parsing the class object to obtain detailed information of the class object; the detailed information includes fields of the class object and contents corresponding to the fields and types corresponding to the fields; The detailed information of the class object also includes annotation information corresponding to the field. The method further includes: using the annotation information corresponding to the field of the class object as the annotation information corresponding to the corresponding field in the conversion target object.
2. The method according to claim 1, characterized in that According to the correspondence between the message and the data type of the class object, the field of the object to be converted, the content corresponding to the field, and the type corresponding to the field are converted to obtain field conversion information, content conversion information, and type conversion information, including: Call the target plug-in so that the target plug-in converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence, obtains the type conversion information, and converts the field and the content corresponding to the field into the field of the message and the content corresponding to the field, respectively, to obtain the field conversion information and content conversion information.
3. The method according to claim 2, characterized in that The calling target plug-in includes: Generate a target file identifiable by the target plug-in according to the field and the content, quantity and type of the field; In response to a plug-in selection operation, the target file is passed to the target plug-in.
4. The method according to claim 2, characterized in that: The method further comprises: If the field naming method of the class object is different from the field naming method corresponding to the message format, the converted fields of the class object are adjusted according to the naming method corresponding to the message format.
5. The method according to claim 2, characterized in that: The preset programming language includes the Java programming language, the class object includes a Java class object, and the message includes a Protobuf message; and converting the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence relationship includes: Determine the data type correspondence between the Protobuf message and the Java class object according to the Protobuf message format and the grammatical rules of the Java programming language; determine the target data type in the Protobuf message corresponding to the type of the field in the Java class object according to the data type correspondence; The type of the field in the Java class object is converted to a target data type corresponding to the Protobuf message as a data type adapted to the Protobuf message format.
6. The method according to claim 5, characterized in that The determining of a target data type in the Protobuf message corresponding to a type of a field in the Java class object includes: If the type of the field in the Java class object is a basic data type of the Java programming language or an encapsulation type corresponding to the basic data type, determining that the basic data type having the same data structure as the type of the field in the Protobuf message format is the target data type; If the type of the field in the Java class object is a class object type of the Java programming language, determining that the message body type in the Protobuf message format is the target data type; If the type of the field in the Java class object is a collection type in the Java programming language, determining that a collection type having the same data structure as the type of the field in the Protobuf message format is the target data type; If the type of the field in the Java class object is a string or character array type in the Java programming language, a data type having the same data structure as the type of the field in the Protobuf message format is determined as the target data type.
7. The method according to claim 6, characterized in that After determining that the set type having the same data structure as the type of the field in the Protobuf message format is the target data type, the method further includes: For each collection field element in the collection type field, according to the correspondence between the Protobuf message and the data type of the Java class object, the type corresponding to each collection field element is converted into a data type adapted to the Protobuf message format, and each collection field element and the content corresponding to each collection field element are respectively converted into each collection field element in the target data type and the content corresponding to each collection field element.
8. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: Calling the copy and paste manager to copy and paste the content conversion information and the type conversion information to the clipboard; In response to a pasting operation on the content conversion information and the type conversion information, the content conversion information and the type conversion information on the clipboard are pasted to a corresponding storage object to obtain the conversion target object.
9. A data processing device, characterized in that: include: a processor and a memory storing a computer program; The processor is configured to execute the computer program to: Obtaining an object to be converted; the object to be converted includes a message or a class object in a preset programming language program; According to the correspondence between the message and the data type of the class object, the field of the object to be converted, the content corresponding to the field, and the type corresponding to the field are converted to obtain content conversion information and type conversion information; Obtaining a conversion target object corresponding to the object to be converted according to the content conversion information and the type conversion information; Wherein, when the object to be converted includes a class object in the preset programming language program, the conversion target object includes the message; when the object to be converted includes the message, the conversion target object includes a class object in the preset programming language program; The object to be converted includes a class object in the preset programming language program, and the processor is further used to: parse the class object to obtain detailed information of the class object; the detailed information includes fields of the class object and contents corresponding to the fields and types corresponding to the fields; The detailed information of the class object also includes annotation information corresponding to the field, and the processor is further configured to: use the annotation information corresponding to the field of the class object as the annotation information corresponding to the corresponding field in the conversion target object.
10. A data processing device, characterized in that: include: An acquisition module, a first processing module and a second processing module; The acquisition module is used to acquire the object to be converted; the object to be converted includes a message or a class object in a preset programming language program; The first processing module is used to convert the fields of the object to be converted, the contents corresponding to the fields, and the types corresponding to the fields, respectively, to obtain content conversion information and type conversion information according to the corresponding relationship between the message and the data type of the class object; The second processing module is used to obtain a conversion target object corresponding to the object to be converted according to the content conversion information and the type conversion information; Wherein, when the object to be converted includes a class object in the preset programming language program, the conversion target object includes the message; when the object to be converted includes the message, the conversion target object includes a class object in the preset programming language program; The object to be converted includes a class object in the preset programming language program, and the first processing module is used to: parse the class object to obtain detailed information of the class object; the detailed information includes fields of the class object and contents corresponding to the fields and types corresponding to the fields; The detailed information of the class object also includes annotation information corresponding to the field, and the first processing module is further used to: use the annotation information corresponding to the field of the class object as the annotation information corresponding to the corresponding field in the conversion target object.
11. The device according to claim 10, characterized in that The first processing module converts the fields of the object to be converted, the contents corresponding to the fields, and the types corresponding to the fields, respectively, according to the corresponding relationship between the message and the data type of the class object, to obtain field conversion information, content conversion information, and type conversion information, for: Call the target plug-in so that the target plug-in converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence, obtains the type conversion information, and converts the field and the content corresponding to the field into the field of the message and the content corresponding to the field, respectively, to obtain the field conversion information and content conversion information.
12. The device according to claim 11, characterized in that The first processing module calls the target plug-in to: Generate a target file identifiable by the target plug-in according to the field and the content, quantity and type of the field; In response to a plug-in selection operation, the target file is passed to the target plug-in.
13. The device according to claim 11, characterized in that The first processing module is also used for: If the field naming method of the class object is different from the field naming method corresponding to the message format, the converted fields of the class object are adjusted according to the naming method corresponding to the message format.
14. The device according to claim 11, characterized in that The preset programming language includes the Java programming language, the class object includes the Java class object, and the message includes the Protobuf message; the first processing module converts the type corresponding to the field in the class object into a data type adapted to the message format of the message according to the data type correspondence, for: Determine the data type correspondence between the Protobuf message and the Java class object according to the Protobuf message format and the grammatical rules of the Java programming language; determine the target data type in the Protobuf message corresponding to the type of the field in the Java class object according to the data type correspondence; The type of the field in the Java class object is converted to a target data type corresponding to the Protobuf message as a data type adapted to the Protobuf message format.
15. The device according to claim 14, characterized in that The first processing module determines a target data type in the Protobuf message corresponding to the type of the field in the Java class object, for: If the type of the field in the Java class object is a basic data type of the Java programming language or an encapsulation type corresponding to the basic data type, determining that the basic data type having the same data structure as the type of the field in the Protobuf message format is the target data type; If the type of the field in the Java class object is a class object type of the Java programming language, determining that the message body type in the Protobuf message format is the target data type; If the type of the field in the Java class object is a collection type in the Java programming language, determining that a collection type having the same data structure as the type of the field in the Protobuf message format is the target data type; If the type of the field in the Java class object is a string or character array type in the Java programming language, a data type having the same data structure as the type of the field in the Protobuf message format is determined as the target data type.
16. The device according to claim 15, characterized in that After the first processing module determines that the set type having the same data structure as the type of the field in the Protobuf message format is the target data type, the first processing module is further configured to: For each collection field element in the collection type field, according to the correspondence between the Protobuf message and the data type of the Java class object, the type corresponding to each collection field element is converted into a data type adapted to the Protobuf message format, and each collection field element and the content corresponding to each collection field element are respectively converted into each collection field element in the target data type and the content corresponding to each collection field element.
17. The device according to any one of claims 10 to 16, characterized in that: The second processing module is also used for: Calling the copy and paste manager to copy and paste the content conversion information and the type conversion information to the clipboard; In response to a pasting operation on the content conversion information and the type conversion information, the content conversion information and the type conversion information on the clipboard are pasted to a corresponding storage object to obtain the conversion target object.
18. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of a data processing device, the data processing device is enabled to execute the data processing method according to any one of claims 1 to 8.
19. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the data processing method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Cross-platform data communication, cross-platform data processing method, device and system
CN109308224A
Data format conversion method and device
CN110941655A
Data processing method and device and storage medium
CN113391791A
Information remote synchronization method, terminal and system
WO2017107499A1
