C/C++ Reference
printf compatible function

Classes

struct  BufPrint
 The BufPrint class, which implements an ANSI compatible printf method, is an abstract class used as a base for many of the Barracuda classes. More...

Typedefs

typedef int(* BufPrint_Flush )(struct BufPrint *o, int sizeRequired)
 BufPrint flush callback function.
typedef struct BufPrint BufPrint
 The BufPrint class, which implements an ANSI compatible printf method, is an abstract class used as a base for many of the Barracuda classes.

Functions

void * BufPrint::getUserData ()
 Returns the user data pointer set in the constructor.
 BufPrint::BufPrint (void *userData, BufPrint_Flush flush)
 BufPrint constructor.
int BufPrint::vprintf (const char *fmt, va_list argList)
 The printf function's format is identical to the standard ANSI vprintf function.
int BufPrint::printf (const char *fmt,...)
 The printf function's format is identical to the standard ANSI printf function, but with the following extensions:
char * BufPrint::getBuf ()
 Returns a pointer to the internal buffer.
U32 BufPrint::getBufSize ()
 Returns current size of internal formatted data.
void BufPrint::erase ()
 resets the cursor, thus erasing the data in the buffer
int BufPrint::putc (int c)
 print character
int BufPrint::write (const void *data, int len)
 Write data to the buffer.
int BufPrint::write (const char *buf)
 Used for sending a zero terminated string to the client.
int BufPrint::flush ()
 Flush buffer.
int BufPrint::b64Encode (const void *data, S32 slen)
 Encode binary data as B64.
int BufPrint::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.

Detailed Description

See also:
Barracuda Introduction

Typedef Documentation

typedef struct BufPrint BufPrint

The BufPrint class, which implements an ANSI compatible printf method, is an abstract class used as a base for many of the Barracuda classes.

The output from printf is formatted in an internal buffer. This class does not allocate memory for the buffer. Thus, any class using BufPrint must provide a buffer BufPrint can use. BufPrint calls the callback function BufPrint_Flush when the buffer is full.

typedef int(* BufPrint_Flush)(struct BufPrint *o, int sizeRequired)

BufPrint flush callback function.

A BufPrint instance calls the flush callback function when buffer is full. The callback can either extend the buffer or flush and reset the buffer.

Parameters:
othe object. BufPrint is typically upcasted to the derived object.
sizeRequiredthe required expands size if the callback is expanding the buffer. Not used when flushing and resetting the buffer.

Function Documentation

int BufPrint::b64Encode ( const void *  data,
S32  slen 
)

Encode binary data as B64.

See also:
baB64Decode
Parameters:
databinary data or string to be encoded as B64.
slenthe data size.
BufPrint::BufPrint ( void *  userData,
BufPrint_Flush  flush 
)

BufPrint constructor.

Parameters:
userDataan optional argument stored in the BufPrint object and accessible in the flush callback.
See also:
getUserData()
Parameters:
flusha pointer to the flush callback function.
char * BufPrint::getBuf ( )

Returns a pointer to the internal buffer.

Please note that the buffer returned by this method is not zero terminated.

See also:
BufPrint::getBufSize

Reimplemented in DynBuffer.

int BufPrint::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.

The string must be ASCII or UTF8. A UTF8 string is converted to JavaScript Unicode i.e. to \uxxxx.

The function can, for example, be used if the server generates a JSON response or generates dynamic JavaScript in a CSP page.

See also:
BufPrint::printf with format flag j
int BufPrint::printf ( const char *  fmt,
  ... 
)

The printf function's format is identical to the standard ANSI printf function, but with the following extensions:

  • %lld is for printing S64 or a signed representation of a U64.
  • %llu is for printing an unsigned U64.
  • %j is similar to %s, but the string is encoded by using BufPrint::jsonString
Parameters:
fmtSee vprintf in the C Standard Library for more information.
int BufPrint::vprintf ( const char *  fmt,
va_list  argList 
)

The printf function's format is identical to the standard ANSI vprintf function.

See BufPrint::printf for the format flags.

Parameters:
fmtSee vprintf in the C Standard Library for more information.
argListSee vprintf in the C Standard Library for more information.
int BufPrint::write ( const void *  data,
int  len 
)

Write data to the buffer.

Parameters:
datapointer to data.
lensize of data.
int BufPrint::write ( const char *  buf)

Used for sending a zero terminated string to the client.

C method name is BufPrint_write2.

Parameters:
bufa reference to the string.