Chapter 10. The codec framework

 

This chapter covers

  • An overview of decoders, encoders and codecs
  • Netty’s codec classes

Just as many standard architectural patterns are supported by dedicated frameworks, common data-processing patterns are often good candidates for targeted implementations, which can save developers considerable time and effort.

This certainly applies to the subject of this chapter: encoding and decoding, or the conversion of data from one protocol-specific format to another. These tasks are handled by components commonly called codecs. Netty provides components that simplify the creation of custom codecs for a broad range of protocols. For example, if you’re building a Netty-based mail server, you’ll find Netty’s codec support invaluable for implementing the POP3, IMAP, and SMTP protocols.

10.1. What is a codec?

Every network application has to define how raw bytes transferred between peers are to be parsed and converted to—and from—the target program’s data format. This conversion logic is handled by a codec, which consists of an encoder and a decoder, each of which transforms a stream of bytes from one format to another. What distinguishes them?

10.2. Decoders

10.3. Encoders

10.4. Abstract codec classes

10.5. Summary