Hi folks,
I started to retrofit the codec framework with the new API at 'next-api'
branch, and it seems to work as expected so far. Please feel free to
review it and let me know what you think:
-
http://j.mp/JvGUwx
Notable changes are:
- FrameDecoder is now StreamToMessageDecoder
- Codecs are type-safe
- Because the new API has two different types of buffers
(message buffer and byte buffer aka stream), there are
6 combinations of abstract codecs:
- MessageToMessageDecoder (replaces OneToOneDecoder)
- MessageToMessageEncoder (replaces OneToOneEncoder)
- StreamToMessageDecoder (replaces FrameDecoder)
- MessageToStreamEncoder
- StreamToStreamEncoder
- StreamToStreamDecoder
You will find how these abstract codecs are used at:
- All decoders and length prependers at the codec package
- All codecs in base64, bytes, compression, protobuf
Typical pipeline that encodes and decodes a string with its length
header would look like:
1) LengthFieldBasedFrameDecoder decodes stream into ChannelBuffer
2) StringDecoder decodes ChannelBuffer into String
3) LengthFieldPrepender encodes ChannelBuffer into stream
4) StringEncoder encodes String into ChannelBuffer
To add ZLIB compression:
-2) ZlibDecoder decodes stream into stream
-1) ZlibEncoder encodes stream into stream
1) LengthFieldBasedFrameDecoder decodes stream into ChannelBuffer
2) StringDecoder decodes ChannelBuffer into String
3) LengthFieldPrepender encodes ChannelBuffer into stream
4) StringEncoder encodes String into ChannelBuffer
If a user cares more about performance, he or she can write a new codec
that combined 1 and 2 (or 3 and 4) to reduce memory copy dramatically,
which was not possible in Netty 3.
I'll ping you guys again if a major change is made in the codec
framework. So far, it looks pretty solid in my opinion.
Cheers,
T
--
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project