|
yocton
|
Functions for writing a Yocton file. More...
#include <inttypes.h>Typedefs | |
| typedef int(* | yoctonw_write) (void *buf, size_t nbytes, void *handle) |
| Callback invoked to write more data to the output. More... | |
| typedef struct yoctonw_writer | yoctonw_writer |
| Writer object for generating Yocton-formatted output. | |
Functions | |
| struct yoctonw_writer * | yoctonw_write_with (yoctonw_write callback, void *handle) |
| Start writing a new stream of yocton-encoded data, using the given callback to write more data. More... | |
| struct yoctonw_writer * | yoctonw_write_to (FILE *fstream) |
| Start writing a new stream of yocton-encoded data, using the given FILE handle. More... | |
| void | yoctonw_free (struct yoctonw_writer *w) |
| Free the writer and stop writing the output stream. More... | |
| void | yoctonw_prop (struct yoctonw_writer *w, const char *name, const char *value) |
| Write a new property and value to the output. More... | |
| void | yoctonw_printf (struct yoctonw_writer *w, const char *name, const char *fmt,...) |
| Write a new property with the value constructed printf-style. More... | |
| void | yoctonw_subobject (struct yoctonw_writer *w, const char *name) |
| Start writing a new subobject. More... | |
| void | yoctonw_end (struct yoctonw_writer *w) |
| End the current subobject. More... | |
| int | yoctonw_have_error (struct yoctonw_writer *w) |
| Check if an error occurred. More... | |
| void | yoctonw_flush (struct yoctonw_writer *w) |
| Flush output buffer and write all pending data. More... | |
Functions for writing a Yocton file.
The entrypoint is to use yoctonw_write_with or yoctonw_write_to.
| typedef int(* yoctonw_write) (void *buf, size_t nbytes, void *handle) |
Callback invoked to write more data to the output.
| buf | Buffer containing data to write. |
| nbytes | Size of buffer in bytes. |
| handle | Arbitrary pointer, passed through from yoctonw_write_with. |
| void yoctonw_end | ( | struct yoctonw_writer * | w | ) |
| void yoctonw_flush | ( | struct yoctonw_writer * | w | ) |
Flush output buffer and write all pending data.
Note that data is automatically flushed whenever a new top-level property is written, so the main use of this is to force any pending data to be written while writing a subobject.
| w | Writer. |
| void yoctonw_free | ( | struct yoctonw_writer * | w | ) |
Free the writer and stop writing the output stream.
| w | The yoctonw_writer. |
| int yoctonw_have_error | ( | struct yoctonw_writer * | w | ) |
Check if an error occurred.
| void yoctonw_printf | ( | struct yoctonw_writer * | w, |
| const char * | name, | ||
| const char * | fmt, | ||
| ... | |||
| ) |
Write a new property with the value constructed printf-style.
For example, the following code:
will produce the following output:
| w | Writer. |
| name | Property name. |
| fmt | Format string |
| void yoctonw_prop | ( | struct yoctonw_writer * | w, |
| const char * | name, | ||
| const char * | value | ||
| ) |
Write a new property and value to the output.
For example, the following code:
will produce the following output:
| w | Writer. |
| name | Property name. |
| value | Property value. |
| void yoctonw_subobject | ( | struct yoctonw_writer * | w, |
| const char * | name | ||
| ) |
Start writing a new subobject.
The yoctonw_end function should be called to end the subobject.
Example:
will produce the following output:
| w | Writer. |
| name | Property name for subobject. |
| struct yoctonw_writer * yoctonw_write_to | ( | FILE * | fstream | ) |
Start writing a new stream of yocton-encoded data, using the given FILE handle.
Example:
| fstream | File handle. |
| struct yoctonw_writer * yoctonw_write_with | ( | yoctonw_write | callback, |
| void * | handle | ||
| ) |
Start writing a new stream of yocton-encoded data, using the given callback to write more data.
Example:
| callback | Callback function to invoke to write data. |
| handle | Arbitrary pointer passed through when callback is invoked. |