MGen跨语言对象序列化
MGen 是一个支持跨语言的对象序列化项目,由以下两部分组成:
源码生成的工具 ( MGen 编译器 )
语言的支持库
MGen 类似 Gooogle 的 Protocol Buffers ,可序列化到 JSON 和二进制格式。
目前支持的语言有:
C++
Java
JavaScript
示例代码:
#include <com/fruitcompany/ClassRegistry.h> #include <mgen/serialization/JsonPrettyWriter.h> #include <mgen/serialization/JsonReader.h> using namespace mgen; using namespace com::fruitcompany; using namespace com::fruitcompany::fruits; // A class registry for type identification const ClassRegistry registry; std::string toJSON(const MGenBase& object) { // Create a target to stream the object to std::stringstream stream; // Create a writer object JsonPrettyWriter<std::stringstream, ClassRegistry> writer(stream, registry); // Write the object writer.writeObject(object); // Return the written string return stream.str(); } template <typename T> T fromJSON(const std::string& json) { // Create a data source to stream objects from std::stringstream stream(json); // Create a reader object JsonReader<std::stringstream, ClassRegistry> reader(stream, registry); // Read object. You can read T* polymorphicly with reader.readObject<T>() return reader.readStatic<T>(); } int main() { // Create some objects const Apple apple(Brand_A, 4); const Banana banana = Banana().setLength(5).setBrand(Brand_B); // Serialize them to JSON and print them std::cout << toJSON(banana) << std::endl; std::cout << toJSON(apple) << std::endl; // Read the objects back from their serialized form const Apple appleBack = fromJSON<Apple>(toJSON(apple)); const Banana bananaBack = fromJSON<Banana>(toJSON(banana)); // Check that they are still the same std::cout << (apple == appleBack) << std::endl; std::cout << (banana == bananaBack) << std::endl; return 0; }
评论
KryoJava对象序列化框架
Kryo是一个快速高效的Java对象图形序列化框架,主要特点是性能、高效和易用。该项目用来序列化对象到文件、数据库或者网络。示例代码:Kryo kryo = new Kryo();// ...Outp
KryoJava对象序列化框架
0
XsonJava对象序列化和反序列化工具
Xson是一个Java对象序列化和反序列化程序。支持Java对象到字节数组的序列化,和从字节数组到Java对象的反序列化。Maven:<dependency> <groupId
XsonJava对象序列化和反序列化工具
0
Hprose for Ruby高性能的跨语言序列化与RPC引擎
Hprose 是高性能远程对象服务引擎(High Performance Remote Object
Hprose for Ruby高性能的跨语言序列化与RPC引擎
0
Hprose for Node.js高性能的跨语言序列化与RPC引擎
Hprose 是高性能远程对象服务引擎(HighPerformanceRemoteObjectServiceEngine)的缩写。它是一个先进的轻量级的跨语言跨平台面向对象的高性能远程动态通讯中间件。
Hprose for Node.js高性能的跨语言序列化与RPC引擎
0
Hprose for .NET高性能的跨语言序列化与RPC引擎
Hprose 是高性能远程对象服务引擎(HighPerformanceRemoteObjectServiceEngine)的缩写。它是一个先进的轻量级的跨语言跨平台面向对象的高性能远程动态通讯中间件。
Hprose for .NET高性能的跨语言序列化与RPC引擎
0