Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. size_t cs_dynamic_data_nnbuf_get_required_alloc_size(size_t max_payload_size, size_t records_count);
  2. void* cs_dynamic_data_nnbuf_add_record(void* buf, size_t record_size);
  3. void cs_dynamic_data_nnbuf_finalize(void* buf, Source queue_type);
  4. size_t cs_dynamic_data_get_current_content_size(const void* buf);
  5.  
  6. payload_size = content_size = alloc_size - header_size
  7. //comment that payload_size contains dynamic record headers (sizes)
  8.  
  9. size_t s = cs_nnbuf_get_required_alloc_size(1000);
  10. void* buf = nn_alloc(s);
  11.  
  12. if (cs_dynamic_data_get_current_content_size(buf) + 500 < 1000) { // 0 -> true
  13.     void* rec = cs_dynamic_data_nnbuf_add_record(buf, 500);
  14.     memcpy(rec);
  15. } else {
  16.     cs_dynamic_data_nnbuf_finalize(buf, 0x8);
  17.     nn_send(&buf);
  18. }
  19.  
  20. if (cs_dynamic_data_get_current_content_size(buf) + 500 < 1000) { // 504 -> false
  21.     void* rec = cs_dynamic_data_nnbuf_add_record(buf, 500);
  22.     memcpy(rec);
  23. } else {
  24.     cs_dynamic_data_nnbuf_finalize(buf, 0x8);
  25.     nn_send(&buf);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement