aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/Makefile180
-rw-r--r--doc/doxy_frontpage.md37
-rw-r--r--doc/make.bat242
-rw-r--r--doc/source/api.rst39
-rw-r--r--doc/source/api/decoding.rst53
-rw-r--r--doc/source/api/encoding.rst23
-rw-r--r--doc/source/api/item_reference_counting.rst41
-rw-r--r--doc/source/api/item_types.rst41
-rw-r--r--doc/source/api/type_0_1.rst91
-rw-r--r--doc/source/api/type_2.rst66
-rw-r--r--doc/source/api/type_3.rst55
-rw-r--r--doc/source/api/type_4.rst62
-rw-r--r--doc/source/api/type_5.rst44
-rw-r--r--doc/source/api/type_6.rst21
-rw-r--r--doc/source/api/type_7.rst75
-rw-r--r--doc/source/changelog.rst4
-rw-r--r--doc/source/conf.py296
-rw-r--r--doc/source/development.rst143
-rw-r--r--doc/source/getting_started.rst190
-rw-r--r--doc/source/img/win_1.pngbin0 -> 29291 bytes
-rw-r--r--doc/source/img/win_2.pngbin0 -> 20179 bytes
-rw-r--r--doc/source/img/win_3.pngbin0 -> 47224 bytes
-rw-r--r--doc/source/img/win_4.pngbin0 -> 11272 bytes
-rw-r--r--doc/source/img/win_5.pngbin0 -> 29490 bytes
-rw-r--r--doc/source/img/win_6.pngbin0 -> 25195 bytes
-rw-r--r--doc/source/index.rst40
-rw-r--r--doc/source/internal.rst128
-rw-r--r--doc/source/requirements.txt39
-rw-r--r--doc/source/rfc_conformance.rst17
-rw-r--r--doc/source/streaming.rst13
-rw-r--r--doc/source/streaming/decoding.rst40
-rw-r--r--doc/source/streaming/encoding.rst4
-rw-r--r--doc/source/tests.rst39
-rw-r--r--doc/source/using.rst173
34 files changed, 2196 insertions, 0 deletions
diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 000000000000..97a6bdc99543
--- /dev/null
+++ b/doc/Makefile
@@ -0,0 +1,180 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = build
+
+# User-friendly check for sphinx-build
+ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
+$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
+endif
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " texinfo to make Texinfo files"
+ @echo " info to make Texinfo files and run them through makeinfo"
+ @echo " gettext to make PO message catalogs"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " xml to make Docutils-native XML files"
+ @echo " pseudoxml to make pseudoxml-XML files for display purposes"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+ rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/libcbor.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/libcbor.qhc"
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/libcbor"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/libcbor"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+latexpdfja:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through platex and dvipdfmx..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+ @echo "Run \`make' in that directory to run these through makeinfo" \
+ "(use \`make info' here to do that automatically)."
+
+info:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo "Running Texinfo files through makeinfo..."
+ make -C $(BUILDDIR)/texinfo info
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
+
+xml:
+ $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
+ @echo
+ @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
+
+pseudoxml:
+ $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
+ @echo
+ @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
+
+livehtml: html
+ sphinx-autobuild -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
diff --git a/doc/doxy_frontpage.md b/doc/doxy_frontpage.md
new file mode 100644
index 000000000000..30980c4872d4
--- /dev/null
+++ b/doc/doxy_frontpage.md
@@ -0,0 +1,37 @@
+
+
+This is the development reference of [libcbor](https://github.com/PJK/libcbor). Looking for the [user documentation](https://libcbor.readthedocs.io/)?
+
+
+# Where to start
+
+A couple of pointers for you to start with: `0x00000000`, `0xDEADBEEF`.
+
+If you just want to peek under the hood, have a look at:
+ - \ref src/cbor/common.h
+ - \ref src/cbor/encoding.h
+ - \ref src/cbor.h
+
+If you want to implement your own decoder or see how the default one is made:
+ - \ref src/cbor/internal/builder_callbacks.h
+ - \ref src/cbor/internal/stack.h
+
+For details on encoding and packing (could be useful when porting to exotic platforms):
+ - \ref src/cbor/internal/encoders.h
+ - \ref src/cbor/internal/loaders.h
+
+Streaming driver:
+ - \ref src/cbor/streaming.h
+
+Manipulation routines for particular types:
+ - \ref src/cbor/ints.h
+ - \ref src/cbor/bytestrings.h
+ - \ref src/cbor/strings.h
+ - \ref src/cbor/arrays.h
+ - \ref src/cbor/maps.h
+ - \ref src/cbor/tags.h
+ - \ref src/cbor/floats_ctrls.h
+
+# How to contribute
+
+Please refer to [the repository](https://github.com/PJK/libcbor)
diff --git a/doc/make.bat b/doc/make.bat
new file mode 100644
index 000000000000..b3647968e8a5
--- /dev/null
+++ b/doc/make.bat
@@ -0,0 +1,242 @@
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
+set I18NSPHINXOPTS=%SPHINXOPTS% source
+if NOT "%PAPER%" == "" (
+ set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+ set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+ :help
+ echo.Please use `make ^<target^>` where ^<target^> is one of
+ echo. html to make standalone HTML files
+ echo. dirhtml to make HTML files named index.html in directories
+ echo. singlehtml to make a single large HTML file
+ echo. pickle to make pickle files
+ echo. json to make JSON files
+ echo. htmlhelp to make HTML files and a HTML help project
+ echo. qthelp to make HTML files and a qthelp project
+ echo. devhelp to make HTML files and a Devhelp project
+ echo. epub to make an epub
+ echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+ echo. text to make text files
+ echo. man to make manual pages
+ echo. texinfo to make Texinfo files
+ echo. gettext to make PO message catalogs
+ echo. changes to make an overview over all changed/added/deprecated items
+ echo. xml to make Docutils-native XML files
+ echo. pseudoxml to make pseudoxml-XML files for display purposes
+ echo. linkcheck to check all external links for integrity
+ echo. doctest to run all doctests embedded in the documentation if enabled
+ goto end
+)
+
+if "%1" == "clean" (
+ for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+ del /q /s %BUILDDIR%\*
+ goto end
+)
+
+
+%SPHINXBUILD% 2> nul
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.http://sphinx-doc.org/
+ exit /b 1
+)
+
+if "%1" == "html" (
+ %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+ goto end
+)
+
+if "%1" == "dirhtml" (
+ %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+ goto end
+)
+
+if "%1" == "singlehtml" (
+ %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+ goto end
+)
+
+if "%1" == "pickle" (
+ %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can process the pickle files.
+ goto end
+)
+
+if "%1" == "json" (
+ %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can process the JSON files.
+ goto end
+)
+
+if "%1" == "htmlhelp" (
+ %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+ goto end
+)
+
+if "%1" == "qthelp" (
+ %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+ echo.^> qcollectiongenerator %BUILDDIR%\qthelp\libcbor.qhcp
+ echo.To view the help file:
+ echo.^> assistant -collectionFile %BUILDDIR%\qthelp\libcbor.ghc
+ goto end
+)
+
+if "%1" == "devhelp" (
+ %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished.
+ goto end
+)
+
+if "%1" == "epub" (
+ %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The epub file is in %BUILDDIR%/epub.
+ goto end
+)
+
+if "%1" == "latex" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "latexpdf" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ cd %BUILDDIR%/latex
+ make all-pdf
+ cd %BUILDDIR%/..
+ echo.
+ echo.Build finished; the PDF files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "latexpdfja" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ cd %BUILDDIR%/latex
+ make all-pdf-ja
+ cd %BUILDDIR%/..
+ echo.
+ echo.Build finished; the PDF files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "text" (
+ %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The text files are in %BUILDDIR%/text.
+ goto end
+)
+
+if "%1" == "man" (
+ %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The manual pages are in %BUILDDIR%/man.
+ goto end
+)
+
+if "%1" == "texinfo" (
+ %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+ goto end
+)
+
+if "%1" == "gettext" (
+ %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+ goto end
+)
+
+if "%1" == "changes" (
+ %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.The overview file is in %BUILDDIR%/changes.
+ goto end
+)
+
+if "%1" == "linkcheck" (
+ %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+ goto end
+)
+
+if "%1" == "doctest" (
+ %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+ goto end
+)
+
+if "%1" == "xml" (
+ %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The XML files are in %BUILDDIR%/xml.
+ goto end
+)
+
+if "%1" == "pseudoxml" (
+ %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
+ goto end
+)
+
+:end
diff --git a/doc/source/api.rst b/doc/source/api.rst
new file mode 100644
index 000000000000..c25629115060
--- /dev/null
+++ b/doc/source/api.rst
@@ -0,0 +1,39 @@
+API
+=======
+
+The data API is centered around :type:`cbor_item_t`, a generic handle for any CBOR item. There are functions to
+
+ - create items,
+ - set items' data,
+ - parse serialized data into items,
+ - manage, move, and links item together.
+
+The single most important thing to keep in mind is: :type:`cbor_item_t` **is an opaque type and should only be manipulated using the appropriate functions!** Think of it as an object.
+
+The *libcbor* API closely follows the semantics outlined by `CBOR standard <http://tools.ietf.org/html/rfc7049>`_. This part of the documentation provides a short overview of the CBOR constructs, as well as a general introduction to the *libcbor* API. Remaining reference can be found in the following files structured by data types.
+
+The API is designed to allow both very tight control & flexibility and general convenience with sane defaults. [#]_ For example, client with very specific requirements (constrained environment, custom application protocol built on top of CBOR, etc.) may choose to take full control (and responsibility) of memory and data structures management by interacting directly with the decoder. Other clients might want to take control of specific aspects (streamed collections, hash maps storage), but leave other responsibilities to *libcbor*. More general clients might prefer to be abstracted away from all aforementioned details and only be presented complete data structures.
+
+
+*libcbor* provides
+ - stateless encoders and decoders
+ - encoding and decoding *drivers*, routines that coordinate encoding and decoding of complex structures
+ - data structures to represent and transform CBOR structures
+ - routines for building and manipulating these structures
+ - utilities for inspection and debugging
+
+.. toctree::
+
+ api/item_types
+ api/item_reference_counting
+ api/decoding
+ api/encoding
+ api/type_0_1
+ api/type_2
+ api/type_3
+ api/type_4
+ api/type_5
+ api/type_6
+ api/type_7
+
+.. [#] http://softwareengineering.vazexqi.com/files/pattern.html
diff --git a/doc/source/api/decoding.rst b/doc/source/api/decoding.rst
new file mode 100644
index 000000000000..e3a41f467a15
--- /dev/null
+++ b/doc/source/api/decoding.rst
@@ -0,0 +1,53 @@
+Decoding
+=============================
+
+The following diagram illustrates the relationship among different parts of libcbor from the decoding standpoint.
+
+::
+
+ ┌──────────────────────────────────────────────────────────────────────────────────────────────┐
+ │ │
+ │ Client application │
+ │ │
+ │ ┌────────────────────────────────────────────┘
+ │ │ ↕
+ │ │ ┌──────────────────────────────────────────┐
+ │ │ │ │
+ │ │ │ Manipulation routines │
+ │ │ │ │
+ │ ┌─────────────────────────────────────┘ └──────────────────────────────────────────┘
+ │ │ ↑ ↑ ↑ ↑
+ │ │ │ │ ┌─────────────╫──────────┬───────────────────┴─┐
+ │ │ │ CDS │ ║ │ │
+ │ │ │ │ PDS ║ PDS PDS
+ │ │ ↓ ↓ ↓ ↓ ↓ ↓
+ │ │ ┌─────────────────┐ ┌────────────────────┐ ┌────────────────────────────┐
+ │ │ │ │ │ │ │ │
+ │ │ │ Custom driver │ ↔ │ Streaming driver │ ↔ │ Default driver │ ↔ CD
+ │ │ │ │ │ │ │ │
+ └───────────┘ └─────────────────┘ └────────────────────┘ └────────────────────────────┘
+ ↕ ↕ ↕ ↕
+ ┌──────────────────────────────────────────────────────────────────────────────────────────────┐
+ │ │
+ │ Stateless event─driven decoder │
+ │ │
+ └──────────────────────────────────────────────────────────────────────────────────────────────┘
+
+ (PSD = Provided Data Structures, CDS = Custom Data Structures)
+
+This section will deal with the API that is labeled as the "Default driver" in the diagram. That is, routines that
+decode complete libcbor data items
+
+.. doxygenfunction:: cbor_load
+
+Associated data structures
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenenum:: cbor_error_code
+
+.. doxygenstruct:: cbor_load_result
+ :members:
+
+.. doxygenstruct:: cbor_error
+ :members:
+
diff --git a/doc/source/api/encoding.rst b/doc/source/api/encoding.rst
new file mode 100644
index 000000000000..af6bbbe7b9d3
--- /dev/null
+++ b/doc/source/api/encoding.rst
@@ -0,0 +1,23 @@
+Encoding
+=============================
+
+The easiest way to encode data items is using the :func:`cbor_serialize` or :func:`cbor_serialize_alloc` functions:
+
+.. doxygenfunction:: cbor_serialize
+.. doxygenfunction:: cbor_serialize_alloc
+
+Type-specific serializers
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+In case you know the type of the item you want to serialize beforehand, you can use one
+of the type-specific serializers.
+
+.. note:: Unless compiled in debug mode, these do not verify the type. Passing an incorrect item will result in an undefined behavior.
+
+.. doxygenfunction:: cbor_serialize_uint
+.. doxygenfunction:: cbor_serialize_negint
+.. doxygenfunction:: cbor_serialize_bytestring
+.. doxygenfunction:: cbor_serialize_string
+.. doxygenfunction:: cbor_serialize_array
+.. doxygenfunction:: cbor_serialize_map
+.. doxygenfunction:: cbor_serialize_tag
+.. doxygenfunction:: cbor_serialize_float_ctrl
diff --git a/doc/source/api/item_reference_counting.rst b/doc/source/api/item_reference_counting.rst
new file mode 100644
index 000000000000..0c0fa7257826
--- /dev/null
+++ b/doc/source/api/item_reference_counting.rst
@@ -0,0 +1,41 @@
+Memory management and reference counting
+===============================================
+
+Due to the nature of its domain, *libcbor* will need to work with heap memory. The stateless decoder and encoder don't allocate any memory.
+
+If you have specific requirements, you should consider rolling your own driver for the stateless API.
+
+Using custom allocator
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+*libcbor* gives you with the ability to provide your own implementations of ``malloc``, ``realloc``, and ``free``. This can be useful if you are using a custom allocator throughout your application, or if you want to implement custom policies (e.g. tighter restrictions on the amount of allocated memory).
+
+In order to use this feature, *libcbor* has to be compiled with the :doc:`appropriate flags </getting_started>`. You can verify the configuration using the ``CBOR_CUSTOM_ALLOC`` macro. A simple usage might be as follows:
+
+.. code-block:: c
+
+ #if CBOR_CUSTOM_ALLOC
+ cbor_set_allocs(malloc, realloc, free);
+ #else
+ #error "libcbor built with support for custom allocation is required"
+ #endif
+
+.. doxygenfunction:: cbor_set_allocs
+
+
+Reference counting
+^^^^^^^^^^^^^^^^^^^^^
+
+As CBOR items may require complex cleanups at the end of their lifetime, there is a reference counting mechanism in place. This also enables very simple GC when integrating *libcbor* into managed environment. Every item starts its life (by either explicit creation, or as a result of parsing) with reference count set to 1. When the refcount reaches zero, it will be destroyed.
+
+Items containing nested items will be destroyed recursively - refcount of every nested item will be decreased by one.
+
+The destruction is synchronous and renders any pointers to items with refcount zero invalid immediately after calling the :func:`cbor_decref`.
+
+
+.. doxygenfunction:: cbor_incref
+.. doxygenfunction:: cbor_decref
+.. doxygenfunction:: cbor_intermediate_decref
+.. doxygenfunction:: cbor_refcount
+.. doxygenfunction:: cbor_move
+.. doxygenfunction:: cbor_copy
diff --git a/doc/source/api/item_types.rst b/doc/source/api/item_types.rst
new file mode 100644
index 000000000000..1452b3e5f90e
--- /dev/null
+++ b/doc/source/api/item_types.rst
@@ -0,0 +1,41 @@
+Types of items
+===============================================
+
+Every :type:`cbor_item_t` has a :type:`cbor_type` associated with it - these constants correspond to the types specified by the `CBOR standard <http://tools.ietf.org/html/rfc7049>`_:
+
+.. doxygenenum:: cbor_type
+
+To find out the type of an item, one can use
+
+.. doxygenfunction:: cbor_typeof
+
+Please note the distinction between functions like :func:`cbor_isa_uint()` and :func:`cbor_is_int()`. The following functions work solely with the major type value.
+
+
+Binary queries
+------------------------
+
+Alternatively, there are functions to query each particular type.
+
+.. warning:: Passing an invalid :type:`cbor_item_t` reference to any of these functions results in undefined behavior.
+
+.. doxygenfunction:: cbor_isa_uint
+.. doxygenfunction:: cbor_isa_negint
+.. doxygenfunction:: cbor_isa_bytestring
+.. doxygenfunction:: cbor_isa_string
+.. doxygenfunction:: cbor_isa_array
+.. doxygenfunction:: cbor_isa_map
+.. doxygenfunction:: cbor_isa_tag
+.. doxygenfunction:: cbor_isa_float_ctrl
+
+
+Logical queries
+------------------------
+
+These functions provide information about the item type from a more high-level perspective
+
+.. doxygenfunction:: cbor_is_int
+.. doxygenfunction:: cbor_is_float
+.. doxygenfunction:: cbor_is_bool
+.. doxygenfunction:: cbor_is_null
+.. doxygenfunction:: cbor_is_undef
diff --git a/doc/source/api/type_0_1.rst b/doc/source/api/type_0_1.rst
new file mode 100644
index 000000000000..4fc851dd1ed1
--- /dev/null
+++ b/doc/source/api/type_0_1.rst
@@ -0,0 +1,91 @@
+Types 0 & 1 – Positive and negative integers
+===============================================
+
+*CBOR* has two types of integers – positive (which may be effectively regarded as unsigned), and negative. There are four possible widths for an integer – 1, 2, 4, or 8 bytes. These are represented by
+
+.. doxygenenum:: cbor_int_width
+
+
+Type 0 - positive integers
+--------------------------
+================================== =========================================
+Corresponding :type:`cbor_type` ``CBOR_TYPE_UINT``
+Number of allocations One per lifetime
+Storage requirements ``sizeof(cbor_item_t) + sizeof(uint*_t)``
+================================== =========================================
+
+**Note:** once a positive integer has been created, its width *cannot* be changed.
+
+Type 1 - negative integers
+--------------------------
+================================== =========================================
+Corresponding :type:`cbor_type` ``CBOR_TYPE_NEGINT``
+Number of allocations One per lifetime
+Storage requirements ``sizeof(cbor_item_t) + sizeof(uint*_t)``
+================================== =========================================
+
+**Note:** once a positive integer has been created, its width *cannot* be changed.
+
+Type 0 & 1
+-------------
+Due to their largely similar semantics, the following functions can be used for both Type 0 and Type 1 items. One can convert between them freely using `the conversion functions <#dealing-with-signedness>`_.
+
+Actual Type of the integer can be checked using :doc:`item types API <item_types>`.
+
+
+
+An integer item is created with one of the four widths. Because integers' `storage is bundled together with the handle </internal#c.cbor_item_t.data>`_, the width cannot be changed over its lifetime.
+
+.. warning::
+
+ Due to the fact that CBOR negative integers represent integers in the range :math:`[-1, -2^N]`, ``cbor_set_uint`` API is somewhat counter-intuitive as the resulting logical value is 1 less. This behavior is necessary in order to permit uniform manipulation with the full range of permitted values. For example, the following snippet
+
+ .. code-block:: c
+
+ cbor_item_t * item = cbor_new_int8();
+ cbor_mark_negint(item);
+ cbor_set_uint8(0);
+
+ will produce an item with the logical value of :math:`-1`. There is, however, an upside to this as well: There is only one representation of zero.
+
+
+Building new items
+------------------------
+.. doxygenfunction:: cbor_build_uint8
+.. doxygenfunction:: cbor_build_uint16
+.. doxygenfunction:: cbor_build_uint32
+.. doxygenfunction:: cbor_build_uint64
+
+
+Retrieving values
+------------------------
+.. doxygenfunction:: cbor_get_uint8
+.. doxygenfunction:: cbor_get_uint16
+.. doxygenfunction:: cbor_get_uint32
+.. doxygenfunction:: cbor_get_uint64
+
+Setting values
+------------------------
+
+.. doxygenfunction:: cbor_set_uint8
+.. doxygenfunction:: cbor_set_uint16
+.. doxygenfunction:: cbor_set_uint32
+.. doxygenfunction:: cbor_set_uint64
+
+Dealing with width
+---------------------
+.. doxygenfunction:: cbor_int_get_width
+
+Dealing with signedness
+--------------------------
+
+.. doxygenfunction:: cbor_mark_uint
+.. doxygenfunction:: cbor_mark_negint
+
+Creating new items
+------------------------
+
+.. doxygenfunction:: cbor_new_int8
+.. doxygenfunction:: cbor_new_int16
+.. doxygenfunction:: cbor_new_int32
+.. doxygenfunction:: cbor_new_int64
diff --git a/doc/source/api/type_2.rst b/doc/source/api/type_2.rst
new file mode 100644
index 000000000000..17df5716ccc2
--- /dev/null
+++ b/doc/source/api/type_2.rst
@@ -0,0 +1,66 @@
+Type 2 – Byte strings
+=============================
+
+CBOR byte strings are just (ordered) series of bytes without further interpretation (unless there is a :doc:`tag <type_6>`). Byte string's length may or may not be known during encoding. These two kinds of byte strings can be distinguished using :func:`cbor_bytestring_is_definite` and :func:`cbor_bytestring_is_indefinite` respectively.
+
+In case a byte string is indefinite, it is encoded as a series of definite byte strings. These are called "chunks". For example, the encoded item
+
+::
+
+ 0xf5 Start indefinite byte string
+ 0x41 Byte string (1B long)
+ 0x00
+ 0x41 Byte string (1B long)
+ 0xff
+ 0xff "Break" control token
+
+represents two bytes, ``0x00`` and ``0xff``. This on one hand enables streaming messages even before they are fully generated, but on the other hand it adds more complexity to the client code.
+
+
+================================== ======================================================
+Corresponding :type:`cbor_type` ``CBOR_TYPE_BYTESTRING``
+Number of allocations (definite) One plus any manipulations with the data
+Number of allocations (indefinite) One plus logarithmically many
+ reallocations relative to chunk count
+Storage requirements (definite) ``sizeof(cbor_item_t) + length(handle)``
+Storage requirements (indefinite) ``sizeof(cbor_item_t) * (1 + chunk_count) + chunks``
+================================== ======================================================
+
+
+Streaming indefinite byte strings
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Please refer to :doc:`/streaming`.
+
+Getting metadata
+~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_bytestring_length
+.. doxygenfunction:: cbor_bytestring_is_definite
+.. doxygenfunction:: cbor_bytestring_is_indefinite
+.. doxygenfunction:: cbor_bytestring_chunk_count
+
+Reading data
+~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_bytestring_handle
+.. doxygenfunction:: cbor_bytestring_chunks_handle
+
+Creating new items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_new_definite_bytestring
+.. doxygenfunction:: cbor_new_indefinite_bytestring
+
+
+Building items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.. doxygenfunction:: cbor_build_bytestring
+
+
+Manipulating existing items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_bytestring_set_handle
+.. doxygenfunction:: cbor_bytestring_add_chunk
+
diff --git a/doc/source/api/type_3.rst b/doc/source/api/type_3.rst
new file mode 100644
index 000000000000..abec24de40a3
--- /dev/null
+++ b/doc/source/api/type_3.rst
@@ -0,0 +1,55 @@
+Type 3 – UTF-8 strings
+=============================
+
+CBOR strings work in much the same ways as :doc:`type_2`.
+
+================================== ======================================================
+Corresponding :type:`cbor_type` ``CBOR_TYPE_STRING``
+Number of allocations (definite) One plus any manipulations with the data
+Number of allocations (indefinite) One plus logarithmically many
+ reallocations relative to chunk count
+Storage requirements (definite) ``sizeof(cbor_item_t) + length(handle)``
+Storage requirements (indefinite) ``sizeof(cbor_item_t) * (1 + chunk_count) + chunks``
+================================== ======================================================
+
+Streaming indefinite strings
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Please refer to :doc:`/streaming`.
+
+UTF-8 encoding validation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+*libcbor* considers UTF-8 encoding validity to be a part of the well-formedness notion of CBOR and therefore invalid UTF-8 strings will be rejected by the parser. Strings created by the user are not checked.
+
+
+Getting metadata
+~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_string_length
+.. doxygenfunction:: cbor_string_is_definite
+.. doxygenfunction:: cbor_string_is_indefinite
+.. doxygenfunction:: cbor_string_chunk_count
+
+Reading data
+~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_string_handle
+.. doxygenfunction:: cbor_string_chunks_handle
+
+Creating new items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_new_definite_string
+.. doxygenfunction:: cbor_new_indefinite_string
+
+
+Building items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.. doxygenfunction:: cbor_build_string
+
+
+Manipulating existing items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_string_set_handle
+.. doxygenfunction:: cbor_string_add_chunk
diff --git a/doc/source/api/type_4.rst b/doc/source/api/type_4.rst
new file mode 100644
index 000000000000..c3bb88a9cd8a
--- /dev/null
+++ b/doc/source/api/type_4.rst
@@ -0,0 +1,62 @@
+Type 4 – Arrays
+=============================
+
+CBOR arrays, just like :doc:`byte strings <type_2>` and :doc:`strings <type_3>`, can be encoded either as definite, or as indefinite.
+
+================================== =====================================================================================
+Corresponding :type:`cbor_type` ``CBOR_TYPE_ARRAY``
+Number of allocations (definite) Two plus any manipulations with the data
+Number of allocations (indefinite) Two plus logarithmically many
+ reallocations relative to additions
+Storage requirements (definite) ``(sizeof(cbor_item_t) + 1) * size``
+Storage requirements (indefinite) ``<= sizeof(cbor_item_t) + sizeof(cbor_item_t) * size * BUFFER_GROWTH``
+================================== =====================================================================================
+
+
+Examples
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ 0x9f Start indefinite array
+ 0x01 Unsigned integer 1
+ 0xff "Break" control token
+
+::
+
+ 0x9f Start array, 1B length follows
+ 0x20 Unsigned integer 32
+ ... 32 items follow
+
+Streaming indefinite arrays
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Please refer to :doc:`/streaming`.
+
+Getting metadata
+~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_array_size
+.. doxygenfunction:: cbor_array_allocated
+.. doxygenfunction:: cbor_array_is_definite
+.. doxygenfunction:: cbor_array_is_indefinite
+
+Reading data
+~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_array_handle
+.. doxygenfunction:: cbor_array_get
+
+Creating new items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_new_definite_array
+.. doxygenfunction:: cbor_new_indefinite_array
+
+
+Modifying items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_array_push
+.. doxygenfunction:: cbor_array_replace
+.. doxygenfunction:: cbor_array_set
diff --git a/doc/source/api/type_5.rst b/doc/source/api/type_5.rst
new file mode 100644
index 000000000000..c9b2e904af6e
--- /dev/null
+++ b/doc/source/api/type_5.rst
@@ -0,0 +1,44 @@
+Type 5 – Maps
+=============================
+
+CBOR maps are the plain old associate hash maps known from JSON and many other formats and languages, with one exception: any CBOR data item can be a key, not just strings. This is somewhat unusual and you, as an application developer, should keep that in mind.
+
+Maps can be either definite or indefinite, in much the same way as :doc:`type_4`.
+
+================================== =====================================================================================
+Corresponding :type:`cbor_type` ``CBOR_TYPE_MAP``
+Number of allocations (definite) Two plus any manipulations with the data
+Number of allocations (indefinite) Two plus logarithmically many
+ reallocations relative to additions
+Storage requirements (definite) ``sizeof(cbor_pair) * size + sizeof(cbor_item_t)``
+Storage requirements (indefinite) ``<= sizeof(cbor_item_t) + sizeof(cbor_pair) * size * BUFFER_GROWTH``
+================================== =====================================================================================
+
+Streaming maps
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Please refer to :doc:`/streaming`.
+
+Getting metadata
+~~~~~~~~~~~~~~~~~
+.. doxygenfunction:: cbor_map_size
+.. doxygenfunction:: cbor_map_allocated
+.. doxygenfunction:: cbor_map_is_definite
+.. doxygenfunction:: cbor_map_is_indefinite
+
+Reading data
+~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_map_handle
+
+Creating new items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_new_definite_map
+.. doxygenfunction:: cbor_new_indefinite_map
+
+
+Modifying items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_map_add
diff --git a/doc/source/api/type_6.rst b/doc/source/api/type_6.rst
new file mode 100644
index 000000000000..e98457ceae2a
--- /dev/null
+++ b/doc/source/api/type_6.rst
@@ -0,0 +1,21 @@
+Type 6 – Semantic tags
+=============================
+
+Tag are additional metadata that can be used to extend or specialize the meaning or interpretation of the other data items.
+
+For example, one might tag an array of numbers to communicate that it should be interpreted as a vector.
+
+Please consult the official `IANA repository of CBOR tags <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml>`_ before inventing new ones.
+
+================================== ======================================================
+Corresponding :type:`cbor_type` ``CBOR_TYPE_TAG``
+Number of allocations One plus any manipulations with the data
+ reallocations relative to chunk count
+Storage requirements ``sizeof(cbor_item_t) + the tagged item``
+================================== ======================================================
+
+.. doxygenfunction:: cbor_new_tag
+.. doxygenfunction:: cbor_tag_item
+.. doxygenfunction:: cbor_tag_value
+.. doxygenfunction:: cbor_tag_set_item
+
diff --git a/doc/source/api/type_7.rst b/doc/source/api/type_7.rst
new file mode 100644
index 000000000000..d2e75c8bf0b3
--- /dev/null
+++ b/doc/source/api/type_7.rst
@@ -0,0 +1,75 @@
+Type 7 – Floats & control tokens
+=================================
+
+This type combines two completely unrelated types of items -- floating point numbers and special values such as true, false, null, etc. We refer to these special values as 'control values' or 'ctrls' for short throughout the code.
+
+Just like integers, they have different possible width (resulting in different value ranges and precisions).
+
+.. doxygenenum:: cbor_float_width
+
+================================== =========================================
+Corresponding :type:`cbor_type` ``CBOR_TYPE_FLOAT_CTRL``
+Number of allocations One per lifetime
+Storage requirements ``sizeof(cbor_item_t) + 1/4/8``
+================================== =========================================
+
+Getting metadata
+~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_float_ctrl_is_ctrl
+.. doxygenfunction:: cbor_float_get_width
+
+Reading data
+~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_float_get_float2
+.. doxygenfunction:: cbor_float_get_float4
+.. doxygenfunction:: cbor_float_get_float8
+.. doxygenfunction:: cbor_float_get_float
+.. doxygenfunction:: cbor_ctrl_value
+.. doxygenfunction:: cbor_get_bool
+
+Creating new items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_new_ctrl
+.. doxygenfunction:: cbor_new_float2
+.. doxygenfunction:: cbor_new_float4
+.. doxygenfunction:: cbor_new_float8
+.. doxygenfunction:: cbor_new_null
+.. doxygenfunction:: cbor_new_undef
+
+
+Building items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_build_bool
+.. doxygenfunction:: cbor_build_ctrl
+.. doxygenfunction:: cbor_build_float2
+.. doxygenfunction:: cbor_build_float4
+.. doxygenfunction:: cbor_build_float8
+
+
+Manipulating existing items
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenfunction:: cbor_set_ctrl
+.. doxygenfunction:: cbor_set_bool
+.. doxygenfunction:: cbor_set_float2
+.. doxygenfunction:: cbor_set_float4
+.. doxygenfunction:: cbor_set_float8
+
+
+.. _api_type_7_hard_floats:
+
+Half floats
+~~~~~~~~~~~~
+CBOR supports two `bytes wide ("half-precision") <https://en.wikipedia.org/wiki/Half-precision_floating-point_format>`_
+floats which are not supported by the C language. *libcbor* represents them using `float <https://en.cppreference.com/w/c/language/type>` values throughout the API, which has important implications when manipulating these values.
+
+In particular, if a user uses some of the manipulation APIs
+(e.g. :func:`cbor_set_float2`, :func:`cbor_new_float2`)
+to introduce a value that doesn't have an exect half-float representation,
+the encoding semantics are given by :func:`cbor_encode_half` as follows:
+
+.. doxygenfunction:: cbor_encode_half
diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst
new file mode 100644
index 000000000000..89e7008afab2
--- /dev/null
+++ b/doc/source/changelog.rst
@@ -0,0 +1,4 @@
+Changelog
+==============
+
+.. include:: ../../CHANGELOG.md
diff --git a/doc/source/conf.py b/doc/source/conf.py
new file mode 100644
index 000000000000..3ca95bd6dd1f
--- /dev/null
+++ b/doc/source/conf.py
@@ -0,0 +1,296 @@
+# -*- coding: utf-8 -*-
+#
+# libcbor documentation build configuration file, created by
+# sphinx-quickstart on Sun Jun 8 13:27:19 2014.
+#
+# This file is execfile()d with the current directory set to its
+# containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys
+import os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#sys.path.insert(0, os.path.abspath('.'))
+sys.path.append(os.path.abspath(os.path.dirname(__file__)))
+
+# -- General configuration ------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+ 'breathe',
+ 'sphinx.ext.mathjax',
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.ifconfig'
+]
+
+import subprocess, os
+
+# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
+on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
+print(subprocess.check_output('cd ../..; mkdir doc/build; doxygen', shell=True))
+
+if on_rtd:
+ print(subprocess.check_output('cd ../..; mkdir doc/build; doxygen', shell=True))
+
+
+print(os.getcwd())
+print(os.getcwd() + '/../build/doxygen/xml')
+
+breathe_projects = {
+ 'libcbor': '../build/doxygen/xml'
+}
+
+breathe_default_project = "libcbor"
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = 'libcbor'
+copyright = '2014 - 2020, Pavel Kalvoda'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '0.8'
+release = '0.8.0'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# https://github.com/michaeljones/breathe/issues/197
+exclude_patterns = ['breathe/*']
+
+# The reST default role (used for this markup: `text`) to use for all
+# documents.
+breathe_domain_by_extension = {
+ "h" : "C",
+ }
+#default_role = 'c:func'
+primary_domain = "cpp"
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+# If true, keep warnings as "system message" paragraphs in the built documents.
+#keep_warnings = False
+
+
+# -- Options for HTML output ----------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+html_theme = 'default'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = []
+
+# Add any extra paths that contain custom files (such as robots.txt or
+# .htaccess) here, relative to this directory. These files are copied
+# directly to the root of the documentation.
+#html_extra_path = []
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'libcbordoc'
+
+
+# -- Options for LaTeX output ---------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+# author, documentclass [howto, manual, or own class]).
+latex_documents = [
+ ('index', 'libcbor.tex', 'libcbor Documentation',
+ 'Pavel Kalvoda', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output ---------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ ('index', 'libcbor', 'libcbor Documentation',
+ ['Pavel Kalvoda'], 3)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- Options for Texinfo output -------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+# dir menu entry, description, category)
+texinfo_documents = [
+ ('index', 'libcbor', 'libcbor Documentation',
+ 'Pavel Kalvoda', 'libcbor', 'C library for parsing and generating CBOR.',
+ 'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
+
+# If true, do not generate a @detailmenu in the "Top" node's menu.
+#texinfo_no_detailmenu = False
+
+
+if not on_rtd: # only import and set the theme if we're building docs locally
+ import sphinx_rtd_theme
+ html_theme = 'sphinx_rtd_theme'
+ html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
+
+# otherwise, readthedocs.org uses their theme by default, so no need to specify it
+
diff --git a/doc/source/development.rst b/doc/source/development.rst
new file mode 100644
index 000000000000..13e91ef25762
--- /dev/null
+++ b/doc/source/development.rst
@@ -0,0 +1,143 @@
+Development
+==========================
+
+Vision and principles
+---------------------------
+
+Consistency and coherence are one of the key characteristics of good software.
+While the reality is never black and white, it is important libcbor
+contributors are working towards the same high-level goal. This document
+attempts to set out the basic principles of libcbor and the rationale behind
+them. If you are contributing to libcbor or looking to evaluate whether libcbor
+is the right choice for your project, it might be worthwhile to skim through the
+section below.
+
+Mission statement
+~~~~~~~~~~~~~~~~~~~~~~
+
+*libcbor* is the compact, full-featured, and safe CBOR library that works
+everywhere.
+
+
+Goals
+~~~~~~~~~~~~~~~~~~~~~~
+
+RFC-conformance and full feature support
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Anything the standard allows, libcbor can do.
+
+**Why?** Because conformance and interoperability is the point of defining
+standards. Clients expect the support to be feature-complete and
+there is no significant complexity reduction that can be achieved by slightly
+cutting corners, which means that the incremental cost of full RFC support is
+comparatively small over "almost-conformance" seen in many alternatives.
+
+
+Safety
+^^^^^^^^^^^^^^^^^^^^^^
+
+Untrusted bytes from the network are the typical input.
+
+**Why?** Because it is the client expectation. Vast majority of security
+vulnerabilities are violations of contracts -- in other words, bugs -- anyway.
+
+
+Self-containment
+^^^^^^^^^^^^^^^^^^^^^^
+
+libcbor has no runtime dependencies.
+
+**Why?** Because any constraint imposed on libcbor has to be enforced
+transitively, which is difficult and leads to incompatibilities and
+distribution issues, especially in IoT applications.
+
+Portability
+^^^^^^^^^^^^^^^^^^^^^^
+
+If you can compile C for it, libcbor will work there.
+
+**Why?** Lowest-common-denominator solution for system-level and IoT software
+was the original niche of libcbor. Users who rely on libcbor expect future
+updates to work on their target platform.
+
+Stable and predictable API
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+libcbor will not break without a warning.
+
+**Why?** `Industry-standard <https://semver.org/>`_ versioning is a basic
+requirement for production-quality software. This is especially relevant in IoT
+environments where updates may be costly.
+
+Performance
+^^^^^^^^^^^^^^^^^^^^^^
+
+libcbor is fast and resource-efficient by design
+
+
+**Why?** Because the main maintainer is an avid hater of slow bloated software.
+Who wouldn't want more bang per their electricity buck?
+
+
+Non-goals
+~~~~~~~~~~~~~~~~~~~~~~
+
+ - Convenience -- libcbor only provides the minimum surface to make it usable
+ - FFI/SWIG/interop support -- libcbor is primarily a C library for C clients
+ - One-off usecases support -- although there are primitives to reuse, the
+ basic
+ assumption is that most clients want most of CBOR features
+
+
+Development dependencies
+---------------------------
+- `CMocka <http://cmocka.org/>`_ (testing)
+- `Python <https://www.python.org/>`_ and `pip <https://pypi.python.org/pypi/pip>`_ (Sphinx platform)
+- `Doxygen <http://www.stack.nl/~dimitri/doxygen/>`_
+- `Sphinx <http://sphinx-doc.org/>`_ (documentation)
+- There are some `Ruby <https://www.ruby-lang.org/en/>`_ scripts in ``misc``
+- `Valgrind <http://valgrind.org/>`_ (memory correctness & profiling)
+- `GCOV/LCOV <http://ltp.sourceforge.net/coverage/lcov.php>`_ (test coverage)
+- `clang-format`
+
+
+Installing *sphinx*
+~~~~~~~~~~~~~~~~~~~~~~
+
+.. code-block:: bash
+
+ pip install sphinx
+ pip install sphinx_rtd_theme
+ pip install breathe
+ pip install https://github.com/lepture/python-livereload/archive/master.zip
+ pip install sphinx-autobuild
+
+Further instructions on configuring advanced features can be found at `<http://read-the-docs.readthedocs.org/en/latest/install.html>`_.
+
+
+Live preview of docs
+~~~~~~~~~~~~~~~~~~~~~~
+
+.. code-block:: bash
+
+ cd doc
+ make livehtml
+
+
+Set up git hooks
+~~~~~~~~~~~~~~~~~
+
+A catch-all git hook that runs clang-format and automatically refreshes the `GH
+pages <https://pages.github.com/>`_ contents located in ``docs`` can be
+symlinked:
+
+.. code-block:: bash
+
+ ln -sf $(pwd)/misc/hooks/pre-commit .git/hooks
+
+
+Testing and code coverage
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Please refer to :doc:`tests`
diff --git a/doc/source/getting_started.rst b/doc/source/getting_started.rst
new file mode 100644
index 000000000000..3e56f2c84c08
--- /dev/null
+++ b/doc/source/getting_started.rst
@@ -0,0 +1,190 @@
+Getting started
+==========================
+
+Pre-built Linux packages are available in most mainstream distributions
+
+**Ubuntu, Debian, etc.**:
+
+.. code-block:: bash
+
+ apt-get install libcbor-dev
+
+**Fedora, openSUSE, etc.**:
+
+.. code-block:: bash
+
+ yum install libcbor-devel
+
+
+**OS X** users can use `Homebrew <http://brew.sh/>`_:
+
+.. code-block:: bash
+
+ brew install libcbor
+
+For other platforms, you will need to compile it from source.
+
+Building & installing libcbor
+------------------------------
+
+Prerequisites:
+ - C99 compiler
+ - CMake_ 2.8 or newer (might also be called ``cmakesetup``, ``cmake-gui`` or ``ccmake`` depending on the installed version and system)
+ - C build system CMake can target (make, Apple Xcode, MinGW, ...)
+
+.. _CMake: http://cmake.org/
+
+**Configuration options**
+
+A handful of configuration flags can be passed to `cmake`. The following table lists libcbor compile-time directives and several important generic flags.
+
+======================== ======================================================= ====================== =====================================================================================================================
+Option Meaning Default Possible values
+------------------------ ------------------------------------------------------- ---------------------- ---------------------------------------------------------------------------------------------------------------------
+``CMAKE_C_COMPILER`` C compiler to use ``cc`` ``gcc``, ``clang``, ``clang-3.5``, ...
+``CMAKE_INSTALL_PREFIX`` Installation prefix System-dependent ``/usr/local/lib``, ...
+``BUILD_SHARED_LIBS`` Build as a shared library ``OFF`` ``ON``, ``OFF``
+``HUGE_FUZZ`` :doc:`Fuzz test </tests>` with 8GB of data ``OFF`` ``ON``, ``OFF``
+``SANE_MALLOC`` Assume ``malloc`` will refuse unreasonable allocations ``OFF`` ``ON``, ``OFF``
+``COVERAGE`` Generate test coverage instrumentation ``OFF`` ``ON``, ``OFF``
+``WITH_TESTS`` Build unit tests (see :doc:`development`) ``OFF`` ``ON``, ``OFF``
+======================== ======================================================= ====================== =====================================================================================================================
+
+The following configuration options will also be defined as macros[#]_ in ``<cbor/common.h>`` and can therefore be used in client code:
+
+======================== ======================================================= ====================== =====================================================================================================================
+Option Meaning Default Possible values
+------------------------ ------------------------------------------------------- ---------------------- ---------------------------------------------------------------------------------------------------------------------
+``CBOR_CUSTOM_ALLOC`` Enable custom allocator support ``OFF`` ``ON``, ``OFF``
+``CBOR_PRETTY_PRINTER`` Include a pretty-printing routine ``ON`` ``ON``, ``OFF``
+``CBOR_BUFFER_GROWTH`` Factor for buffer growth & shrinking ``2`` Decimals > 1
+======================== ======================================================= ====================== =====================================================================================================================
+
+.. [#] ``ON`` & ``OFF`` will be translated to ``1`` and ``0`` using `cmakedefine <https://cmake.org/cmake/help/v3.2/command/configure_file.html?highlight=cmakedefine>`_.
+
+If you want to pass other custom configuration options, please refer to `<http://www.cmake.org/Wiki/CMake_Useful_Variables>`_.
+
+**Building using make**
+
+CMake will generate a Makefile and other configuration files for the build. As a rule of thumb, you should configure the
+build *outside of the source tree* in order to keep different configurations isolated. If you are unsure where to
+execute the build, just use a temporary directory:
+
+.. code-block:: bash
+
+ cd $(mktemp -d /tmp/cbor_build.XXXX)
+
+Now, assuming you are in the directory where you want to build, build libcbor as a **static library**:
+
+.. code-block:: bash
+
+ cmake -DCMAKE_BUILD_TYPE=Release path_to_libcbor_dir
+ make cbor
+
+... or as a **dynamic library**:
+
+.. code-block:: bash
+
+ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON path_to_libcbor_dir
+ make cbor
+
+To install locally:
+
+.. code-block:: bash
+
+ make install
+
+Root permissions are required on most systems when using the default installation prefix.
+
+
+**Portability**
+
+libcbor is highly portable and works on both little- and big-endian systems regardless of the operating system. After building
+on an exotic platform, you might wish to verify the result by running the :doc:`test suite </tests>`. If you encounter any problems, please
+report them to the `issue tracker <https://github.com/PJK/libcbor/issues>`_.
+
+libcbor is known to successfully work on ARM Android devices. Cross-compilation is possible with ``arm-linux-gnueabi-gcc``.
+
+
+Linking with libcbor
+---------------------
+
+If you include and linker paths include the directories to which libcbor has been installed, compiling programs that uses libcbor requires
+no extra considerations.
+
+You can verify that everything has been set up properly by creating a file with the following contents
+
+.. code-block:: c
+
+ #include <cbor.h>
+ #include <stdio.h>
+
+ int main(int argc, char * argv[])
+ {
+ printf("Hello from libcbor %s\n", CBOR_VERSION);
+ }
+
+
+and compiling it
+
+.. code-block:: bash
+
+ cc hello_cbor.c -lcbor -o hello_cbor
+
+
+libcbor also comes with `pkg-config <https://wiki.freedesktop.org/www/Software/pkg-config/>`_ support. If you install libcbor with a custom prefix, you can use pkg-config to resolve the headers and objects:
+
+.. code-block:: bash
+
+ cc $(pkg-config --cflags libcbor) hello_cbor.c $(pkg-config --libs libcbor) -o hello_cbor
+
+
+**A note on linkage**
+
+libcbor is primarily intended to be linked statically. The shared library versioning scheme generally follows `SemVer <https://semver.org/>`_, but is irregular for the 0.X.Y development branch for historical reasons. The following version identifiers are used as a part of the SONAME (Linux) or the dylib `"Compatibility version" <https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/CreatingDynamicLibraries.html>`_ (OS X):
+
+ - 0.Y for the 0.Y.Z branch. Patches are backwards compatible, minor releases are generally not and require re-compilation of any dependent code.
+ - X for the X.Y.Z stable versions starting 1.X.Y. All minor release of the major version are backwards compatible.
+
+.. warning:: Please note that releases up to and including v0.6.0 `may export misleading .so/.dylib version number <https://github.com/PJK/libcbor/issues/52>`_.
+
+
+Troubleshooting
+---------------------
+
+**cbor.h not found**: The headers directory is probably not in your include path. First, verify the installation
+location by checking the installation log. If you used make, it will look something like
+
+.. code-block:: text
+
+ ...
+ -- Installing: /usr/local/include/cbor
+ -- Installing: /usr/local/include/cbor/callbacks.h
+ -- Installing: /usr/local/include/cbor/encoding.h
+ ...
+
+Make sure that ``CMAKE_INSTALL_PREFIX`` (if you provided it) was correct. Including the path path during compilation should suffice, e.g.:
+
+.. code-block:: bash
+
+ cc -I/usr/local/include hello_cbor.c -lcbor -o hello_cbor
+
+
+**cannot find -lcbor during linking**: Most likely the same problem as before. Include the installation directory in the
+linker shared path using ``-R``, e.g.:
+
+.. code-block:: bash
+
+ cc -Wl,-rpath,/usr/local/lib -lcbor -o hello_cbor
+
+**shared library missing during execution**: Verify the linkage using ``ldd``, ``otool``, or similar and adjust the compilation directives accordingly:
+
+.. code-block:: text
+
+ ⇒ ldd hello_cbor
+ linux-vdso.so.1 => (0x00007ffe85585000)
+ libcbor.so => /usr/local/lib/libcbor.so (0x00007f9af69da000)
+ libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9af65eb000)
+ /lib64/ld-linux-x86-64.so.2 (0x00007f9af6be9000)
+
+**compilation failed**: If your compiler supports C99 yet the compilation has failed, please report the issue to the `issue tracker <https://github.com/PJK/libcbor/issues>`_.
diff --git a/doc/source/img/win_1.png b/doc/source/img/win_1.png
new file mode 100644
index 000000000000..1bc34e5f8de5
--- /dev/null
+++ b/doc/source/img/win_1.png
Binary files differ
diff --git a/doc/source/img/win_2.png b/doc/source/img/win_2.png
new file mode 100644
index 000000000000..f6af59949df6
--- /dev/null
+++ b/doc/source/img/win_2.png
Binary files differ
diff --git a/doc/source/img/win_3.png b/doc/source/img/win_3.png
new file mode 100644
index 000000000000..68ba112cbae0
--- /dev/null
+++ b/doc/source/img/win_3.png
Binary files differ
diff --git a/doc/source/img/win_4.png b/doc/source/img/win_4.png
new file mode 100644
index 000000000000..b274be7d530b
--- /dev/null
+++ b/doc/source/img/win_4.png
Binary files differ
diff --git a/doc/source/img/win_5.png b/doc/source/img/win_5.png
new file mode 100644
index 000000000000..dffeb882f744
--- /dev/null
+++ b/doc/source/img/win_5.png
Binary files differ
diff --git a/doc/source/img/win_6.png b/doc/source/img/win_6.png
new file mode 100644
index 000000000000..850e3e2f6cc8
--- /dev/null
+++ b/doc/source/img/win_6.png
Binary files differ
diff --git a/doc/source/index.rst b/doc/source/index.rst
new file mode 100644
index 000000000000..1922586097e3
--- /dev/null
+++ b/doc/source/index.rst
@@ -0,0 +1,40 @@
+libcbor
+===================================
+
+Documentation for version |release|, updated on |today|.
+
+Overview
+--------
+*libcbor* is a C library for parsing and generating CBOR_, the general-purpose schema-less binary data format.
+
+
+Main features
+ - Complete RFC conformance [#]_
+ - Robust C99 implementation
+ - Layered architecture offers both control and convenience
+ - Flexible memory management
+ - No shared global state - threading friendly [#]_
+ - Proper handling of UTF-8
+ - Full support for streams & incremental processing
+ - Extensive documentation and test suite
+ - No runtime dependencies, small footprint
+
+.. [#] See :doc:`rfc_conformance`
+
+.. [#] With the exception of custom memory allocators (see :doc:`api/item_reference_counting`)
+
+Contents
+----------
+.. toctree::
+
+ getting_started
+ using
+ api
+ streaming
+ tests
+ rfc_conformance
+ internal
+ changelog
+ development
+
+.. _CBOR: http://tools.ietf.org/html/rfc7049
diff --git a/doc/source/internal.rst b/doc/source/internal.rst
new file mode 100644
index 000000000000..2c62a82b2329
--- /dev/null
+++ b/doc/source/internal.rst
@@ -0,0 +1,128 @@
+Internal mechanics
+==========================
+
+Internal workings of *libcbor* are mostly derived from the specification. The purpose of this document is to describe technical choices made during design & implementation and to explicate the reasoning behind those choices.
+
+Terminology
+---------------
+=== ====================== ========================================================================================================================================
+MTB Major Type Byte http://tools.ietf.org/html/rfc7049#section-2.1
+--- ---------------------- ----------------------------------------------------------------------------------------------------------------------------------------
+DST Dynamically Sized Type Type whose storage requirements cannot be determined
+
+ during compilation (originated in the `Rust <http://www.rust-lang.org/>`_ community)
+=== ====================== ========================================================================================================================================
+
+Conventions
+--------------
+API symbols start with ``cbor_`` or ``CBOR_`` prefix, internal symbols have ``_cbor_`` or ``_CBOR_`` prefix.
+
+Inspiration & related projects
+-------------------------------
+Most of the API is largely modelled after existing JSON libraries, including
+
+ - `Jansson <http://www.digip.org/jansson/>`_
+ - `json-c <https://github.com/json-c/json-c>`_
+ - Gnome's `JsonGlib <https://wiki.gnome.org/action/show/Projects/JsonGlib?action=show&redirect=JsonGlib>`_
+
+and also borrowing from
+
+ - `msgpack-c <https://github.com/msgpack/msgpack-c>`_
+ - `Google Protocol Buffers <http://code.google.com/p/protobuf/>`_.
+
+General notes on the API design
+--------------------------------
+The API design has two main driving priciples:
+
+ 1. Let the client manage the memory as much as possible
+ 2. Behave exactly as specified by the standard
+
+Combining these two principles in practice turns out to be quite difficult. Indefinite-length strings, arrays, and maps require client to handle every fixed-size chunk explicitly in order to
+
+ - ensure the client never runs out of memory due to *libcbor*
+ - use :func:`realloc` sparsely and predictably [#]_
+
+ - provide strong guarantees about its usage (to prevent latency spikes)
+ - provide APIs to avoid :func:`realloc` altogether
+ - allow proper handling of (streamed) data bigger than available memory
+
+ .. [#] Reasonable handling of DSTs requires reallocation if the API is to remain sane.
+
+
+Coding style
+-------------
+This code loosely follows the `Linux kernel coding style <https://www.kernel.org/doc/Documentation/CodingStyle>`_. Tabs are tabs, and they are 4 characters wide.
+
+
+Memory layout
+---------------
+CBOR is very dynamic in the sense that it contains many data elements of variable length, sometimes even indefinite length. This section describes internal representation of all CBOR data types.
+
+Generally speaking, data items consist of three parts:
+
+ - a generic :type:`handle <cbor_item_t>`,
+ - the associated :type:`metadata <cbor_item_metadata>`,
+ - and the actual data
+
+.. type:: cbor_item_t
+
+ Represents the item. Used as an opaque type
+
+ .. member:: cbor_type type
+
+ Type discriminator
+
+ .. member:: size_t refcount
+
+ Reference counter. Used by :func:`cbor_decref`, :func:`cbor_incref`
+
+ .. member:: union cbor_item_metadata metadata
+
+ Union discriminated by :member:`type`. Contains type-specific metadata
+
+ .. member:: unsigned char * data
+
+ Contains pointer to the actual data. Small, fixed size items (:doc:`api/type_0_1`, :doc:`api/type_6`, :doc:`api/type_7`) are allocated as a single memory block.
+
+ Consider the following snippet
+
+ .. code-block:: c
+
+ cbor_item_t * item = cbor_new_int8();
+
+ then the memory is laid out as follows
+
+ ::
+
+ +-----------+---------------+---------------+-----------------------------------++-----------+
+ | | | | || |
+ | type | refcount | metadata | data || uint8_t |
+ | | | | (= item + sizeof(cbor_item_t)) || |
+ +-----------+---------------+---------------+-----------------------------------++-----------+
+ ^ ^
+ | |
+ +--- item +--- item->data
+
+ Dynamically sized types (:doc:`api/type_2`, :doc:`api/type_3`, :doc:`api/type_4`, :doc:`api/type_5`) may store handle and data in separate locations. This enables creating large items (e.g :doc:`byte strings <api/type_2>`) without :func:`realloc` or copying large blocks of memory. One simply attaches the correct pointer to the handle.
+
+
+.. type:: cbor_item_metadata
+
+ Union type of the following members, based on the item type:
+
+ .. member:: struct _cbor_int_metadata int_metadata
+
+ Used both by both :doc:`api/type_0_1`
+
+ .. member:: struct _cbor_bytestring_metadata bytestring_metadata
+ .. member:: struct _cbor_string_metadata string_metadata
+ .. member:: struct _cbor_array_metadata array_metadata
+ .. member:: struct _cbor_map_metadata map_metadata
+ .. member:: struct _cbor_tag_metadata tag_metadata
+ .. member:: struct _cbor_float_ctrl_metadata float_ctrl_metadata
+
+Decoding
+---------
+
+As outlined in :doc:`api`, there decoding is based on the streaming decoder Essentially, the decoder is a custom set of callbacks for the streaming decoder.
+
diff --git a/doc/source/requirements.txt b/doc/source/requirements.txt
new file mode 100644
index 000000000000..461bb7e804d2
--- /dev/null
+++ b/doc/source/requirements.txt
@@ -0,0 +1,39 @@
+alabaster==0.7.12
+argh==0.26.2
+Babel==2.8.0
+breathe==4.14.1
+certifi==2019.11.28
+chardet==3.0.4
+Click==7.0
+docutils==0.16
+Flask==1.1.1
+idna==2.9
+imagesize==1.2.0
+itsdangerous==1.1.0
+Jinja2==2.10.1
+livereload==2.6.1
+MarkupSafe==1.1.1
+packaging==20.3
+pathtools==0.1.2
+port-for==0.3.1
+Pygments==2.6.1
+pyparsing==2.4.6
+pytz==2019.3
+PyYAML==5.3
+requests==2.23.0
+six==1.14.0
+snowballstemmer==2.0.0
+sortedcontainers==2.1.0
+Sphinx==2.4.4
+sphinx-autobuild==0.7.1
+sphinx-rtd-theme==0.4.3
+sphinxcontrib-applehelp==1.0.2
+sphinxcontrib-devhelp==1.0.2
+sphinxcontrib-htmlhelp==1.0.3
+sphinxcontrib-jsmath==1.0.1
+sphinxcontrib-qthelp==1.0.3
+sphinxcontrib-serializinghtml==1.1.4
+tornado==6.0.4
+urllib3==1.25.8
+watchdog==0.10.2
+Werkzeug==0.15.5
diff --git a/doc/source/rfc_conformance.rst b/doc/source/rfc_conformance.rst
new file mode 100644
index 000000000000..817614835a1f
--- /dev/null
+++ b/doc/source/rfc_conformance.rst
@@ -0,0 +1,17 @@
+RFC conformance
+=========================
+
+*libcbor* is, generally speaking, very faithful implementation of `RFC 7049 <http://tools.ietf.org/html/rfc7049>`_. There are, however, some limitations imposed by technical constraints.
+
+Bytestring length
+-------------------
+There is no explicit limitation of indefinite length byte strings. [#]_ *libcbor* will not handle byte strings with more chunks than the maximum value of :type:`size_t`. On any sane platform, such string would not fit in the memory anyway. It is, however, possible to process arbitrarily long strings and byte strings using the streaming decoder.
+
+.. [#] http://tools.ietf.org/html/rfc7049#section-2.2.2
+
+"Half-precision" IEEE 754 floats
+---------------------------------
+As of C99 and even C11, there is no standard implementation for 2 bytes floats. *libcbor* packs them as a `float <https://en.cppreference.com/w/c/language/type>`. When encoding, *libcbor* selects the appropriate wire representation based on metadata and the actual value. This applies both to canonical and normal mode.
+
+For more information on half-float serialization, please refer to the section on :ref:`api_type_7_hard_floats`.
+
diff --git a/doc/source/streaming.rst b/doc/source/streaming.rst
new file mode 100644
index 000000000000..8e3bb0d9bade
--- /dev/null
+++ b/doc/source/streaming.rst
@@ -0,0 +1,13 @@
+Streaming & indefinite items
+=============================
+
+CBOR :doc:`strings <api/type_2>`, :doc:`byte strings <api/type_3>`, :doc:`arrays <api/type_4>`, and :doc:`maps <api/type_5>` can be encoded as *indefinite*, meaning their length or size is not specified. Instead, they are divided into *chunks* (:doc:`strings <api/type_2>`, :doc:`byte strings <api/type_3>`), or explicitly terminated (:doc:`arrays <api/type_4>`, :doc:`maps <api/type_5>`).
+
+This is one of the most important (and due to poor implementations, underutilized) features of CBOR. It enables low-overhead streaming just about anywhere without dealing with channels or pub/sub mechanism. It is, however, important to recognize that CBOR streaming is not a substitute for Websockets [#]_ and similar technologies.
+
+.. [#] :RFC:`6455`
+
+.. toctree::
+
+ streaming/decoding
+ streaming/encoding
diff --git a/doc/source/streaming/decoding.rst b/doc/source/streaming/decoding.rst
new file mode 100644
index 000000000000..70174aa2715d
--- /dev/null
+++ b/doc/source/streaming/decoding.rst
@@ -0,0 +1,40 @@
+Decoding
+=============================
+
+Another way to decode data using libcbor is to specify a callbacks that will be invoked when upon finding certain items in the input. This API is provided by
+
+.. doxygenfunction:: cbor_stream_decode
+
+Usage example: https://github.com/PJK/libcbor/blob/master/examples/streaming_parser.c
+
+The callbacks are defined by
+
+.. doxygenstruct:: cbor_callbacks
+ :members:
+
+When building custom sets of callbacks, feel free to start from
+
+.. doxygenvariable:: cbor_empty_callbacks
+
+Related structures
+~~~~~~~~~~~~~~~~~~~~~
+
+.. doxygenenum:: cbor_decoder_status
+.. doxygenstruct:: cbor_decoder_result
+ :members:
+
+
+Callback types definition
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+.. doxygentypedef:: cbor_int8_callback
+.. doxygentypedef:: cbor_int16_callback
+.. doxygentypedef:: cbor_int32_callback
+.. doxygentypedef:: cbor_int64_callback
+.. doxygentypedef:: cbor_simple_callback
+.. doxygentypedef:: cbor_string_callback
+.. doxygentypedef:: cbor_collection_callback
+.. doxygentypedef:: cbor_float_callback
+.. doxygentypedef:: cbor_double_callback
+.. doxygentypedef:: cbor_bool_callback
diff --git a/doc/source/streaming/encoding.rst b/doc/source/streaming/encoding.rst
new file mode 100644
index 000000000000..8a56461d3584
--- /dev/null
+++ b/doc/source/streaming/encoding.rst
@@ -0,0 +1,4 @@
+Encoding
+=============================
+
+TODO
diff --git a/doc/source/tests.rst b/doc/source/tests.rst
new file mode 100644
index 000000000000..47357ba36cd6
--- /dev/null
+++ b/doc/source/tests.rst
@@ -0,0 +1,39 @@
+Tests
+=============
+
+Unit tests
+--------------
+
+There is a comprehensive test suite employing CMocka_. You can run all of them using ``ctest`` in the build directory. Individual tests are themselves runnable. Please refer to `CTest <http://www.cmake.org/Wiki/CMake/Testing_With_CTest>`_ documentation for detailed information on how to specify particular subset of tests.
+
+.. _CMocka: http://cmocka.org/
+
+Testing for memory leaks
+------------------------
+
+Every release is tested for memory correctness. You can run these tests by passing the ``-T memcheck`` flag to ``ctest``. [#]_
+
+.. [#] Project should be configured with ``-DCMAKE_BUILD_TYPE=Debug`` to obtain meaningful description of location of the leak. You might also need ``--dsymutil=yes`` on OS X.
+
+
+Code coverage
+-------------------
+
+Every release is inspected using `GCOV/LCOV <http://ltp.sourceforge.net/coverage/lcov.php>`_. Platform-independent code should be fully covered by the test suite. Simply run
+
+.. code-block:: bash
+
+ make coverage
+
+
+or alternatively run ``lcov`` by hand using
+
+.. code-block:: bash
+
+ lcov --capture --directory . --output-file coverage.info
+ genhtml coverage.info --output-directory out
+
+Fuzz testing
+-----------------
+
+Every release is tested using a fuzz test. In this test, a huge buffer filled with random data is passed to the decoder. We require that it either succeeds or fail with a sensible error, without leaking any memory. This is intended to simulate real-world situations where data received from the network are CBOR-decoded before any further processing.
diff --git a/doc/source/using.rst b/doc/source/using.rst
new file mode 100644
index 000000000000..dbc09819d46b
--- /dev/null
+++ b/doc/source/using.rst
@@ -0,0 +1,173 @@
+Usage & preliminaries
+=======================
+
+Version information
+--------------------
+
+libcbor exports its version using three self-explanatory macros:
+
+ - ``CBOR_MAJOR_VERSION``
+ - ``CBOR_MINOR_VERSION``
+ - ``CBOR_PATCH_VERSION``
+
+The ``CBOR_VERSION`` is a string concatenating these three identifiers into one (e.g. ``0.2.0``).
+
+In order to simplify version comparisons, the version is also exported as
+
+.. code-block:: c
+
+ #define CBOR_HEX_VERSION ((CBOR_MAJOR_VERSION << 16) | (CBOR_MINOR_VERSION << 8) | CBOR_PATCH_VERSION)
+
+Since macros are difficult to work with through FFIs, the same information is also available through three ``uint8_t`` constants,
+namely
+
+ - ``cbor_major_version``
+ - ``cbor_minor_version``
+ - ``cbor_patch_version``
+
+
+Headers to include
+---------------------
+
+The ``cbor.h`` header includes all the symbols. If, for any reason, you don't want to include all the exported symbols,
+feel free to use just some of the ``cbor/*.h`` headers:
+
+ - ``cbor/arrays.h`` - :doc:`api/type_4`
+ - ``cbor/bytestrings.h`` - :doc:`api/type_2`
+ - ``cbor/callbacks.h`` - Callbacks used for :doc:`streaming/decoding`
+ - ``cbor/common.h`` - Common utilities - always transitively included
+ - ``cbor/data.h`` - Data types definitions - always transitively included
+ - ``cbor/encoding.h`` - Streaming encoders for :doc:`streaming/encoding`
+ - ``cbor/floats_ctrls.h`` - :doc:`api/type_7`
+ - ``cbor/ints.h`` - :doc:`api/type_0_1`
+ - ``cbor/maps.h`` - :doc:`api/type_5`
+ - ``cbor/serialization.h`` - High level serialization such as :func:`cbor_serialize`
+ - ``cbor/streaming.h`` - Home of :func:`cbor_stream_decode`
+ - ``cbor/strings.h`` - :doc:`api/type_3`
+ - ``cbor/tags.h`` - :doc:`api/type_6`
+
+
+Using libcbor
+--------------
+
+If you want to get more familiar with CBOR, we recommend the `cbor.io <http://cbor.io/>`_ website. Once you get the grasp
+of what is it CBOR does, the examples (located in the ``examples`` directory) should give you a good feel of the API. The
+:doc:`API documentation <api>` should then provide with all the information you may need.
+
+
+**Creating and serializing items**
+
+.. code-block:: c
+
+ #include "cbor.h"
+ #include <stdio.h>
+
+ int main(int argc, char * argv[])
+ {
+ /* Preallocate the map structure */
+ cbor_item_t * root = cbor_new_definite_map(2);
+ /* Add the content */
+ cbor_map_add(root, (struct cbor_pair) {
+ .key = cbor_move(cbor_build_string("Is CBOR awesome?")),
+ .value = cbor_move(cbor_build_bool(true))
+ });
+ cbor_map_add(root, (struct cbor_pair) {
+ .key = cbor_move(cbor_build_uint8(42)),
+ .value = cbor_move(cbor_build_string("Is the answer"))
+ });
+ /* Output: `length` bytes of data in the `buffer` */
+ unsigned char * buffer;
+ size_t buffer_size, length = cbor_serialize_alloc(root, &buffer, &buffer_size);
+
+ fwrite(buffer, 1, length, stdout);
+ free(buffer);
+
+ fflush(stdout);
+ cbor_decref(&root);
+ }
+
+
+**Reading serialized data**
+
+.. code-block:: c
+
+ #include "cbor.h"
+ #include <stdio.h>
+
+ /*
+ * Reads data from a file. Example usage:
+ * $ ./examples/readfile examples/data/nested_array.cbor
+ */
+
+ int main(int argc, char * argv[])
+ {
+ FILE * f = fopen(argv[1], "rb");
+ fseek(f, 0, SEEK_END);
+ size_t length = (size_t)ftell(f);
+ fseek(f, 0, SEEK_SET);
+ unsigned char * buffer = malloc(length);
+ fread(buffer, length, 1, f);
+
+ /* Assuming `buffer` contains `info.st_size` bytes of input data */
+ struct cbor_load_result result;
+ cbor_item_t * item = cbor_load(buffer, length, &result);
+ /* Pretty-print the result */
+ cbor_describe(item, stdout);
+ fflush(stdout);
+ /* Deallocate the result */
+ cbor_decref(&item);
+
+ fclose(f);
+ }
+
+
+**Using the streaming parser**
+
+.. code-block:: c
+
+ #include "cbor.h"
+ #include <stdio.h>
+ #include <string.h>
+
+ /*
+ * Illustrates how one might skim through a map (which is assumed to have
+ * string keys and values only), looking for the value of a specific key
+ *
+ * Use the examples/data/map.cbor input to test this.
+ */
+
+ const char * key = "a secret key";
+ bool key_found = false;
+
+ void find_string(void * _ctx, cbor_data buffer, size_t len)
+ {
+ if (key_found) {
+ printf("Found the value: %*s\n", (int) len, buffer);
+ key_found = false;
+ } else if (len == strlen(key)) {
+ key_found = (memcmp(key, buffer, len) == 0);
+ }
+ }
+
+ int main(int argc, char * argv[])
+ {
+ FILE * f = fopen(argv[1], "rb");
+ fseek(f, 0, SEEK_END);
+ size_t length = (size_t)ftell(f);
+ fseek(f, 0, SEEK_SET);
+ unsigned char * buffer = malloc(length);
+ fread(buffer, length, 1, f);
+
+ struct cbor_callbacks callbacks = cbor_empty_callbacks;
+ struct cbor_decoder_result decode_result;
+ size_t bytes_read = 0;
+ callbacks.string = find_string;
+ while (bytes_read < length) {
+ decode_result = cbor_stream_decode(buffer + bytes_read,
+ length - bytes_read,
+ &callbacks, NULL);
+ bytes_read += decode_result.read;
+ }
+
+ fclose(f);
+ }