Simplify encoder message caching.

Instead of keeping a separate message cache vector and a temporary
buffer for every encoding operation, just dump everything in this buffer
and flush it when it's possible.