Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Possible fix for #19 .
I do not have proficient understanding of the COBS protocol yet so it would be good if this is thoroughly reviewed.
I compared the Rust implementation with the C implementation from wikipedia and I saw that there is a similar process of an encode pointer double increment. However, this is only done if the algorithm is not finished yet, more explicitely when length is not 0.
In Rust, this is a bit more complicated. I figured that the state machine has to remember when there might be the possibility that the encoding process is done and the destination index does not need to be incremented anymore. I did this with a boolean flag for the encoder struct. If push is called again, then the index needs to be incremented, and this is done before it starts iterating over the data to be pushed.
I ran all the existing tests again and also added a new one for the issue case.