Go to the source code of this file.
◆ DynBuffer_destructor
Release the current storage.
- Parameters
-
◆ DynBuffer_getBufSize
Read the payload length.
- Parameters
-
- Returns
- Payload bytes, excluding the NUL.
◆ DynBuffer_getCurPtr
| #define DynBuffer_getCurPtr |
( |
|
o | ) |
(((BufPrint*)(o))->buf+((BufPrint*)(o))->cursor) |
Get the current write position.
- Parameters
-
| [in] | o | Initialized buffer with allocated storage. |
- Returns
- Borrowed cursor pointer, invalidated by reallocation or release.
◆ DynBuffer_getECode
| #define DynBuffer_getECode |
( |
|
o | ) |
((o)->expandSize < 0 ? (o)->expandSize : 0) |
Read the allocation-error state.
- Parameters
-
- Returns
- Zero or a negative recorded error; see DynBuffer::getECode.
◆ DynBuffer_incrementCursor
| #define DynBuffer_incrementCursor |
( |
|
o, |
|
|
|
nBytes |
|
) |
| ((BufPrint*)(o))->cursor+=nBytes |
Advance after writing reserved storage.
- Parameters
-
| [in,out] | o | Initialized buffer. |
| [in] | nBytes | Nonnegative bytes written; must fit in the reserved space. |
◆ DynBuffer
A dynamic buffer.
You either Subclass and implement the DynBuffer_OnAllocError method or set OnAllocError to NULL.
◆ DynBuffer_OnAllocError
| typedef void(* DynBuffer_OnAllocError) (struct DynBuffer *o, int eCode) |
Report an allocation error synchronously from a buffer operation.
- Parameters
-
| [in,out] | o | Buffer that encountered the error; borrowed, not transferred. |
| [in] | eCode | Negative status stored by DynBuffer_getECode: -1 missing allocation callback, -2 allocation failure, -3 no resize callback, -4 resize failure, -5 size arithmetic failure. This callback cannot supply a new buffer or turn the failed operation into a success. |
◆ DynBuffer_constructor()
Initialize a dynamic buffer and optionally allocate its starting storage.
- Parameters
-
| [out] | o | Caller-owned buffer object. |
| [in] | startSize | Nonnegative initial payload capacity in bytes. |
| [in] | expandSize | Nonnegative growth increment; zero disables growth. |
| [in] | alloc | Borrowed allocator or NULL for the default. |
| [in] | onAllocError | Optional synchronous allocation-error callback. No status is returned; inspect DynBuffer_getECode after construction. |
- See also
- DynBuffer::DynBuffer
◆ DynBuffer_ecode2str()
| BA_API const char * DynBuffer_ecode2str |
( |
int |
eCode | ) |
|
Translate an allocation error.
- Parameters
-
| [in] | eCode | One of -2, -3, -4 or -5; other values assert. |
- Returns
- Borrowed static message; see DynBuffer::ecode2str.
◆ DynBuffer_expand()
| BA_API int DynBuffer_expand |
( |
DynBuffer * |
o, |
|
|
int |
sizeNeeded |
|
) |
| |
Reserve additional space without advancing the cursor.
- Parameters
-
| [in,out] | o | Initialized buffer. |
| [in] | sizeNeeded | Nonnegative byte count required after the cursor. |
- Returns
- 0 when available, -1 on failure or disabled growth.
◆ DynBuffer_getBuf()
| BA_API char * DynBuffer_getBuf |
( |
DynBuffer * |
o | ) |
|
Terminate and obtain the current payload.
- Parameters
-
| [in,out] | o | Initialized buffer. |
- Returns
- Borrowed NUL-terminated storage or NULL if unallocated.
◆ DynBuffer_release()
| BA_API void DynBuffer_release |
( |
DynBuffer * |
o | ) |
|
Release the current storage and invalidate borrowed pointers.
- Parameters
-