数据与计算发展前沿 ›› 2020, Vol. 2 ›› Issue (4): 155-164.doi: 10.11871/jfdc.issn.2096-742X.2020.04.013

• 技术与应用 • 上一篇    

一种Protobuf到JSON动态转换方法

田丹1(),张金杰2,3,*(),李翀2,3(),曲艳华4,焦昊4   

  1. 1.中国中钢集团有限公司,北京 100180
    2.中国科学院计算机网络信息中心,北京 100190
    3.中国科学院大学,北京 100049
    4.战略支援部队航天系统部,北京 100094
  • 收稿日期:2020-07-06 出版日期:2020-08-20 发布日期:2020-09-10
  • 通讯作者: 张金杰
  • 作者简介:田丹,中国中钢集团公司,资深信息化主管,主要工作内容为企业信息化,有丰富的信息化规划建设经验,研究领域为Web技术和数据挖掘、数据融合。
    本文主要承担总体设计、技术调研及相关部分撰写。
    Tian Dan is a senior Information Supervisor of Sinosteel Corporation. She is interested in the research fields of web technology, data mining, and data fusion.
    In this paper, she is mainly responsible for the overall approach design and technical investigation.
    E-mail: 45443620@qq.com|张金杰,中国科学院计算机网络信息中心,硕士研究生,主要研究方向为管理大数据、推荐技术、高级软件体系结构等。
    本文主要承担工作为算法实现。
    Zhang Jinjie is a master student at Computer Network Information Center, Chinese Academy of Sciences. His main research interests are big data management, recommendation technology, advanced software architecture, etc.
    In this paper, he is mainly responsible for the realization of the algorithms.
    E-mail: zhangjinjie1996@163.com|李翀,中国科学院计算机网络信息中心,高级工程师,中国计算机学会高级会员,主要研究方向为管理大数据、推荐技术、高级软件体系结构等。以第一作者及通讯作者发表论文20余篇。
    本文主要承担工作为实验分析。
    Li Chong is a senior engineer at the Computer Network Information Center, Chinese Academy of Sciences. He is also a senior member of the Chinese computer society. His main research interests include big data management, recommendation technology, and advanced software architecture.
    In this paper, he is mainly responsible for the experimental analysis.
    E-mail: lichong@cnic.cn

A Dynamic Conversion Method from Protobuf to JSON

Tian Dan1(),Zhang Jinjie2,3,*(),Li Chong2,3(),Qu Yanhua4,Jiao Hao4   

  1. 1. Sinosteel Group Corporation Limited, Beijing 100180, China
    2. Computer Network Information Center, Chinese Academy of Sciences, Beijing 100190, China
    3. University of Chinese Academy of Sciences, Beijing 100049, China
    4. Strategic Support Force Space Systems Division, Beijing 100094, China
  • Received:2020-07-06 Online:2020-08-20 Published:2020-09-10
  • Contact: Zhang Jinjie

摘要:

【背景】Protobuf和JSON是目前两种主流网络数据结构,有着各自的特点和应用场景,随着互联网应用的场景复杂,不同场景下数据交换上有了新的要求。JSON主要应用于Web浏览器到服务器数据传输,Protobuf主要用于客户端到服务器端高效安全数据传输。【目的】若能实现两者的转换,可以促进数据交互,极大地提高开发效率。【方法】本文基于动态解析和类型反射技术,实现了Protobuf和JSON数据动态转换,并搭建测试平台和编写测试用例进行了验证。【结果】实验表明,该方法可靠稳定兼容性好,在测试用例不同测试数据下转换效率保持20MB/s,Protobuf 2和Protobuf 3均可正常转换。

关键词: Protobuf, JSON, 转换, 动态解析, 类型反射

Abstract:

[Background] Two mainstream network data structures, Protobuf and JSON, have their own characteristics and application scenarios. With the growing complexity of network applications, data exchanges under different scenarios are required. In traditional, JSON is mainly used for data transmission from the Web browser to the server, while Protobuf is mainly for efficient and safe data transmission from clients to servers. [Objective] Thus, if the data format of JSON and Protobuf exchange can be achieved, it will promote data interactions and greatly improve development efficiency. [Methods] This article implements the dynamic data conversion method to convert Protobuf data to JSON format based on dynamic parsing and type reflection technologies. Besides, a test platform with multiple test cases for verifications has been built. [Results] Experiments show the proposed method is reliable and stable with good compatibility. The conversion capacity maintains at 20MB/s under different test data of the test cases for both Protobuf 2 and Protobuf 3.

Key words: Protobuf, JSON, conversion, dynamic analysis, type reflection