Squashed merge from writenal_refactor2
Merge pull request #325 from sijchen/writenal_refactor3

add encoder error code and refactor WelsWriteNal