mfreadwrite: Implement encoder creation. (Part 1)
I split the implementations into 2 parts to make it looks easier to review. So plz first review this MR and make sure it's good so that we don't have to rebase. The follwing patches is in !7571.
Edited by Ziqing Hui