Closed lygstate closed 4 years ago
I don't think that's possible without allocation unless the writer is guaranteed to be able to seek backwards, since the count comes before the data in the format.
limit the stack depth, then would be possible, such as 1024
This is an interesting idea, but like @catwell said we'd either have to allocate or put a buffer on the context, and I'd rather not.
I have been toying w/ the idea of writing a buffer on top of CMP for situations like this. CMP pushes all the bookkeeping into applications, which is by design but also tedious. I don't get a ton of time to work on CMP-related stuff but, it might materialize.
bool cmp_write_map16_begin(cmp_ctx_t ctx); bool cmp_write_map32_begin(cmp_ctx_t ctx); bool cmp_write_map_end(cmp_ctx_t *ctx);
bool cmp_write_array16_begin(cmp_ctx_t ctx); bool cmp_write_array32_begin(cmp_ctx_t ctx); bool cmp_write_array_end(cmp_ctx_t *ctx);
And we use stack to track how much number of elements that map16 、 map32 、array16、array32 are written.