Chapter 5. Serializing data with protocols

 

This chapter covers

  • Understanding the Apache Thrift serialization protocol layer
  • Serializing language-based types
  • Programming with the Apache Thrift Binary, Compact, and JSON protocols
  • Selecting the most appropriate protocol for an application

In chapter 4, the Transport chapter, we saw how the Apache Thrift transport layer provides a byte-level interface used to perform I/O against a range of physical and logical devices. We also noted that different languages typically produce different representations of data when built-in serialization is used. To communicate across languages, we need a layer to create standard serialized representations for data. Apache Thrift protocols (see figure 5.1) provide this functionality.

Figure 5.1. The Apache Thrift protocol layer

Protocols create and consume a single, central representation of logically equivalent structures across languages. Using Apache Thrift protocols, a C++ object can be serialized into a common format, sent to a Ruby program, and reconstituted as a Ruby object (see figure 5.2). Protocols also support communications between dissimilar hardware platforms where byte ordering, padding, and pointer width may vary. For example, Apache Thrift supports communicating between 32-bit and 64-bit C++ applications without incompatibilities. The Apache Thrift protocols standardize the representation of serialized objects independent of language, operating system, or hardware platform.

5.1. Basic serialization with the binary protocol

5.2. The TProtocol interface

5.3. Serializing objects

5.4. TCompactProtocol

5.5. TJSONProtocol

5.6. Selecting a protocol

Summary

sitemap