Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int bert_decoder_pull(bert_decoder_t *decoder,size_t size)
- {
- size_t remaining_space = (decoder->short_length - decoder->short_index);
- if (size <= remaining_space)
- {
- // we still have enough data in the short buffer
- return BERT_SUCCESS;
- }
- size_t empty_space = BERT_DECODER_EMPTY(decoder);
- if (empty_space >= (BERT_SHORT_BUFFER / 2))
- {
- // fill the remaining space in the short buffer
- goto fill_short_buffer;
- }
- size_t unread_space = (decoder->short_length - decoder->short_index);
- if (unread_space)
- {
- // shift the other half of the short buffer down
- memcpy(decoder->short_buffer,decoder->short_buffer+decoder->short_index,sizeof(unsigned char)*unread_space);
- }
- decoder->short_length = unread_space;
- decoder->short_index = 0;
- empty_space = BERT_DECODER_EMPTY(decoder);
- ssize_t length;
- fill_short_buffer:
- length = bert_buffer_read(decoder->short_buffer+decoder->short_length,&(decoder->buffer),empty_space);
- decoder->short_length += length;
- if ((decoder->short_length - decoder->short_index) < size)
- {
- return BERT_ERRNO_EMPTY;
- }
- return BERT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment