MGen 跨语言对象序列化开源项目

我要开发同款
匿名用户2014年12月21日
50阅读

技术信息

开源地址
https://github.com/berdario/pew
授权协议
MIT

作品详情

MGe是一个支持跨语言的对象序列化项目,由以下两部分组成:

源码生成的工具(MGe编译器)

语言的支持库

MGe类似Gooogle的ProtocolBuffers,可序列化到JSON和二进制格式。

目前支持的语言有:

C++

Java

JavaScript

示例代码:

#iclude <com/fruitcompay/ClassRegistry.h>#iclude <mge/serializatio/JsoPrettyWriter.h>#iclude <mge/serializatio/JsoReader.h>usig amespace mge;usig amespace com::fruitcompay;usig amespace com::fruitcompay::fruits;// A class registry for type idetificatiocost ClassRegistry registry;std::strig toJSON(cost MGeBase& object) {  // Create a target to stream the object to  std::strigstream stream;  // Create a writer object  JsoPrettyWriter<std::strigstream, ClassRegistry> writer(stream, registry);  // Write the object  writer.writeObject(object);  // Retur the writte strig  retur stream.str();}template <typeame T>T fromJSON(cost std::strig& jso) {  // Create a data source to stream objects from  std::strigstream stream(jso);  // Create a reader object  JsoReader<std::strigstream, ClassRegistry> reader(stream, registry);  // Read object. You ca read T* polymorphicly with reader.readObject<T>()  retur reader.readStatic<T>();}it mai() {  // Create some objects  cost Apple apple(Brad_A, 4);  cost Baaa baaa = Baaa().setLegth(5).setBrad(Brad_B);  // Serialize them to JSON ad prit them  std::cout << toJSON(baaa) << std::edl;  std::cout << toJSON(apple) << std::edl;  // Read the objects back from their serialized form  cost Apple appleBack = fromJSON<Apple>(toJSON(apple));  cost Baaa baaaBack = fromJSON<Baaa>(toJSON(baaa));  // Check that they are still the same  std::cout << (apple == appleBack) << std::edl;  std::cout << (baaa == baaaBack) << std::edl;  retur 0;}

功能介绍

MGen 是一个支持跨语言的对象序列化项目,由以下两部分组成: 源码生成的工具 ( MGen 编译器 ) 语言的支持库 MGen 类似 Gooogle 的 Protocol Buffers ,可...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论