#include <evo/impl/rawbuffer.h>
Simple raw memory buffer.
- Members are public for quick access and simple low-level interface
- Access buffer with 'data' member, size used with 'used'
- Use resize() to resize buffer
- Use insert() to make room for new items
- Use remove() to remove items
◆ RawBuffer() [1/2]
◆ RawBuffer() [2/2]
◆ ~RawBuffer()
◆ avail() [1/2]
Get size available.
- Returns
- Size available at end (size - used)
◆ avail() [2/2]
ulong avail |
( |
ulong |
checksize | ) |
const |
|
inline |
Get size up to size available.
- Parameters
-
checksize | Size to check against size available |
- Returns
- Size available at end (size - used) or
checksize
, whichever is smaller
◆ clear()
Clear buffer.
- Returns
- This
◆ flush()
void flush |
( |
ulong & |
offset | ) |
|
|
inline |
Flush data already read from buffer using offset.
- This moves data at offset to beginning of buffer to make room for more data
- Parameters
-
offset | Offset to use and update, will be set to 0 [in/out] |
◆ insert()
ulong insert |
( |
ulong |
index, |
|
|
ulong |
size = 1 |
|
) |
| |
|
inline |
Make room to insert items.
- This shifts items over to make room and updates 'used' but doesn't actually insert
- Parameters
-
index | Insert index, END to append |
size | Insert size in bytes, must be postive |
- Returns
- Actual insert index
◆ minsize()
Resize buffer if smaller than minimum size.
- Parameters
-
- Returns
- This
◆ read()
ulong read |
( |
ulong & |
offset, |
|
|
char * |
buf, |
|
|
ulong |
readsize |
|
) |
| |
|
inline |
Read from buffer using offset.
- This copies from offset (data+offset) and increments offset
- Parameters
-
offset | Offset to use and update [in/out] |
buf | Buffer to read/copy to |
readsize | Read size in bytes, reduced if too large |
- Returns
- Actual size read/copied, may be less than readsize if end reached (offset=used)
◆ ref()
RawBuffer& ref |
( |
char * |
data, |
|
|
ulong |
size, |
|
|
ulong |
used = 0 |
|
) |
| |
|
inline |
Reference another buffer.
- Use to access and/or modify another buffer
- This will not take ownership of the buffer (will not free it)
- Parameters
-
data | Buffer data pointer, must not be NULL |
size | Buffer size (capacity) in bytes, must be > 0 |
used | Buffer size in use in bytes, must be <= size |
- Returns
- This
◆ remove()
RawBuffer& remove |
( |
ulong |
index, |
|
|
ulong |
size = 1 |
|
) |
| |
|
inline |
Remove items.
- This removes items and updates 'used'
- Parameters
-
index | Insert index |
size | Remove size in bytes |
- Returns
- This
◆ reset()
Reset to empty state without a buffer.
- This is useful for clearing a reference to another buffer
- Returns
- This
◆ resize()
Resize buffer.
- This updates 'used' if the new size truncates items
- If newsize is the same as current size this does nothing
- If newsize is 0 this will free the buffer (if owned) and reset the data
- If newsize is positive this will: allocate a new buffer, copy existing data if needed (up to 'used'), and free the old buffer (if owned)
- Parameters
-
newsize | New size in bytes, 0 to free |
- Returns
- This
◆ write() [1/2]
ulong write |
( |
const char * |
buf, |
|
|
ulong |
writesize |
|
) |
| |
|
inline |
Write at end of buffer.
- This appends to buffer and increments used
- If write is too big for buffer it will be truncated to fit
- Parameters
-
buf | Buffer to write from |
writesize | Write size in bytes, reduced if too large |
- Returns
- Actual size written, may be less than writesize if buffer is full
◆ write() [2/2]
ulong write |
( |
char |
ch, |
|
|
ulong |
count = 1 |
|
) |
| |
|
inline |
Write character at end of buffer.
- This appends to buffer and increments used
- If count is too big for buffer it will be truncated to fit
- Parameters
-
ch | Character to write |
count | Character repeat count, reduced if too large |
- Returns
- Actual size written, may be less than count if buffer is full
◆ data
Buffer data pointer, NULL if empty (size=0)
◆ owned
Whether this owns the buffer and must free it.
◆ size
◆ used
Buffer size in use in bytes.
The documentation for this struct was generated from the following file: