摘要
本文主要通过一款用C++开发的协议生成工具来说明代码生成技术在网络通信中的应用。该工具通过读取固定格式的模板文件生成可以用C++编译器编译的源文件和头文件,这些源文件和头文件通过编译后,可以进行序列化和反序列化。然而,把程序中的数据结构按照自定义协议进行传输,就需要序列化,反之,把网络传输过来的数据用于程序中的数据结构就需要反序列化。本文提及的工具正是从实际应用角度出发,通过工具生成代码,然后将代码编译应用到网络通信自定义协议的序列化和反序列化,最终实现网络通信。这样一套流程充分证明了代码生成技术是可以应用在网络通信中,具有重要的现实意义。
This paper describes the application of code generation technology in network communication through a protocol generation tool developed with C++.The tool can generate source files and header files that can be compiled by C++compiler by reading template files in fixed format.These source files and header files can be serialized and deserialized after being compiled.However,if the data structure in the program is transmitted according to the custom protocol,it needs to be serialized.On the contrary,if the data transferred from the network is used for the data structure in the program,it needs to be deserialized.The tool mentioned in this paper is just from the perspective of practical application.Code is generated by the tool,and then the code compilation is applied to the serialization and deserialization of network communication custom protocol,and finally network communication is realized.Such a set of process fully proves that code generation technology can be applied in network communication and has important practical significance.
作者
朱彬
Zhu Bin(The Third Research Institute of the Ministry of Public Security,Shanghai 200000,China)
出处
《信息与电脑》
2020年第13期176-178,共3页
Information & Computer