跨平台和语言(反)序列化 [英] Cross-platform and language (de)serialization

查看:101
本文介绍了跨平台和语言(反)序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种以最便捷的方式对一堆C ++结构进行序列化的方法,以使该序列化可在C ++和Java(至少)以及32位/64位,大/小端序平台之间移植.要序列化的结构仅包含数据,即它们是没有状态或行为的纯数据对象.

I'm looking for a way to serialize a bunch of C++ structs in the most convenient way so that the serialization is portable across C++ and Java (at a minimum) and across 32bit/64bit, big/little endian platforms. The structures to be serialized just contain data, i.e. they're pure data objects with no state or behavior.

这样的想法是,我们将结构序列化为一个八位位组blob,然后可以一般"地将其存储在数据库中,并在以后读取.因此,避免了每当结构改变时就更改数据库,并且避免将每个数据成员分配给一个字段-也就是说,我们只希望一个表一般"地将所有内容保存为二进制blob.这样一来,开发人员的工作量就会减少,并且在结构更改时所需的更改也将更少.

The idea being that we serialize the structs into an octet blob that we can store in a database "generically" and be read out later on. Thus avoiding changing the database whenever a struct changes and also avoiding assigning each data member to a field - i.e. we only want one table to hold everything "generically" as a binary blob. This should make less work for developers and require less changes when structures change.

我看过boost.serialize,但是认为没有一种方法可以实现与Java的兼容性.同样,对于继承Java中的Serializable.

I've looked at boost.serialize but don't think there's a way to enable compatibility with Java. And likewise for inheriting Serializable in Java.

如果有一种方法可以从最好的IDL文件开始,因为我们已经有描述结构的IDL文件.

If there is a way to do it by starting with an IDL file that would be best as we already have IDL files that describe the structures.

提前加油!

推荐答案

如果我想真正使用跨语言,通常我会建议使用JSON,因为它易于使用JavaScript并支持协议缓冲区 thrift 在那里将具有优势(可以通过IDL进行节约,但也可以将其用于编码服务,因此它可能比您想要的要重.)

If I want to go really really cross language, I normally would suggest JSON, as the ease of javascript support and an abundance of libraries, as well as being human readable and modifiable (I prefer it to XML as I find it smaller in terms of chars, faster, and more readable). It's not the most efficient in terms of space, however, and a more machine readable format like protocol buffers or thrift would have advantages there (thrift can be made from an IDL, but it is also made for encoding services, so it could be heavier than you want).

这篇关于跨平台和语言(反)序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆