diff options
| author | Emmanuele Bassi <ebassi@linux.intel.com> | 2010-08-02 17:07:36 +0100 |
|---|---|---|
| committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2010-08-02 17:07:36 +0100 |
| commit | d9b2845572123ed79a6626d90d2d2298c9c3d5a7 (patch) | |
| tree | 4976f8ddca57554ceab5380b29b9669ca296e80c /json-glib/json-generator.c | |
| parent | c7c288b89175b1f9545d6ddff25609b7bb243041 (diff) | |
| download | json-glib-d9b2845572123ed79a6626d90d2d2298c9c3d5a7.tar.gz | |
generator: Add an OutputStream-based method
Currently, only synchronous API.
The output handling is pretty trivial, unlike the input handling in
JsonParser; this is a really basic convenience API.
Diffstat (limited to 'json-glib/json-generator.c')
| -rw-r--r-- | json-glib/json-generator.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c index c77830e..0df5c0b 100644 --- a/json-glib/json-generator.c +++ b/json-glib/json-generator.c @@ -619,6 +619,43 @@ json_generator_to_file (JsonGenerator *generator, } /** + * json_generator_to_stream: + * @generator: a #JsonGenerator + * @stream: a #GOutputStream + * @cancellable: (allow-none): a #GCancellable, or %NULL + * @error: return location for a #GError, or %NULL + * + * Outputs JSON data and streams it (synchronously) to @stream. + * + * Return value: %TRUE if the write operation was successful, and %FALSE + * on failure. In case of error, the #GError will be filled accordingly + * + * Since: 0.12 + */ +gboolean +json_generator_to_stream (JsonGenerator *generator, + GOutputStream *stream, + GCancellable *cancellable, + GError **error) +{ + gboolean retval; + gchar *buffer; + gsize len; + + g_return_val_if_fail (JSON_IS_GENERATOR (generator), FALSE); + g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE); + + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; + + buffer = json_generator_to_data (generator, &len); + retval = g_output_stream_write (stream, buffer, len, cancellable, error); + g_free (buffer); + + return retval; +} + +/** * json_generator_set_root: * @generator: a #JsonGenerator * @node: a #JsonNode |
