stream_cache.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "stream.h"
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef struct StreamCache StreamCache;
  7. /**
  8. * Allocate stream cache.
  9. * @return StreamCache* pointer to a StreamCache instance
  10. */
  11. StreamCache* stream_cache_alloc();
  12. /**
  13. * Free stream cache.
  14. * @param cache Pointer to a StreamCache instance
  15. */
  16. void stream_cache_free(StreamCache* cache);
  17. /**
  18. * Drop the cache contents and set it to initial state.
  19. * @param cache Pointer to a StreamCache instance
  20. */
  21. void stream_cache_drop(StreamCache* cache);
  22. /**
  23. * Determine if the internal cursor is at end the end of cached data.
  24. * @param cache Pointer to a StreamCache instance
  25. * @return True if cursor is at end, otherwise false.
  26. */
  27. bool stream_cache_at_end(StreamCache* cache);
  28. /**
  29. * Get the current size of cached data.
  30. * @param cache Pointer to a StreamCache instance
  31. * @return Size of cached data.
  32. */
  33. size_t stream_cache_size(StreamCache* cache);
  34. /**
  35. * Get the internal cursor position.
  36. * @param cache Pointer to a StreamCache instance
  37. * @return Cursor position inside the cache.
  38. */
  39. size_t stream_cache_pos(StreamCache* cache);
  40. /**
  41. * Load the cache with new data from a stream.
  42. * @param cache Pointer to a StreamCache instance
  43. * @param stream Pointer to a Stream instance
  44. * @return Size of newly cached data.
  45. */
  46. size_t stream_cache_fill(StreamCache* cache, Stream* stream);
  47. /**
  48. * Read cached data and advance the internal cursor.
  49. * @param cache Pointer to a StreamCache instance.
  50. * @param data Pointer to a data buffer. Must be initialized.
  51. * @param size Maximum size in bytes to read from the cache.
  52. * @return Actual size that was read.
  53. */
  54. size_t stream_cache_read(StreamCache* cache, uint8_t* data, size_t size);
  55. /**
  56. * Move the internal cursor relatively to its current position.
  57. * @param cache Pointer to a StreamCache instance.
  58. * @param offset Cursor offset.
  59. * @return Actual cursor offset. Equal to offset parameter on hit.
  60. */
  61. int32_t stream_cache_seek(StreamCache* cache, int32_t offset);
  62. #ifdef __cplusplus
  63. }
  64. #endif