Closed nwoods closed 3 years ago
Edit: Factored implementations into separate functions to avoid unnecessary decode-encode during encoding retry when buffer is too small, and to avoid changing the interface of functions that should respect the codec API.
This is my first time working on an implementation of the codec API so please be patient if I did anything stupid.
Changes:
msg
is bytes, index returned by error can be used unmodified).errors='ignore'
orerrors='replace'
, remove the offending byte before retrying.When the buffer is too small, I increase it by 10% (min 3 bytes). I chose those numbers based on nothing whatsoever, and I'm open to other suggestions.
The unit tests succeed, and this works for my use cases plus some others I fiddled around with, but I wouldn't say it has been tested extensively.