11/*
2- * Copyright (C) 2021 Linux Studio Plugins Project <https://lsp-plug.in/>
3- * (C) 2021 Vladimir Sadovnikov <[email protected] > 2+ * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3+ * (C) 2025 Vladimir Sadovnikov <[email protected] > 44 *
55 * This file is part of lsp-runtime-lib
66 * Created on: 13 мар. 2021 г.
@@ -54,9 +54,10 @@ namespace lsp
5454 public:
5555 uint8_t *data; // Buffer data (2 x capacity)
5656 uint32_t *index; // Index
57- ssize_t head; // Head of the buffer
58- ssize_t tail; // Buffer tail
59- ssize_t cap; // Buffer capacity
57+ uint32_t *root; // Root index
58+ uint32_t head; // Head of the buffer
59+ uint32_t length; // Buffer length
60+ uint32_t cap; // Buffer capacity
6061
6162 public:
6263 explicit cbuffer_t ();
@@ -66,11 +67,38 @@ namespace lsp
6667 void destroy ();
6768
6869 public:
69- void append (const void *src, ssize_t count);
70+ /* *
71+ * Append buffer to compression buffer
72+ * @param src buffer to append
73+ * @param count the length of the buffer to append
74+ */
75+ void append (const void *src, size_t count);
76+
77+ /* *
78+ * Append single byte to compression buffer
79+ * @param v byte to append
80+ */
7081 void append (uint8_t v);
71- size_t lookup (ssize_t *out, const void *src, size_t avail);
82+
83+ /* *
84+ * Lookup for byte sequence inside of the buffer
85+ * @param out relative offset of the sub-sequence in the buffer to the last byte stored in the buffer
86+ * @param src byte sequence to search inside of the buffer
87+ * @param avail number of bytes available in the sequence
88+ * @return the length of sub-sequence found in the buffer
89+ */
90+ size_t lookup (size_t *out, const void *src, size_t avail);
91+
92+ /* *
93+ * Cleanup state of the buffer
94+ */
7295 void clear ();
73- inline size_t size () const { return tail - head; }
96+
97+ /* *
98+ * Get size of data currently stored in the buffer
99+ * @return size of data currently stored in the buffer
100+ */
101+ inline size_t size () const { return lsp_min (length, cap); }
74102
75103 } cbuffer_t ;
76104
@@ -81,9 +109,9 @@ namespace lsp
81109 {
82110 public:
83111 uint8_t *data; // Buffer data (2 x capacity)
84- ssize_t head ; // Head of the buffer
85- ssize_t tail ; // Buffer tail
86- ssize_t cap; // Buffer capacity
112+ uint32_t length ; // Actual size of buffer
113+ uint32_t head ; // Head of the buffer
114+ uint32_t cap; // Buffer capacity
87115
88116 public:
89117 explicit dbuffer_t ();
@@ -93,14 +121,43 @@ namespace lsp
93121 void destroy ();
94122
95123 public:
124+ /* *
125+ * Extract data from buffer
126+ * @param dst destination pointer to store result
127+ * @param offset relative offset of the subsequence in the buffer to the last byte store in the buffer
128+ * @param count number of bytes to extract
129+ * @return status of operation (error on buffer underflow)
130+ */
131+ status_t extract (void *dst, size_t offset, size_t count);
132+
133+ /* *
134+ * Append multiple bytes to the buffer
135+ * @param src data to append to the buffer
136+ * @param count number of bytes to append
137+ */
96138 void append (const void *src, ssize_t count);
139+
140+ /* *
141+ * Append single byte to the buffer
142+ * @param v byt to append
143+ */
97144 void append (uint8_t v);
145+
146+ /* *
147+ * Clear buffer state
148+ */
98149 void clear ();
99- inline size_t size () const { return tail - head; }
150+
151+ /* *
152+ * Get size of data currently stored in the buffer
153+ * @return size of data currently stored in the buffer
154+ */
155+ inline size_t size () const { return length; }
100156
101157 } duffer_t ;
102- }
103- }
158+
159+ } /* namespace resource */
160+ } /* namespace lsp */
104161
105162
106163
0 commit comments