|
Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
|
Classes | |
| struct | BufPrint |
| The BufPrint class, which implements a compact printf-style formatter, is a base class used by several other classes. More... | |
Macros | |
| #define | BufPrint_getUserData(o) (o)->userData |
| #define | BufPrint_erase(o) (o)->cursor=0 |
| Discard pending bytes without flushing or releasing storage. More... | |
| #define | BufPrint_getBuf(o) (o)->buf |
| #define | BufPrint_setBuf(o, b, size) (o)->buf=b,(o)->bufSize=size,(o)->cursor=0 |
| Replace borrowed storage and discard pending bytes. More... | |
| #define | BufPrint_getBufSize(o) (o)->cursor |
| #define | BufPrint_destructor(o) |
| No operation: BufPrint does not own its storage or context. More... | |
| #define | BufPrint_write2(o, data) BufPrint_write(o, data, -1) |
| Append a NUL-terminated string without copying its terminator. More... | |
Typedefs | |
| typedef int(* | BufPrint_Flush) (struct BufPrint *o, int sizeRequired) |
| BufPrint flush callback function. More... | |
| typedef struct BufPrint | BufPrint |
| The BufPrint class, which implements a compact printf-style formatter, is a base class used by several other classes. More... | |
Functions | |
| BA_API void | BufPrint_constructor (BufPrint *o, void *userData, BufPrint_Flush flush) |
| Initialize a writer without storage; install a buffer before writing. More... | |
| BA_API void | BufPrint_constructor2 (BufPrint *o, char *buf, int size, void *userData, BufPrint_Flush flush) |
| Initialize a writer with borrowed storage. More... | |
| BA_API int | BufPrint_vprintf (BufPrint *o, const char *fmt, va_list argList) |
| Format arguments into this writer. More... | |
| BA_API int | BufPrint_printf (BufPrint *o, const char *fmt,...) |
| Format values using the compact BAS formatter. More... | |
| BA_API int | BufPrint_write (BufPrint *o, const void *data, int len) |
| Append bytes, flushing or expanding through the callback as needed. More... | |
| BA_API int | BufPrint_putc (BufPrint *o, int c) |
| Append one byte (C function: BufPrint_putc). More... | |
| BA_API int | BufPrint_flush (BufPrint *o) |
| Deliver pending bytes to the callback with sizeRequired zero. More... | |
| BA_API int | BufPrint_b64Encode (BufPrint *o, const void *source, S32 slen) |
| Append padded standard Base64; see BufPrint::b64Encode. More... | |
| BA_API int | BufPrint_b64urlEncode (BufPrint *o, const void *source, S32 slen, BaBool padding) |
| Append Base64url using - and _, without a NUL terminator. More... | |
| BA_API int | BufPrint_jsonString (BufPrint *o, const char *str, size_t len) |
| Append a complete quoted JSON string. More... | |
| void * | BufPrint::getUserData () |
| BufPrint::BufPrint (void *userData=0, BufPrint_Flush flush=0) | |
| BufPrint constructor. More... | |
| BufPrint::BufPrint (char *buf, int size, void *userData=0, BufPrint_Flush flush=0) | |
| Initialize a writer using caller-owned storage. More... | |
| int | BufPrint::vprintf (const char *fmt, va_list argList) |
| Format arguments into this writer. More... | |
| int | BufPrint::printf (const char *fmt,...) |
| Format values using the compact BAS formatter. More... | |
| char * | BufPrint::getBuf () |
| Returns a pointer to the internal buffer. More... | |
| void | BufPrint::setBuf (char *buf, int size) |
| Replace borrowed storage and reset the cursor, discarding pending data. More... | |
| U32 | BufPrint::getBufSize () |
| void | BufPrint::erase () |
| resets the cursor, thus erasing the data in the buffer More... | |
| int | BufPrint::baputc (int c) |
| Append one byte (C function: BufPrint_putc). More... | |
| int | BufPrint::write (const void *data, int len) |
| Append bytes, flushing or expanding through the callback as needed. More... | |
| int | BufPrint::write (const char *buf) |
| Append a NUL-terminated string (C macro: BufPrint_write2). More... | |
| int | BufPrint::flush () |
| Deliver pending bytes to the callback with sizeRequired zero. More... | |
| int | BufPrint::b64Encode (const void *data, S32 slen) |
| Append standard Base64 with = padding, without a NUL terminator. More... | |
| int | BufPrint::b64urlEncode (const void *source, S32 slen, bool padding) |
| Append Base64url using - and _, without a NUL terminator. More... | |
| int | BufPrint::jsonString (const char *str, size_t len) |
| Append a complete quoted JSON string. More... | |
| #define BufPrint_destructor | ( | o | ) |
No operation: BufPrint does not own its storage or context.
| [in] | o | Writer being destroyed; release owned resources separately. |
| #define BufPrint_erase | ( | o | ) | (o)->cursor=0 |
Discard pending bytes without flushing or releasing storage.
| [in,out] | o | Initialized writer. |
| #define BufPrint_getBuf | ( | o | ) | (o)->buf |
| [in] | o | Initialized writer. |
| #define BufPrint_getBufSize | ( | o | ) | (o)->cursor |
| [in] | o | Initialized writer. |
| #define BufPrint_getUserData | ( | o | ) | (o)->userData |
| [in] | o | Initialized writer. |
| #define BufPrint_setBuf | ( | o, | |
| b, | |||
| size | |||
| ) | (o)->buf=b,(o)->bufSize=size,(o)->cursor=0 |
Replace borrowed storage and discard pending bytes.
| [in,out] | o | Initialized writer. |
| [in] | b | Writable buffer, valid while installed; not freed by BufPrint. |
| [in] | size | Nonnegative capacity in bytes. |
| #define BufPrint_write2 | ( | o, | |
| data | |||
| ) | BufPrint_write(o, data, -1) |
Append a NUL-terminated string without copying its terminator.
| [in,out] | o | Initialized writer. |
| [in] | data | Required string, length fitting int, not overlapping storage. |
The BufPrint class, which implements a compact printf-style formatter, is a base class used by several other classes.
This class does not allocate memory for the buffer. Thus, any class using BufPrint must provide a buffer BufPrint can use. The output from printf is formatted in the buffer passed into the constructor. BufPrint calls the callback function BufPrint_Flush when the buffer is full. See BufPrint_Flush for additional details.
| typedef int(* BufPrint_Flush) (struct BufPrint *o, int sizeRequired) |
BufPrint flush callback function.
A BufPrint instance calls the flush callback function when the buffer is full or when BufPrint::flush is called. The callback can either extend the buffer or flush and reset the buffer.
The following default callback is set if no callback is installed when calling the BufPrint constructor:
| o | Borrowed writer. Update its buffer, capacity and cursor when providing more space or consuming pending bytes. |
| sizeRequired | Additional space requested in bytes. Zero denotes an explicit flush, or initial buffer creation by printf/vprintf. A callback that grows storage must preserve pending bytes. A callback that sends data must reset the cursor and leave usable storage for continued output. |
| int BufPrint::b64Encode | ( | const void * | data, |
| S32 | slen | ||
| ) |
Append standard Base64 with = padding, without a NUL terminator.
| [in] | data | Borrowed source containing at least slen readable bytes. |
| [in] | slen | Nonnegative source length in bytes; zero produces no output. |
| int BufPrint::b64urlEncode | ( | const void * | source, |
| S32 | slen, | ||
| bool | padding | ||
| ) |
Append Base64url using - and _, without a NUL terminator.
| [in] | source | Borrowed source containing at least slen readable bytes. |
| [in] | slen | Nonnegative source length in bytes; zero produces no output. |
| [in] | padding | True appends = padding, false omits it. |
| int BufPrint::baputc | ( | int | c | ) |
Append one byte (C function: BufPrint_putc).
| [in] | c | Character value converted to char. |
| BufPrint::BufPrint | ( | char * | buf, |
| int | size, | ||
| void * | userData = 0, |
||
| BufPrint_Flush | flush = 0 |
||
| ) |
Initialize a writer using caller-owned storage.
C constructor name: BufPrint_constructor2
| buf | Borrowed writable storage; must remain valid while installed. |
| size | Nonnegative capacity in bytes. Supply usable storage before writing. |
| userData | Optional borrowed pointer (default NULL) stored in the BufPrint object and accessible in the flush callback. |
| flush | Optional callback; NULL selects the fixed-buffer callback. See BufPrint_Flush for details. |
| BufPrint::BufPrint | ( | void * | userData = 0, |
| BufPrint_Flush | flush = 0 |
||
| ) |
BufPrint constructor.
When using this constructor, make sure to also call setBuf(). C constructor name: BufPrint_constructor
| userData | Optional borrowed pointer (default NULL) stored in the BufPrint object and accessible in the flush callback. |
| flush | Optional callback; NULL selects the fixed-buffer callback. See BufPrint_Flush for details. |
Append padded standard Base64; see BufPrint::b64Encode.
| [in,out] | o | Initialized writer. |
| [in] | source | Borrowed readable bytes. |
| [in] | slen | Nonnegative source length in bytes. |
Append Base64url using - and _, without a NUL terminator.
| [in] | source | Borrowed source containing at least slen readable bytes. |
| [in] | slen | Nonnegative source length in bytes; zero produces no output. |
| [in] | padding | True appends = padding, false omits it. |
| [in,out] | o | Initialized writer. |
| BA_API void BufPrint_constructor | ( | BufPrint * | o, |
| void * | userData, | ||
| BufPrint_Flush | flush | ||
| ) |
Initialize a writer without storage; install a buffer before writing.
| [out] | o | Caller-owned writer. |
| [in] | userData | Optional borrowed callback context, or NULL. |
| [in] | flush | Callback or NULL for the default fixed-buffer callback. |
| BA_API void BufPrint_constructor2 | ( | BufPrint * | o, |
| char * | buf, | ||
| int | size, | ||
| void * | userData, | ||
| BufPrint_Flush | flush | ||
| ) |
Initialize a writer with borrowed storage.
| [out] | o | Caller-owned writer. |
| [in] | buf | Writable buffer, valid while installed. |
| [in] | size | Nonnegative buffer capacity in bytes. |
| [in] | userData | Optional borrowed callback context, or NULL. |
| [in] | flush | Callback or NULL for the default fixed-buffer callback. |
| BA_API int BufPrint_flush | ( | BufPrint * | o | ) |
Deliver pending bytes to the callback with sizeRequired zero.
| [in,out] | o | Initialized writer. |
| BA_API int BufPrint_jsonString | ( | BufPrint * | o, |
| const char * | str, | ||
| size_t | len | ||
| ) |
Append a complete quoted JSON string.
Escapes ASCII control characters, quotes, slash and backslash. UTF-8 is validated and encoded as \uxxxx sequences, using surrogate pairs for characters outside the Basic Multilingual Plane. Does not append NUL.
| [in] | str | Borrowed ASCII or UTF-8 bytes. Embedded NUL bytes are escaped. |
| [in] | len | Exact readable byte count; no NUL terminator is required. |
| [in,out] | o | Initialized writer. |
| BA_API int BufPrint_printf | ( | BufPrint * | o, |
| const char * | fmt, | ||
| ... | |||
| ) |
Format values using the compact BAS formatter.
Supports integer conversions %d, %i, %u, %o, %x, %X; %p, %c, %s and %%; flags -, +, space, # and 0; width and precision (including *); and the h, l and ll integer length modifiers. %lld and %llu format S64 and U64. %f, %e, %E, %g and %G require floating-point support in the build. This is not a complete implementation of the C library printf.
%j takes a NUL-terminated UTF-8 string and emits a quoted JSON string using jsonString. Precision limits input bytes and must not split a UTF-8 sequence. %s and %j require complete NUL-terminated input even with precision. NULL string pointers become "(null)" (%j also adds JSON quotes). Avoid %n: this implementation does not maintain an output byte count.
| [in] | fmt | Required NUL-terminated format. Following arguments must match the conversions and promoted C types. Keep widths and precisions within signed-short range; literal fields are limited by the parser. |
| [in,out] | o | Initialized writer. |
| BA_API int BufPrint_putc | ( | BufPrint * | o, |
| int | c | ||
| ) |
Append one byte (C function: BufPrint_putc).
| [in] | c | Character value converted to char. |
| [in,out] | o | Initialized writer. |
| BA_API int BufPrint_vprintf | ( | BufPrint * | o, |
| const char * | fmt, | ||
| va_list | argList | ||
| ) |
Format arguments into this writer.
| [in] | fmt | NUL-terminated format using printf's supported conversions. |
| [in] | argList | Initialized argument list matching fmt. Its state after this call is platform dependent; use va_copy if it is needed again. |
| [in,out] | o | Initialized writer. |
| BA_API int BufPrint_write | ( | BufPrint * | o, |
| const void * | data, | ||
| int | len | ||
| ) |
Append bytes, flushing or expanding through the callback as needed.
| [in] | data | Borrowed readable source; must not overlap destination storage. With negative len, supply a NUL-terminated string. |
| [in] | len | Byte count, or a negative value to use strlen(data). Length and cursor arithmetic must fit int. |
| [in,out] | o | Initialized writer. |
| void BufPrint::erase | ( | ) |
resets the cursor, thus erasing the data in the buffer
| int BufPrint::flush | ( | ) |
Deliver pending bytes to the callback with sizeRequired zero.
| char * BufPrint::getBuf | ( | ) |
Returns a pointer to the internal buffer.
Please note that the buffer returned by this method is not zero terminated.
| U32 BufPrint::getBufSize | ( | ) |
| void * BufPrint::getUserData | ( | ) |
| int BufPrint::jsonString | ( | const char * | str, |
| size_t | len | ||
| ) |
Append a complete quoted JSON string.
Escapes ASCII control characters, quotes, slash and backslash. UTF-8 is validated and encoded as \uxxxx sequences, using surrogate pairs for characters outside the Basic Multilingual Plane. Does not append NUL.
| [in] | str | Borrowed ASCII or UTF-8 bytes. Embedded NUL bytes are escaped. |
| [in] | len | Exact readable byte count; no NUL terminator is required. |
| int BufPrint::printf | ( | const char * | fmt, |
| ... | |||
| ) |
Format values using the compact BAS formatter.
Supports integer conversions %d, %i, %u, %o, %x, %X; %p, %c, %s and %%; flags -, +, space, # and 0; width and precision (including *); and the h, l and ll integer length modifiers. %lld and %llu format S64 and U64. %f, %e, %E, %g and %G require floating-point support in the build. This is not a complete implementation of the C library printf.
%j takes a NUL-terminated UTF-8 string and emits a quoted JSON string using jsonString. Precision limits input bytes and must not split a UTF-8 sequence. %s and %j require complete NUL-terminated input even with precision. NULL string pointers become "(null)" (%j also adds JSON quotes). Avoid %n: this implementation does not maintain an output byte count.
| [in] | fmt | Required NUL-terminated format. Following arguments must match the conversions and promoted C types. Keep widths and precisions within signed-short range; literal fields are limited by the parser. |
| void BufPrint::setBuf | ( | char * | buf, |
| int | size | ||
| ) |
Replace borrowed storage and reset the cursor, discarding pending data.
Neither the old nor new storage is freed by BufPrint.
| buf | Borrowed writable storage; must remain valid while installed. |
| size | Nonnegative capacity in bytes. Supply usable storage before writing. |
| int BufPrint::vprintf | ( | const char * | fmt, |
| va_list | argList | ||
| ) |
Format arguments into this writer.
| [in] | fmt | NUL-terminated format using printf's supported conversions. |
| [in] | argList | Initialized argument list matching fmt. Its state after this call is platform dependent; use va_copy if it is needed again. |
| int BufPrint::write | ( | const char * | buf | ) |
Append a NUL-terminated string (C macro: BufPrint_write2).
| [in] | buf | Required readable string, not overlapping writer storage. Its length must fit int; the terminating NUL is not copied. |
| int BufPrint::write | ( | const void * | data, |
| int | len | ||
| ) |
Append bytes, flushing or expanding through the callback as needed.
| [in] | data | Borrowed readable source; must not overlap destination storage. With negative len, supply a NUL-terminated string. |
| [in] | len | Byte count, or a negative value to use strlen(data). Length and cursor arithmetic must fit int. |