aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2018-02-09 09:33:41 +0200
committerPetri Lehtinen <petri@digip.org>2018-02-09 09:35:53 +0200
commita6138a07b6f302567254c1f51193d9017dcb8d3e (patch)
treea39f982e663e9a2d908a39bb17c988b6f4f4ead4
parent9e5af7c3b77f81a7d1720073dca600e51fe9962d (diff)
downloadjansson-doc-utf-8.zip
jansson-doc-utf-8.tar.gz
jansson-doc-utf-8.tar.bz2
Document encoding requirements for callbacksdoc-utf-8
Original patch by @phst. Fixes #369.
-rw-r--r--doc/apiref.rst18
1 files changed, 15 insertions, 3 deletions
diff --git a/doc/apiref.rst b/doc/apiref.rst
index a8cf8d6..f5493c6 100644
--- a/doc/apiref.rst
+++ b/doc/apiref.rst
@@ -1119,6 +1119,10 @@ These functions output UTF-8:
the length of the buffer, and *data* is the corresponding
:func:`json_dump_callback()` argument passed through.
+ *buffer* is guaranteed to be a valid UTF-8 string (i.e. multi-byte
+ code unit sequences are preserved). *buffer* never contains
+ embedded null bytes.
+
On error, the function should return -1 to stop the encoding
process. On success, it should return 0.
@@ -1314,11 +1318,19 @@ If no error or position information is needed, you can pass *NULL*.
*buffer* points to a buffer of *buflen* bytes, and *data* is the
corresponding :func:`json_load_callback()` argument passed through.
- On success, the function should return the number of bytes read; a
- returned value of 0 indicates that no data was read and that the
- end of file has been reached. On error, the function should return
+ On success, the function should write at most *buflen* bytes to
+ *buffer*, and return the number of bytes written; a returned value
+ of 0 indicates that no data was produced and that the end of file
+ has been reached. On error, the function should return
``(size_t)-1`` to abort the decoding process.
+ In UTF-8, some code points are encoded as multi-byte sequences. The
+ callback function doesn't need to worry about this, as Jansson
+ handles it at a higher level. For example, you can safely read a
+ fixed number of bytes from a network connection without having to
+ care about code unit sequences broken apart by the chunk
+ boundaries.
+
.. versionadded:: 2.4
.. function:: json_t *json_load_callback(json_load_callback_t callback, void *data, size_t flags, json_error_t *error)