Buffer Format Interface

DESCRIPTION

SILC Buffer Format API provides functions for formatting different data types into a buffer and retrieving different data types from a buffer into specified data types. It is especially useful to encode packets, protocol payloads and such.

It also provides many advanced features like calling user specified encoder and decoder functions that are free to do anything to the buffer. The API also provides powerful regular expression matching capabilities within the buffer, enabling caller to not only match regular expressions but to make the API behave like Stream Editor (Sed) and Awk. The buffer can be matched against regular expression and then edited. Caller can do anything they want to the buffer after a match. The SILC_STR_REGEX macro provides many different flags that can change the behavior of the matching, with capabilities to also mimic Sed behavior.

As the SilcBuffer context is not thread-safe these routines may not be used in multithreaded environment with a same SilcBuffer context without concurrency control.

EXAMPLE

 SilcBufferStruct buffer;

 // Encode buffer
 memset(&buffer, 0, sizeof(buffer));
 ret = silc_buffer_format(&buffer,
                          SILC_STR_UINT32(intval),
                          SILC_STR_UINT8(charval),
                          SILC_STR_UINT64(longintval),
                          SILC_STR_UINT16(str_len),
                          SILC_STR_DATA(str, str_len),
                          SILC_STR_END);
 if (ret < 0)
   error;

 // sed 's/foo/bar/', replace first foo with bar
 silc_buffer_format(buffer,
                    SILC_STR_REGEX("foo", 0),
                      SILC_STR_STRING("bar"),
                    SILC_STR_END, SILC_STR_END);

TABLE OF CONTENTS