Guest User

Untitled

a guest
Jul 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. int bert_decoder_pull(bert_decoder_t *decoder,size_t size)
  2. {
  3. size_t remaining_space = (decoder->short_length - decoder->short_index);
  4.  
  5. if (size <= remaining_space)
  6. {
  7. // we still have enough data in the short buffer
  8. return BERT_SUCCESS;
  9. }
  10.  
  11. size_t empty_space = BERT_DECODER_EMPTY(decoder);
  12.  
  13. if (empty_space >= (BERT_SHORT_BUFFER / 2))
  14. {
  15. // fill the remaining space in the short buffer
  16. goto fill_short_buffer;
  17. }
  18.  
  19. size_t unread_space = (decoder->short_length - decoder->short_index);
  20.  
  21. if (unread_space)
  22. {
  23. // shift the other half of the short buffer down
  24. memcpy(decoder->short_buffer,decoder->short_buffer+decoder->short_index,sizeof(unsigned char)*unread_space);
  25. }
  26.  
  27. decoder->short_length = unread_space;
  28. decoder->short_index = 0;
  29. empty_space = BERT_DECODER_EMPTY(decoder);
  30.  
  31. ssize_t length;
  32.  
  33. fill_short_buffer:
  34. length = bert_buffer_read(decoder->short_buffer+decoder->short_length,&(decoder->buffer),empty_space);
  35.  
  36. decoder->short_length += length;
  37.  
  38. if ((decoder->short_length - decoder->short_index) < size)
  39. {
  40. return BERT_ERRNO_EMPTY;
  41. }
  42. return BERT_SUCCESS;
  43. }
Add Comment
Please, Sign In to add comment