You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Examine whether the code supports in-place encoding and/or decoding. That is, output is written to the input buffer, overwriting the original input. It could be useful to save RAM in small embedded systems.
My guess is that in-place decoding should work as-is
In-place encoding should work I think, however the input would have to be offset from the start of the output buffer by a certain number of bytes. In the code, see COBS_ENCODE_SRC_OFFSET() and COBSR_ENCODE_SRC_OFFSET() which calculate the required offset, for a given data size.
I was looking through this just now for cobs_decode and I do believe that cobs_decode at least should be ok - every increment of src_read_ptr is followed by at most 1 increment of dst_write_ptr, so it should never be possible for the write pointer to get ahead of the read pointer. The only case where they are unmatched is when decoding a 0xff byte, in which case the src pointer gets ahead by one byte.
I have been using the library on a new project and I can say that in place encode works if put the data on the buffer with and offset of 1. The header is populated properly and there is no issues.
For decode case it works without issues with no offset.
My project had a union that had a buffer and also a structure that contained information on the packets (cobs header, length crc etc) and if I tried to do in place using the structure and used an offset of 1 on the output, you get a zero in input error because the src pointer points to the decoded 0 present on the next step. So for a generic array it works, with a dedicated structure more work needs to be performed, or a copy needs to be made.
I have been using the library on a new project and I can say that in place encode works if put the data on the buffer with and offset of 1.
An offset of 1 is fine if the data size is less than 255 bytes.
But, for larger data sizes, the offset needs to be bigger. In the code, see COBS_ENCODE_SRC_OFFSET() and COBSR_ENCODE_SRC_OFFSET() which calculate the required offset, for a given data size.
Originally reported by: Craig McQueen (Bitbucket: cmcqueen1975, GitHub: @cmcqueen)
Examine whether the code supports in-place encoding and/or decoding. That is, output is written to the input buffer, overwriting the original input. It could be useful to save RAM in small embedded systems.
COBS_ENCODE_SRC_OFFSET()
andCOBSR_ENCODE_SRC_OFFSET()
which calculate the required offset, for a given data size.Once this has been checked:
The text was updated successfully, but these errors were encountered: