cobs.rs icon indicating copy to clipboard operation
cobs.rs copied to clipboard

Possible encoder bugfix

Open robamu opened this issue 2 years ago • 2 comments

Possible fix for https://github.com/jamesmunns/cobs.rs/issues/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.

robamu avatar Jan 02 '23 17:01 robamu

Any updates on this?

robamu avatar Jul 11 '23 21:07 robamu

Any chance this could get checked and possibly merged? I'd love to use the upstream again :)

robamu avatar Apr 17 '24 13:04 robamu