[Encode] Implement error handling into metadata buffer

- adding error handling for next platform
- added mi flush command to make sure all commands are finished
6 files changed