SILC_STR_FUNC

NAME

    #define SILC_STR_FUNC() ...

DESCRIPTION

Formatting and unformatting of arbitrary data.

     Formatting:    SILC_STR_FUNC(function, void *value, void *context)
     Unformatting:  SILC_STR_FUNC(function, void **value, void *context)

This type can be used to call the `function' of the type SilcBufferFormatFunc or SilcBufferUnformatFunc to encode or decode the `value'. In encoding the `value' will be passed to the `function' and can be encoded into the buffer. The buffer will be passed as well to the `function' at the location where SILC_STR_FUNC is placed in formatting. The `context' delivers caller specific context to the `function'

In unformatting the `function' will decode the encoded type and return it to `value' pointer. The decoding function should decide itself whether to allocate or not the decoded value.

The `function' does not have to encode anything and passing `value' as NULL is allowed. The `function' could for example modify the existing buffer.

EXAMPLE

    // Encode payload, encrypt and compute MAC.
    silc_buffer_format(buf,
                       SILC_STR_FUNC(foo_encode_id, id, ctx),
                       SILC_STR_UINT16(len),
                       SILC_STR_DATA(data, len),
                       SILC_STR_FUNC(foo_buf_encrypt, NULL, key),
                       SILC_STR_FUNC(foo_buf_hmac, NULL, hmac),
                       SILC_STR_DATA(iv, iv_len);
                       SILC_STR_END);

    // Check MAC, decrypt and decode payload
    silc_buffer_unformat(buf,
                         SILC_STR_FUNC(foo_buf_hmac, NULL, hmac),
                         SILC_STR_FUNC(foo_buf_decrypt, NULL, key),
                         SILC_STR_FUNC(foo_decode_id, &id, ctx),
                         SILC_STR_UINT16(&len),
                         SILC_STR_END);