Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- size_t cs_dynamic_data_nnbuf_get_required_alloc_size(size_t max_payload_size, size_t records_count);
- void* cs_dynamic_data_nnbuf_add_record(void* buf, size_t record_size);
- void cs_dynamic_data_nnbuf_finalize(void* buf, Source queue_type);
- size_t cs_dynamic_data_get_current_content_size(const void* buf);
- payload_size = content_size = alloc_size - header_size
- // comment that payload_size contains dynamic record headers (sizes)
- // client is required to keep track of written data to prevent overflow
- // cs_nnbuf_get_required_alloc_size is interchangeable with cs_dynamic_data_nnbuf_get_required_alloc_size -
- // just use the second one when number of dynamic records is known
- size_t s = cs_nnbuf_get_required_alloc_size(1000);
- void* buf = nn_alloc(s);
- if (cs_dynamic_data_get_current_content_size(buf) + 500 < 1000) { // 0 -> true
- void* rec = cs_dynamic_data_nnbuf_add_record(buf, 500);
- memcpy(rec);
- } else {
- cs_dynamic_data_nnbuf_finalize(buf, 0x8);
- nn_send(&buf);
- }
- if (cs_dynamic_data_get_current_content_size(buf) + 500 < 1000) { // 504 -> false
- void* rec = cs_dynamic_data_nnbuf_add_record(buf, 500);
- memcpy(rec);
- } else {
- cs_dynamic_data_nnbuf_finalize(buf, 0x8);
- nn_send(&buf);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement