laurencelundblade / QCBOR

Comprehensive, powerful, commercial-quality CBOR encoder/ decoder that is still suited for small devices.
Other
181 stars 47 forks source link

Valid cursor at end-of-input results in same Tell output as error state #230

Closed BrianSipos closed 1 month ago

BrianSipos commented 3 months ago

I appreciate the quick changes made in #223 to provide visibility into the internal cursor.

The current API, which is accurately documented in the header below, makes it impossible to distinguish between the error state and a valid cursor positioned at the end-of-input.

https://github.com/laurencelundblade/QCBOR/blob/b239c65376fbc502587df88e47629fa667c721c7/inc/qcbor/qcbor_decode.h#L1054-L1056

In my use of this function, I need to undo the following conversion logic and requires an additional call into UsefulInputBuf_GetBufferLength(). It seems to me that this logic is not really necessary and is not as efficient as simply not including this block (and updating the documentation appropriately). The reason is that a cursor at the end-of-input is perfectly valid situation to be in, and if a user application cares about this condition it can detect it as it needs to.

https://github.com/laurencelundblade/QCBOR/blob/b239c65376fbc502587df88e47629fa667c721c7/src/qcbor_decode.c#L3167-L3172

laurencelundblade commented 3 months ago

Understand your request and kind of thought about that in the back of my mind when I made the change. Thinking about it...