4. CMP setup

4.1. Setting up for getting size

Initializes cmp interface for getting totally size of message. This will store the number of bytes used in the variable sz.

<<moncmp_function_declarations>>=
void moncmp_init_getsize(cmp_ctx_t *cmp, size_t *sz);
<<moncmp_functions>>=
void moncmp_init_getsize(cmp_ctx_t *cmp, size_t *sz)
{
    cmp_init(cmp, sz, NULL, NULL, get_size);
}

4.2. Setup for write

This sets up the cmp interface up for writing data to a properly allocated memory buffer buf.

<<moncmp_function_declarations>>=
void moncmp_init_write(moncmp_d *m,
                       cmp_ctx_t *cmp,
                       uint8_t *buf);
<<moncmp_functions>>=
void moncmp_init_write(moncmp_d *m,
                       cmp_ctx_t *cmp,
                       uint8_t *buf)
{
    m->buf = buf;
    m->pos = 0;
    cmp_init(cmp, m, NULL, NULL, memwrite);
}

4.3. Setup for reading

This sets up the cmp interface for reading from a buffer buf.

<<moncmp_function_declarations>>=
void moncmp_init_read(moncmp_d *m,
                      cmp_ctx_t *cmp,
                      uint8_t *buf,
                      size_t sz);
<<moncmp_functions>>=
void moncmp_init_read(moncmp_d *m,
                      cmp_ctx_t *cmp,
                      uint8_t *buf,
                      size_t sz)
{
    m->pos = 0;
    m->buf = buf;
    m->sz = sz;
    cmp_init(cmp, m, memread, NULL, NULL);
}



prev | home | next