B-Human CodeRelease2013-Chapter3翻译

Chapter 3
3.4 Serialization
In most applications, it is necessary that data can be serialized, i. e. transformed into a sequence of bytes. While this is straightforward for data structures that already consist of a single block of memory, it is a more complex task for dynamic structures, e. g. lists, trees, or graphs. Our implementation for streaming data follows the ideas introduced by the C++ iostreams library, i. e., the operators << and >> are used to implement the process of serialization. In contrast to the iostreams library, our implementation guarantees that data is streamed in a way that it can be read back without any special handling, even when streaming into and from text files, i. e. the user of a stream does not need to know about the representation that is used for the serialized data (cf. Sect. 3.4.1).
大多数的应用程序都要对数据进行串行化,例如将数据转化成字节队列。虽然这对于内部已经包含单独的内存块的数据结构来说很简单,但是对于像列表、树或者图这样的动态结构就很复杂。我们处理数据流的方法遵从了C++输入输出流库体现的思想,比如,用操作符“<<”和“>>”表示串行化过程。不过与输入输出流库不同,我们的实现方式使得串行化的数据即便是读写文本文件的情况下也不需要特殊操作就可以被读回。比如,串行化的使用者不需要了解用来序列化数据的表征(Repre)。
On top of the basic streaming class hierarchy, it is also possible to derive classes from class Streamable and implement the mandatory method serialize(In*, Out*).
在基本流类的顶层部分,从Streamable类继承出类和实现强制的串行化方法(输入和输出)也行可行的。
In addition, the basic concept of streaming data was extended by a mechanism to gather information on the structure of the data while serializing it. This information is used to translate between the data in binary form and a human-readable format that reflects the hierarchy of a data structure, its variables, and their actual values.

As a third layer of serialization, two macros allow defining classes that automatically implement the method serialize(In*, Out*).

3.4.1 Streams
The foundation of B-Human’s implementation of serialization is a hierarchy of streams. As a convention, all classes that write data into a stream have a name starting with \Out”, while classes that read data from a stream start with \In”. In fact, all writing classes are derived from the class Out, and all reading classes are derivations of the class In. All classes support reading or writing basic datatypes with the exceptions of long, unsigned long, and size t, because their binary representations have different sizes on currently used platforms (32/64 bits). They also provide the ability to read or write raw binary data.
B-Human实现串行化的基础是一个流层。。。根据一般约定,所有将数据写入流的类的类名都以“Out”开头,而所有从流读数据的类的类名都以“In”开头。实际上,所有的写入类都是“Out”类的子类,所有读出类都是“In”类的子类。所有类都支持读写基本的数据类型,除了long 、unsigned long 和 size_t,因为它们的二进制表示在现在使用的平台上有不同的大小。所有的类也提供了读写原始二进制数据的能力。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值