Automatic generation tool and method for network layer module codes under CS framework
Technical Field
The invention belongs to the field of computer software development, and particularly relates to a tool and a method for automatically generating network layer module codes under a CS (computer system) framework.
Background
The Client/Server architecture, i.e., the Client/Server architecture, is a general software system architecture at present, and with the rapid development of computer technology, the architecture is widely applied to various software platforms at present. In the interaction between the client and the server, the development of a network communication layer is crucial. In actual development, a developer needs to write a communication layer code according to a network protocol, the process is time-consuming and labor-consuming, the development quality is not easy to control, and in the development of other similar systems, the development needs to be repeated, so that manpower and material resources are wasted.
Therefore, it is very necessary to provide a tool and a method for automatically generating network layer module codes under the CS architecture to overcome the above-mentioned drawbacks in the prior art.
Disclosure of Invention
The invention aims to provide a tool and a method for automatically generating network layer module codes under a CS (circuit switched) framework, aiming at the defects that the development process of the network communication layer codes is time-consuming and labor-consuming, the development intelligence is not easy to control, and similar systems are repeatedly developed to waste manpower and material resources, so as to solve the technical problems.
In order to achieve the purpose, the invention provides the following technical scheme:
a network layer module code automatic generation tool under CS architecture comprises a protocol file acquisition module, a name space acquisition module, an application terminal selection module and a network module code generation module;
the protocol file acquisition module is used for acquiring a system network protocol;
the system comprises a namespace obtaining module, a namespace obtaining module and a namespace obtaining module, wherein the namespace obtaining module is used for obtaining a namespace;
the application terminal selection module is used for selecting an application terminal, and the application terminal comprises a client terminal and a server terminal;
and the network module code generating module is used for generating a network module code according to the acquired system network protocol, the name space name and the selected application terminal.
Further, the system also comprises a compiling module and an exporting module;
the compiling module is used for compiling the generated network module codes to generate a network module dynamic link library;
and the export module is used for exporting the dynamic link library of the network module. The network module codes are compiled to generate a dynamic link library, and the dynamic link library can be used after being exported.
Furthermore, the network module code generation module comprises a name space analysis unit, a protocol file analysis unit, a network module code universal template unit, a directory creation unit, a network module resource file creation unit, a dependent library file copying unit and a network module code generation unit;
the name space analyzing unit is used for analyzing the name spaces and storing each level of analyzed name spaces into a name space structure;
the protocol file analyzing unit is used for analyzing the protocol file and storing the content of each analyzed functional module into a parameter set;
the network module code universal template unit is used for providing a network template code universal template to the network module code generating unit, and the network module code universal template comprises a network module resource file, a dependency library file and a replaceable variable;
the directory creating unit is used for creating directories of all levels according to the analyzed name space;
the network module resource file creating unit is used for creating a required network module resource file;
the dependent library file copying unit is used for copying the basic library file, the head file and the dependent library file required by the network module from the specified directory;
and the network module code generating unit is used for replacing replaceable variables in the universal template of the network module code with parameters in the parameter set analyzed by the protocol file and generating the network module code in the bottom directory of the name space. The tool of the invention can automatically analyze only by acquiring the name space and the system network protocol, create a directory under the analyzed name space, and replace variables in the universal template of the network module network template codes according to parameters in the analyzed system network protocol to generate the network module codes.
Further, the network module resource files comprise project files, resource files, pre-compiling header files, data definitions, API interface files, protocol parsing assembly files and basic library files, wherein the basic library files comprise TCP network files and Json protocol parsing files.
Further, the network module code generating unit comprises a data definition file generating subunit, an API interface file generating subunit, a function module file generating subunit and a network module code generating subunit;
the data definition file generation subunit is used for circularly reading the parameter set of the content of each functional module analyzed by the protocol file analysis unit, generating a structural body definition required by each functional module and storing the structural body definition in the data definition file;
the API interface file generation subunit is used for circularly reading the parameter set of each functional module analyzed by the protocol file analysis unit and generating an interface class of each functional module;
the functional module file generating subunit is used for circularly reading the parameter set of each functional module analyzed by the protocol file analyzing unit and generating the protocol data analysis and assembly class of each functional module;
and the network module code generation subunit is used for replacing the structure definition, the interface class and the protocol data analysis and organization class of each functional module with corresponding replaceable variables in the network module code universal template.
Further, the system network protocol adopts a Json format protocol.
Further, the namespace names support three levels of namespaces, with adjacent two levels of namespaces separated by separators.
The invention also provides the following technical scheme:
a method for automatically generating network layer module codes under a CS framework comprises the following steps:
s1, acquiring a name space;
s2, analyzing the name space, and storing each level of analyzed name space into a name space structure;
s3, acquiring a system network protocol;
s4, analyzing the protocol file, and storing the content of each analyzed functional module into a parameter set;
s5, selecting an application end, wherein the application end comprises a client and a server;
s6, generating a network module code according to the analyzed system network protocol, the name space name and the selected application end;
s7, compiling the generated network module codes to generate a network module dynamic link library;
s8, exporting a dynamic link library of the network module;
and S9, ending.
Further, in step S2, if the namespace analysis fails, the process proceeds to step S9;
in step S4, if the protocol file fails to be parsed, the process proceeds to step S9.
Further, the specific steps of step S6 are as follows:
s61, creating each level of directory according to the analyzed name space;
s62, creating a required network module resource file;
s63, copying basic library files, header files and dependent library files required by the network module from the specified directory;
and S64, replacing replaceable variables in the universal template of the network module codes with parameters in the parameter set analyzed by the protocol file, and generating the network module codes under the bottom-level directory of the name space.
Further, the specific steps of step S64 are as follows:
s641, circularly reading the parameter set of the content of each function module analyzed from the protocol file, generating a structural body definition required by each function module, and storing the structural body definition in a data definition file;
s642, circularly reading the parameter set of each function module analyzed from the protocol file to generate an interface class of each function module;
s643, circularly reading the parameter set of each analyzed functional module in the protocol file, and generating a protocol data analysis and assembly class of each functional module;
and S644, replacing the structural body definition, the interface class and the protocol data analysis and organization class of each functional module with corresponding replaceable variables in the network module code universal template.
The invention has the beneficial effects that:
the invention automatically generates the codes of the network modules of the client and the server according to the system network protocol, and the codes are exported to the project, and the codes can be directly compiled to generate the network modules and provide an API calling interface for the outside. The tool of the invention provides a visual operation interface, has good universality, high usability and easy maintenance, can generate a high-quality network module only by providing a standard network protocol, and is provided in the form of a dynamic link library.
In addition, the invention has reliable design principle, simple structure and very wide application prospect.
Therefore, compared with the prior art, the invention has prominent substantive features and remarkable progress, and the beneficial effects of the implementation are also obvious.
Drawings
FIG. 1 is a schematic diagram of an automatic generation tool for network layer module codes according to the present invention;
FIG. 2 is a schematic diagram of a network module code generation module according to the present invention;
FIG. 3 is a schematic view of a visualization interface of an automatic generation tool for network layer module codes according to the present invention;
FIG. 4 is a flow chart of a method of the present invention;
FIG. 5 shows the steps of the network module code generation of the present invention;
FIG. 6 illustrates a Json format system network protocol used in an embodiment;
wherein, 1-protocol file acquisition module; 2-a namespace acquisition module; 3-an application terminal selection module; 4-a network module code generation module; 4.1-namespace parsing unit; 4.2-protocol file parsing unit; 4.3-network module code universal template unit; 4.4-a catalog creation unit; 4.5-network module resource file creating unit; 4.6-dependent library file copy unit; 4.7-network module code generating unit; 4.7.1-data definition File Generation subunit; 4.7.2-API interface file generation subunit; 4.7.3-function module file generation subunit; 4.7.4-twine module code generating subunit; 5-a compiling module; 6-deriving module.
The specific implementation mode is as follows:
in order to make the objects, features and advantages of the present invention more obvious and understandable, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
Example 1:
as shown in fig. 1, the present invention provides an automatic generation tool for network layer module codes under a CS architecture, which includes a protocol file acquisition module 1, a namespace acquisition module 2, an application selection module 3, a network module code generation module 4, a compilation module 5, and an export module 6;
the protocol file acquisition module 1 is used for acquiring a system network protocol;
the name space obtaining module 2 is used for obtaining a name space;
the application terminal selection module 3 is used for selecting an application terminal, and the application terminal comprises a client terminal and a server terminal;
the network module code generating module 4 is used for generating a network module code according to the acquired system network protocol, the name space name and the selected application end;
the compiling module 5 is used for compiling the generated network module codes to generate a network module dynamic link library;
and the export module 6 is used for exporting the network module dynamic link library.
A visualization interface of the automatic generation tool of the network layer module code under the CS architecture in embodiment 1 is shown in fig. 3;
the system network protocol in the above embodiment 1 adopts the Json format protocol shown in fig. 6, and the network module code generation module 4 adopts the Doxygen annotation specification.
Example 2:
as shown in fig. 2, the network module code generating module 4 in the foregoing embodiment 1 includes a namespace parsing unit 4.1, a protocol file parsing unit 4.2, a network module code universal template unit 4.3, a directory creating unit 4.4, a network module resource file creating unit 4.5, a dependent library file copying unit 4.6, and a network module code generating unit 4.7;
the name space analyzing unit 4.1 is used for analyzing the name spaces and storing each level of analyzed name spaces into a name space structure;
the protocol file analyzing unit 4.2 is used for analyzing the protocol file and storing the content of each analyzed functional module into a parameter set;
the network module code universal template unit 4.3 is used for providing a network template code universal template to the network module code generating unit 4.7, and the network module code universal template comprises a network module resource file, a dependency library file and a replaceable variable;
a directory creating unit 4.4, configured to create directories at different levels according to the parsed name space;
a network module resource file creating unit 4.5, which is used for creating the required network module resource file;
a dependent library file copying unit 4.6, which is used for copying the basic library file, the head file and the dependent library file required by the network module from the specified directory;
the network module code generating unit 4.7 is used for replacing replaceable variables in the universal template of the network module code with parameters in a parameter set analyzed by the protocol file and generating the network module code in a bottom directory of a naming space; the network module code generating unit 4.7 comprises a data definition file generating sub-unit 4.7.1, an API interface file generating sub-unit 4.7.2, a function module file generating sub-unit 4.7.3 and a network module code generating sub-unit 4.7.4;
a data definition file generating subunit 4.7.1, configured to cyclically read the parameter set of the content of each functional module analyzed by the protocol file analyzing unit 4.2, generate a structure definition required by each functional module, and store the structure definition in the data definition file;
an API interface file generating subunit 4.7.2, configured to cyclically read the parameter set of each functional module analyzed by the protocol file analyzing unit 4.2, and generate an interface class of each functional module;
a functional module file generating subunit 4.7.3, configured to circularly read the parameter set of each functional module analyzed by the protocol file analyzing unit 4.2, and generate a protocol data analysis and assembly class of each functional module;
and the network module code generating subunit 4.7.4 is used for replacing the structure definition, the interface class and the protocol data analysis and the organization class of each functional module with corresponding replaceable variables in the network module code universal template.
The name space name in the above embodiment 2 supports three levels of name spaces, two adjacent levels of name spaces are separated by a separator ". times", and the name space resolution unit 4.1 distinguishes the name spaces of each level by the separator ". times".
Generating a network layer module code by applying the embodiment 2, compiling a standard Json protocol shown in the figure 6 according to format requirements, and storing the code as a txt text file after the compiling is finished, wherein the file name is named by an English project name;
opening the automatic tool of network layer module codes under the CS framework, as shown in figure 3, clicking to select and browse, and finding out the saved txt file;
inputting a name space to be generated in a name space input box, wherein at most 3 levels of name spaces are supported;
selecting a client to click and generate a client network module code;
selecting a server side to click and generate a server side network module code;
and opening the client network module code or the server network module code, and compiling to generate a dynamic link library of the available network communication module.
Example 3:
as shown in fig. 4, the present invention provides a method for automatically generating a network layer module code under a CS architecture, which includes the following steps:
s1, acquiring a name space;
s2, analyzing a name space;
if the namespace analysis fails, go to step S9;
if the name space is successfully analyzed, storing each level of analyzed name space into a name space structure;
s3, acquiring a system network protocol;
s4, analyzing the protocol file;
if the protocol file fails to be analyzed, the process goes to step S9;
if the protocol file is successfully analyzed, the content of each analyzed functional module is stored in a parameter set;
s5, selecting an application end, wherein the application end comprises a client and a server;
s6, generating a network module code according to the analyzed system network protocol, the name space name and the selected application end;
s7, compiling the generated network module codes to generate a network module dynamic link library;
s8, exporting a dynamic link library of the network module;
and S9, ending.
As shown in fig. 5, the specific steps of step S6 in embodiment 3 are as follows:
s61, creating each level of directory according to the analyzed name space;
s62, creating a required network module resource file;
s63, copying basic library files, header files and dependent library files required by the network module from the specified directory;
s64, replacing replaceable variables in a universal template of network module codes with parameters in a parameter set analyzed by the protocol file, and generating network module codes under a bottom directory of a name space; the specific steps of step S64 are as follows:
s641, circularly reading the parameter set of the content of each function module analyzed from the protocol file, generating a structural body definition required by each function module, and storing the structural body definition in a data definition file;
s642, circularly reading the parameter set of each function module analyzed from the protocol file to generate an interface class of each function module;
s643, circularly reading the parameter set of each analyzed functional module in the protocol file, and generating a protocol data analysis and assembly class of each functional module;
and S644, replacing the structural body definition, the interface class and the protocol data analysis and organization class of each functional module with corresponding replaceable variables in the network module code universal template.
Example 4:
the embodiments of the present invention are illustrative rather than restrictive, and the above-mentioned embodiments are only provided to help understanding of the present invention, so that the present invention is not limited to the embodiments described in the detailed description, and other embodiments derived from the technical solutions of the present invention by those skilled in the art also belong to the protection scope of the present invention.