decoder_buffer: added function decoder_buffer_skip()
This commit is contained in:
parent
82c6c13780
commit
efb290073b
@ -138,3 +138,29 @@ decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes)
|
||||
|
||||
assert(buffer->consumed <= buffer->length);
|
||||
}
|
||||
|
||||
bool
|
||||
decoder_buffer_skip(struct decoder_buffer *buffer, size_t nbytes)
|
||||
{
|
||||
size_t length;
|
||||
const void *data;
|
||||
bool success;
|
||||
|
||||
/* this could probably be optimized by seeking */
|
||||
|
||||
while (true) {
|
||||
data = decoder_buffer_read(buffer, &length);
|
||||
if (data != NULL) {
|
||||
if (length > nbytes)
|
||||
length = nbytes;
|
||||
decoder_buffer_consume(buffer, length);
|
||||
nbytes -= length;
|
||||
if (nbytes == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
success = decoder_buffer_fill(buffer);
|
||||
if (!success)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -93,4 +93,14 @@ decoder_buffer_read(const struct decoder_buffer *buffer, size_t *length_r);
|
||||
void
|
||||
decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes);
|
||||
|
||||
/**
|
||||
* Skips the specified number of bytes, discarding its data.
|
||||
*
|
||||
* @param buffer the decoder_buffer object
|
||||
* @param nbytes the number of bytes to skip
|
||||
* @return true on success, false on error
|
||||
*/
|
||||
bool
|
||||
decoder_buffer_skip(struct decoder_buffer *buffer, size_t nbytes);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user