I think that you should Assert before encoding - it may not be relevant but it's healthier