Rewrite encoder to remove the need for counts and lengths.