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.
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.