tinycbor icon indicating copy to clipboard operation
tinycbor copied to clipboard

add cbor_value_ptr_{text,byte}_string

Open petm-dec opened this issue 3 years ago • 3 comments

Add functions to directly obtain a pointer to the data of a text or byte string, without the need to copy.

Otherwise these are analogous to the corresponding copy functions.

petm-dec avatar Mar 16 '21 10:03 petm-dec

Zero-copy API is already implemented in https://github.com/intel/tinycbor/compare/dev...thiagomacieira:dev. I've just never published it because it doesn't work really well for microcontrollers.

Since I haven't got the necessary help from them for that in the last 3 years, I'm simply going to ignore them and publish the API as-is.

thiagomacieira avatar Mar 16 '21 17:03 thiagomacieira

Is there some way to help getting the new API merged?... What specifically doesn't work well for microcontrollers?

kalcutter avatar Mar 16 '21 19:03 kalcutter

The problem is that TinyCBOR requires a single buffer with all of your data in it. On many small OSes (I know Zephyr), memory allocation is preferably done in chunks of a fixed size, so if you want for example 200 bytes, you get two 120-byte chunks and form a linked-list with them.

The parsing API was meant to help fix that, but if you couple that with the string API, it gets messy. Suppose you have that 2x120-byte linked list and your string starts 5 bytes into the first one: how does the API return that information?

thiagomacieira avatar Mar 16 '21 19:03 thiagomacieira