## prelude-msgbuf

prelude-msgbuf

## Synopsis

    typedef             prelude_msgbuf_t;
    enum                prelude_msgbuf_flags_t;
    int                 prelude_msgbuf_new                  (prelude_msgbuf_t **msgbuf);
    void                prelude_msgbuf_destroy              (prelude_msgbuf_t *msgbuf);
    void                prelude_msgbuf_mark_end             (prelude_msgbuf_t *msgbuf);
    int                 prelude_msgbuf_set                  (prelude_msgbuf_t *msgbuf,
                                                             uint8_t tag,
                                                             uint32_t len,
                                                             const void *data);
    prelude_msg_t *     prelude_msgbuf_get_msg              (prelude_msgbuf_t *msgbuf);
    void                prelude_msgbuf_set_callback         (prelude_msgbuf_t *msgbuf,
                                                             int (send_msgprelude_msgbuf_t *msgbuf, prelude_msg_t *msg) ());
    void                prelude_msgbuf_set_data             (prelude_msgbuf_t *msgbuf,
                                                             void *data);
    void *              prelude_msgbuf_get_data             (prelude_msgbuf_t *msgbuf);
    void                prelude_msgbuf_set_flags            (prelude_msgbuf_t *msgbuf,
                                                             prelude_msgbuf_flags_t flags);
    prelude_msgbuf_flags_t  prelude_msgbuf_get_flags        (prelude_msgbuf_t *msgbuf);

## Description

## Details

### prelude_msgbuf_t

    typedef struct prelude_msgbuf prelude_msgbuf_t;

### enum prelude_msgbuf_flags_t

    typedef enum {
            PRELUDE_MSGBUF_FLAGS_ASYNC = 0x01
    } prelude_msgbuf_flags_t;

### prelude_msgbuf_new ()

    int                 prelude_msgbuf_new                  (prelude_msgbuf_t **msgbuf);

Create a new prelude_msgbuf_t object and store it into `msgbuf`. You can then write data to `msgbuf` using the `prelude_msgbuf_set()` function.

When the message buffer is full, the message will be flushed using the user provided callback.

`msgbuf` : | Pointer where to store the created prelude_msgbuf_t object.
Returns : | 0 on success, or a negative value if an error occured.

### prelude_msgbuf_destroy ()

    void                prelude_msgbuf_destroy              (prelude_msgbuf_t *msgbuf);

Destroy `msgbuf`, all data remaining will be flushed.

`msgbuf` : | Pointer on a prelude_msgbuf_t object.

### prelude_msgbuf_mark_end ()

    void                prelude_msgbuf_mark_end             (prelude_msgbuf_t *msgbuf);

This function should be called to tell the msgbuf subsystem that you finished writing your message.

`msgbuf` : | Pointer on prelude_msgbuf_t object.

### prelude_msgbuf_set ()

    int                 prelude_msgbuf_set                  (prelude_msgbuf_t *msgbuf,
                                                             uint8_t tag,
                                                             uint32_t len,
                                                             const void *data);

`prelude_msgbuf_set()` append `len` bytes of data from the `data` buffer to the `msgbuf` object representing a message. The data is tagged with `tag`.

`msgbuf` : | Pointer on a prelude_msgbuf_t object to store the data to.
`tag` : | 8 bits unsigned integer describing the kind of data.
`len` : | len of the data chunk.
`data` : | Pointer to the data.
Returns : | 0 on success, a negative value if an error occured.

### prelude_msgbuf_get_msg ()

    prelude_msg_t *     prelude_msgbuf_get_msg              (prelude_msgbuf_t *msgbuf);

`msgbuf` : | Pointer on a prelude_msgbuf_t object.
Returns : | This function return the current message associated with the message buffer.

### prelude_msgbuf_set_callback ()

    void                prelude_msgbuf_set_callback         (prelude_msgbuf_t *msgbuf,
                                                             int (send_msgprelude_msgbuf_t *msgbuf, prelude_msg_t *msg) ());

Associate an application specific callback to this `msgbuf`.

`msgbuf` : | Pointer on a prelude_msgbuf_t object.
`send_msg` : | Pointer to a function for sending a message.

### prelude_msgbuf_set_data ()

    void                prelude_msgbuf_set_data             (prelude_msgbuf_t *msgbuf,
                                                             void *data);

`msgbuf` : |
`data` : |

### prelude_msgbuf_get_data ()

    void *              prelude_msgbuf_get_data             (prelude_msgbuf_t *msgbuf);

`msgbuf` : |
Returns : |

### prelude_msgbuf_set_flags ()

    void                prelude_msgbuf_set_flags            (prelude_msgbuf_t *msgbuf,
                                                             prelude_msgbuf_flags_t flags);

`msgbuf` : |
`flags` : |

### prelude_msgbuf_get_flags ()

    prelude_msgbuf_flags_t  prelude_msgbuf_get_flags        (prelude_msgbuf_t *msgbuf);

`msgbuf` : |
Returns : |