|
Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
|
A dynamic buffer.
You either Subclass and implement the DynBuffer_OnAllocError method or set OnAllocError to NULL.
#include <DynBuffer.h>

Public Member Functions | |
| DynBuffer () | |
| Leave storage uninitialized; call DynBuffer_constructor before use. More... | |
| DynBuffer (int startSize, int expandSize, AllocatorIntf *alloc=0, DynBuffer_OnAllocError onAllocError=0) | |
| Create a dynamic buffer. More... | |
| ~DynBuffer () | |
| destructor. More... | |
| void | release () |
| Free the current storage, reset the cursor and capacity, and invalidate all borrowed buffer pointers. More... | |
| char * | getBuf () |
| Returns a pointer to the internal buffer. More... | |
| U32 | getBufSize () |
| int | getECode () |
| Returns the error code if memory allocation failed. More... | |
| int | expand (int sizeNeeded) |
| force buffer to expand. More... | |
| char * | getCurPtr () |
| Return a pointer to the internal cursor position in the internal dynamic buffer. More... | |
| void | incrementCursor (int nBytes) |
| Increments the internal cursor position. More... | |
Public Member Functions inherited from BufPrint | |
| BufPrint (void *userData=0, BufPrint_Flush flush=0) | |
| BufPrint constructor. More... | |
| BufPrint (char *buf, int size, void *userData=0, BufPrint_Flush flush=0) | |
| Initialize a writer using caller-owned storage. More... | |
| void * | getUserData () |
| int | vprintf (const char *fmt, va_list argList) |
| Format arguments into this writer. More... | |
| int | printf (const char *fmt,...) |
| Format values using the compact BAS formatter. More... | |
| int | baputc (int c) |
| Append one byte (C function: BufPrint_putc). More... | |
| int | write (const void *data, int len) |
| Append bytes, flushing or expanding through the callback as needed. More... | |
| int | write (const char *buf) |
| Append a NUL-terminated string (C macro: BufPrint_write2). More... | |
| void | setBuf (char *buf, int size) |
| Replace borrowed storage and reset the cursor, discarding pending data. More... | |
| char * | getBuf () |
| Returns a pointer to the internal buffer. More... | |
| U32 | getBufSize () |
| void | erase () |
| resets the cursor, thus erasing the data in the buffer More... | |
| int | flush () |
| Deliver pending bytes to the callback with sizeRequired zero. More... | |
| int | b64Encode (const void *data, S32 slen) |
| Append standard Base64 with = padding, without a NUL terminator. More... | |
| int | b64urlEncode (const void *source, S32 slen, bool padding) |
| Append Base64url using - and _, without a NUL terminator. More... | |
| int | jsonString (const char *str, size_t len) |
| Append a complete quoted JSON string. More... | |
Static Public Member Functions | |
| static const char * | ecode2str (int eCode) |
| Convert a recognized allocation error code to a static message. More... | |
| DynBuffer::DynBuffer | ( | ) |
Leave storage uninitialized; call DynBuffer_constructor before use.
| DynBuffer::DynBuffer | ( | int | startSize, |
| int | expandSize, | ||
| AllocatorIntf * | alloc = 0, |
||
| DynBuffer_OnAllocError | onAllocError = 0 |
||
| ) |
Create a dynamic buffer.
| startSize | Nonnegative initial payload capacity in bytes. Zero defers allocation until data requires space. Allocations reserve an additional NUL byte. Keep capacities and cursor arithmetic within int. |
| expandSize | Nonnegative growth increment in bytes. Zero prevents an existing buffer from growing; a larger individual write may request a larger increment. Growth requires a realloc callback. |
| alloc | Borrowed allocator, or NULL for AllocatorIntf_getDefault(). It must outlive the buffer and its storage. |
| onAllocError | Optional callback invoked synchronously on allocation errors; NULL disables notification. Inspect getECode after construction. |
| DynBuffer::~DynBuffer | ( | ) |
destructor.
release memory by calling method DynBuffer::release.
|
static |
Convert a recognized allocation error code to a static message.
| [in] | eCode | One of -2, -3, -4 or -5. Other values, including -1 and zero, trigger an assertion in debug builds. |
| int DynBuffer::expand | ( | int | sizeNeeded | ) |
force buffer to expand.
| sizeNeeded | Nonnegative number of additional bytes required after the current cursor, not a new total capacity. The cursor is unchanged. |
| char * DynBuffer::getBuf | ( | ) |
Returns a pointer to the internal buffer.
This pointer is invalid after the DynBuffer reallocates the internal buffer. Unlike the BufPrint::getBuf method, the buffer returned by this method is zero terminated.
| U32 DynBuffer::getBufSize | ( | ) |
| char * DynBuffer::getCurPtr | ( | ) |
Return a pointer to the internal cursor position in the internal dynamic buffer.
| int DynBuffer::getECode | ( | ) |
Returns the error code if memory allocation failed.
This
| void DynBuffer::incrementCursor | ( | int | nBytes | ) |
Increments the internal cursor position.
It is possible to manually format data in the internal buffer. This method advances the internal cursor by N bytes.
| [in] | nBytes | Nonnegative bytes already written at getCurPtr(). Reserve enough space with expand first; this macro does not check bounds. |
example
| void DynBuffer::release | ( | ) |
Free the current storage, reset the cursor and capacity, and invalidate all borrowed buffer pointers.
Does not destroy the allocator or reset a previously recorded allocation error. Repeated release is harmless.