SmolRTSP  0.1.3
A small, portable, extensible RTSP 1.0 implementation in C99
writer.h File Reference

The writer interface. More...

#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <interface99.h>
#include <slice99.h>
#include <smolrtsp/priv/compiler_attrs.h>
Include dependency graph for writer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SmolRTSP_Writer_IFACE
 The user-supplied data writer interface. More...
 
#define SMOLRTSP_WRITE_SLICES(w, ...)
 The same as smolrtsp_write_slices but calculates an array length from variadic arguments (the syntactically separated items of the array). More...
 

Functions

 interface99 (SmolRTSP_Writer)
 Defines the SmolRTSP_Writer interface. More...
 
ssize_t smolrtsp_write_slices (SmolRTSP_Writer w, size_t len, const CharSlice99 data[restrict static len]) SMOLRTSP_PRIV_MUST_USE
 Sequentially writes all items in data to w. More...
 
SmolRTSP_Writer smolrtsp_fd_writer (int *fd) SMOLRTSP_PRIV_MUST_USE
 A writer that invokes write on a provided file descriptor. More...
 
SmolRTSP_Writer smolrtsp_file_writer (FILE *stream) SMOLRTSP_PRIV_MUST_USE
 A writer that invokes fwrite on a provided file pointer. More...
 
SmolRTSP_Writer smolrtsp_string_writer (char *buffer) SMOLRTSP_PRIV_MUST_USE
 A writer that invokes strncat on a provided buffer. More...
 

Detailed Description

The writer interface.

Macro Definition Documentation

◆ SMOLRTSP_WRITE_SLICES

#define SMOLRTSP_WRITE_SLICES (   w,
  ... 
)
Value:
w, SLICE99_ARRAY_LEN((const CharSlice99[])__VA_ARGS__), \
(const CharSlice99[])__VA_ARGS__)
ssize_t smolrtsp_write_slices(SmolRTSP_Writer w, size_t len, const CharSlice99 data[restrict static len]) SMOLRTSP_PRIV_MUST_USE
Sequentially writes all items in data to w.

The same as smolrtsp_write_slices but calculates an array length from variadic arguments (the syntactically separated items of the array).

◆ SmolRTSP_Writer_IFACE

#define SmolRTSP_Writer_IFACE
Value:
\
/* \
* Writes @p data into itself. \
* \
* @param[in] data The slice of character data to write. \
* \
* @return The number of bytes written or a negative value on error. \
*/ \
vfunc99(ssize_t, write, VSelf99, CharSlice99 data) \
\
/* \
* Lock writer to prevent race conditions on TCP interleaved channels \
*/ \
vfunc99(void, lock, VSelf99) \
\
/* \
* Unlock writer locked by `lock` \
*/ \
vfunc99(void, unlock, VSelf99) \
\
/* \
* Get current size of output buffer \
*/ \
vfunc99(size_t, filled, VSelf99) \
\
/* \
* Writes a formatted string into itself. \
* \
* @param[in] fmt The `printf`-like format string. \
* \
* @return The number of bytes written or a negative value on error. \
*/ \
vfunc99(int, writef, VSelf99, const char *restrict fmt, ...) \
\
/* \
* The same as `printf` but accepts `va_list`. \
*/ \
vfunc99(int, vwritef, VSelf99, const char *restrict fmt, va_list ap)

The user-supplied data writer interface.

Function Documentation

◆ interface99()

interface99 ( SmolRTSP_Writer  )

Defines the SmolRTSP_Writer interface.

See Interface99 for the macro usage.

◆ smolrtsp_fd_writer()

SmolRTSP_Writer smolrtsp_fd_writer ( int *  fd)

A writer that invokes write on a provided file descriptor.

Precondition
fd != NULL

◆ smolrtsp_file_writer()

SmolRTSP_Writer smolrtsp_file_writer ( FILE *  stream)

A writer that invokes fwrite on a provided file pointer.

Precondition
stream != NULL

◆ smolrtsp_string_writer()

SmolRTSP_Writer smolrtsp_string_writer ( char *  buffer)

A writer that invokes strncat on a provided buffer.

Precondition
buffer shall be capable of holding all characters that will be written into it.

◆ smolrtsp_write_slices()

ssize_t smolrtsp_write_slices ( SmolRTSP_Writer  w,
size_t  len,
const CharSlice99  data[restrict static len] 
)

Sequentially writes all items in data to w.

Parameters
[in]wThe writer to be provided with data.
[in]lenThe number of items in data.
[in]dataThe data array which will be written to w, one-by-one.
Returns
The number of bytes written or a negative value on error.
Precondition
w.self && w.vptr