Barracuda Application Server C/C++ Reference
NO
|
A dynamic buffer.
You either Subclass and implement the DynBuffer_OnAllocError method or set OnAllocError to NULL.
#include <DynBuffer.h>
Public Member Functions | |
DynBuffer (int startSize, int expandSize, AllocatorIntf *alloc=0, DynBuffer_OnAllocError onAllocError=0) | |
Create a dynamic buffer. More... | |
~DynBuffer () | |
destructor. More... | |
void | release () |
terminate the internal dynamic buffer by calling free | |
char * | getBuf () |
Returns a pointer to the internal buffer. More... | |
U32 | getBufSize () |
Returns current size of internal formatted data. | |
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) | |
BufPrint constructor. More... | |
void * | getUserData () |
Returns the user data pointer set in the constructor. | |
int | vprintf (const char *fmt, va_list argList) |
The printf function's format is identical to the standard ANSI vprintf function. More... | |
int | printf (const char *fmt,...) |
The printf function's format is identical to the standard ANSI printf function, but with the following extensions: More... | |
int | baputc (int c) |
print character (wrapper for BufPrint_putc) | |
int | write (const void *data, int len) |
Write data to the buffer. More... | |
int | write (const char *buf) |
Used for sending a zero terminated string to the client. More... | |
void | setBuf (char *buf, int size) |
Set the buffer used by BufPrint. More... | |
char * | getBuf () |
Returns a pointer to the internal buffer. More... | |
U32 | getBufSize () |
Returns current size of internal formatted data. | |
void | erase () |
resets the cursor, thus erasing the data in the buffer | |
int | flush () |
Flush buffer. | |
int | b64Encode (const void *data, S32 slen) |
Encode binary data as Base64. More... | |
int | b64urlEncode (const void *source, S32 slen, bool padding) |
Encode binary data as Base64url. More... | |
int | jsonString (const char *str) |
Print and escape a string such that a browser can run the JavaScript 'eval' function and produce a string identical to the string the 'str' argument points to. More... | |
Static Public Member Functions | |
static const char * | ecode2str (int eCode) |
Convert error code to string. More... | |
DynBuffer::DynBuffer | ( | int | startSize, |
int | expandSize, | ||
AllocatorIntf * | alloc = 0 , |
||
DynBuffer_OnAllocError | onAllocError = 0 |
||
) |
Create a dynamic buffer.
startSize | the size allocated by calling malloc. |
expandSize | chunk size used when calling realloc. Set to 0 if you do not want the buffer to dynamically grow. |
alloc | the allocator used by the dynamic buffer. |
onAllocError | pointer to function called on allocation error. |
DynBuffer::~DynBuffer | ( | ) |
destructor.
release memory by calling method DynBuffer::release.
|
static |
Convert error code to string.
Used by the onAllocError callback.
int DynBuffer::expand | ( | int | sizeNeeded | ) |
force buffer to expand.
sizeNeeded | the required expand size. |
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.
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 method is typically used when the DynBuffer_OnAllocError is set to NULL in the constructor.
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.
example