Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
DynBuffer.h File Reference
#include <HttpServer.h>
#include <BaServerLib.h>
Include dependency graph for DynBuffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DynBuffer
 A dynamic buffer. More...
 

Macros

#define DynBuffer_destructor(o)   DynBuffer_release(o)
 Release the current storage. More...
 
#define DynBuffer_getBufSize(o)   BufPrint_getBufSize((BufPrint*)(o))
 Read the payload length. More...
 
#define DynBuffer_getCurPtr(o)   (((BufPrint*)(o))->buf+((BufPrint*)(o))->cursor)
 Get the current write position. More...
 
#define DynBuffer_incrementCursor(o, nBytes)   ((BufPrint*)(o))->cursor+=nBytes
 Advance after writing reserved storage. More...
 
#define DynBuffer_getECode(o)   ((o)->expandSize < 0 ? (o)->expandSize : 0)
 Read the allocation-error state. More...
 

Typedefs

typedef void(* DynBuffer_OnAllocError) (struct DynBuffer *o, int eCode)
 Report an allocation error synchronously from a buffer operation. More...
 
typedef DynBuffer DynBuffer
 A dynamic buffer. More...
 

Functions

BA_API void DynBuffer_constructor (DynBuffer *o, int startSize, int expandSize, AllocatorIntf *alloc, DynBuffer_OnAllocError onAllocError)
 Initialize a dynamic buffer and optionally allocate its starting storage. More...
 
BA_API void DynBuffer_release (DynBuffer *o)
 Release the current storage and invalidate borrowed pointers. More...
 
BA_API char * DynBuffer_getBuf (DynBuffer *o)
 Terminate and obtain the current payload. More...
 
BA_API int DynBuffer_expand (DynBuffer *o, int sizeNeeded)
 Reserve additional space without advancing the cursor. More...
 
BA_API const char * DynBuffer_ecode2str (int eCode)
 Translate an allocation error. More...
 

Macro Definition Documentation

◆ DynBuffer_destructor

#define DynBuffer_destructor (   o)    DynBuffer_release(o)

Release the current storage.

Parameters
[in,out]oInitialized buffer; see DynBuffer::release.

◆ DynBuffer_getBufSize

#define DynBuffer_getBufSize (   o)    BufPrint_getBufSize((BufPrint*)(o))

Read the payload length.

Parameters
[in]oInitialized buffer.
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]oInitialized 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
[in]oInitialized buffer.
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]oInitialized buffer.
[in]nBytesNonnegative bytes written; must fit in the reserved space.

Typedef Documentation

◆ 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]oBuffer that encountered the error; borrowed, not transferred.
[in]eCodeNegative 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.

Function Documentation

◆ DynBuffer_constructor()

BA_API void DynBuffer_constructor ( DynBuffer o,
int  startSize,
int  expandSize,
AllocatorIntf alloc,
DynBuffer_OnAllocError  onAllocError 
)

Initialize a dynamic buffer and optionally allocate its starting storage.

Parameters
[out]oCaller-owned buffer object.
[in]startSizeNonnegative initial payload capacity in bytes.
[in]expandSizeNonnegative growth increment; zero disables growth.
[in]allocBorrowed allocator or NULL for the default.
[in]onAllocErrorOptional 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]eCodeOne 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]oInitialized buffer.
[in]sizeNeededNonnegative 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]oInitialized 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
[in,out]oInitialized buffer; see DynBuffer::release.