Revert "encode: make the central lock recursive"

This reverts commit 231c6672140f019257edd26db20fbcfc2554258f.
encode: get rid of the recursion that led to a deadlock.

Instead, the recursive call has been flattened away by instead
overwriting a parameter and continuing.