camgunz / cmp

An implementation of the MessagePack serialization format in C / msgpack.org[C]
http://msgpack.org
MIT License
340 stars 78 forks source link

Add 6 api about array & map write #49

Closed lygstate closed 4 years ago

lygstate commented 5 years ago

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.

catwell commented 5 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.

lygstate commented 5 years ago

limit the stack depth, then would be possible, such as 1024

camgunz commented 4 years ago

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.