This commit is contained in:
Roman Isaikin
2015-07-12 22:35:34 +03:00
parent 4258811d95
commit d868f78621
6 changed files with 407 additions and 9 deletions

2
doc/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
_build/
!Makefile

194
doc/Makefile Normal file
View File

@ -0,0 +1,194 @@
# 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) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage 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 " applehelp to make an Apple Help Book"
@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)"
@echo " coverage to run coverage check of 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/qmsgpack.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/qmsgpack.qhc"
applehelp:
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
@echo
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
@echo "N.B. You won't be able to view it unless you put it in" \
"~/Library/Documentation/Help or install it in your application" \
"bundle."
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/qmsgpack"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/qmsgpack"
@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."
coverage:
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
@echo "Testing of coverage in the sources finished, look at the " \
"results in $(BUILDDIR)/coverage/python.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."
include sphinx_deployment.mk

91
doc/basics.rst Normal file
View File

@ -0,0 +1,91 @@
Basics
------
.. contents::
:depth: 4
Standard types
==============
Below are Qt equivalents to MessagePack types listed in `spec <https://github.com/msgpack/msgpack/blob/master/spec.md>`_:
================ ==============
MessagePack type Qt or C++ type
================ ==============
positive fixint quint8
fixmap, map QMap, QHash
fixarray,array QList
fixstr, str QString
nil QVariant()
false, true bool
bin QByteArray
float 32 float
float 64 double
uint 8 quint8
uint 16 quint16
uint 32 quint32
uint 64 quint64
int 8 qint8
int 16 qint16
int 32 qint32, int
int 64 qint64
negative fixint qint8
================ ==============
You can pack and unpack any of those types right away:
Packing
^^^^^^^
Pass QVariant to ``MsgPack::pack()`` function:
.. code-block:: cpp
QVariant v = 123;
QByteArray packed = MsgPack::pack(v);
qDebug() << packed.toHex();
Of course QVariant can contain a QVarianList or a QVariantMap:
.. code-block:: cpp
QList<QVariant> list;
list << 123 << 4.56 << true;
QByteArray packed = MsgPack::pack(list);
qDebug() << packed.toHex();
.. note::
If you want to pack QList<int> for example see: REF TO MsgPackStream
Unpacking
^^^^^^^^^
Unpacking is handled by ``MsgPack::unpack()`` function:
.. code-block:: cpp
QByteArray packed = MsgPack::pack("qwerty");
QVariant unpacked = MsgPack::unpack(packed);
qDebug() << unpacked.toString();
.. tip::
If packed data contains only one msgpack type (fixstr of fixmap for example), unpack will return it as ``QVariant(QString())`` and ``QVariant(QMap())`` respectively.
But if there are several values packed, ``QVariant(QList())`` will be returned (consider this 5 bool values packed without msgpack's list: [0xc3, 0xc3, 0xc3, 0xc3, 0xc3])
Thread safety
=============
All methods are thread safe, except ``MsgPack::setCompatibilityModeEnabled`` which is not.
``pack()`` and ``unpack()`` do not use any global variables except user packers and unpackers, access to them is controlled via QReadLocker (and QWriteLocker when registering a new one), so readers do not block each other.
.. warning::
User packers and unpackers can break thread-safety! But in most cases they are so simple, so this is not a problem.
Compatibility mode
==================
You can enable compatibility mode this way: ``MsgPack::setCompatibilityModeEnabled(true)``, after that there will be no str8, and QByteArray will be packed to str.

View File

@ -1,10 +1,11 @@
.. qmsgpack documentation master file, created by
sphinx-quickstart on Sun Jun 28 11:29:36 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
qmsgpack - MessagePack serializer implementation for Qt
=======================================================
Welcome to qmsgpack's documentation!
====================================
.. toctree::
:hidden:
install.rst
basics.rst
Contents:

110
doc/install.rst Normal file
View File

@ -0,0 +1,110 @@
Installation
------------
.. contents::
:depth: 4
qmsgpack is a pure Qt library (Qt4 and Qt5 supported), so you can build it for almost any platform Qt supports.
Also there are several build options:
- CMake
- qmake
And two ways of using it: build separately and include to your project, or build with your project (qmake subdirs)
Build
=====
CMake
^^^^^
Get the latest qmsgpack version by grabbing the source code from GitHub:
.. code-block:: bash
$ git clone https://github.com/romixlab/qmsgpack.git
Now build and install it:
.. code-block:: bash
cd qmsgpack
mkdir build && cd build
cmake ..
make
sudo make install
There are several useful cmake options available:
.. cmdoption:: -DBUILD_TESTS=True
Build all the tests, run with ``make tests``
.. cmdoption:: -DCMAKE_INSTALL_PREFIX=/usr
Change install location to `/usr`
.. cmdoption:: -DCMAKE_BUILD_TYPE=Debug
Change build type to debug mode (default is `Release`), could be very useful if something goes wrong
Add options before ``..`` as follow:
.. code-block:: bash
cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_TESTS=True ..
qmake
^^^^^
Get the latest qmsgpack version by grabbing the source code from GitHub:
.. code-block:: bash
$ git clone https://github.com/romixlab/qmsgpack.git
Now build and install it:
.. code-block:: bash
cd qmsgpack
qmake
make
sudo make install
Also you can just open ``qmsgpack.pro`` in Qt Creator and build it from there.
Use it
======
Separate build
^^^^^^^^^^^^^^
In case of CMake and qmake build, just add following lines to your .pro file:
.. code-block:: makefile
LIBS += -lqmsgpack
On Windows you may also set the ``INCLUDEPATH`` variable to appropriate location
qmake subproject
^^^^^^^^^^^^^^^^
If you are working on a bigger Qt project, building qmsgpack with your project automatically can be very neat feature.
Below are the list of variables that allows you to do it:
.. cmdoption:: QMSGPACK_SUBPROJECT
Settings this variable to ``true`` changes build and destination folder
.. cmdoption:: QMSGPACK_BUILD_DIR
Build directory, default value: ``../../build/3rdparty``
.. cmdoption:: QMSGPACK_BIN_DIR
Where to put dynamic library file, default value: ``../../bin``
.. tip::
You can use GitHub submodules to automatically clone qmsgpack repository

View File

@ -1,5 +1,5 @@
#ifndef COMMON_H
#define COMMON_H
#ifndef MSGPACK_COMMON_H
#define MSGPACK_COMMON_H
#include <QVariant>
#include <QtGlobal>
@ -69,4 +69,4 @@ const quint8 MAP32 = 0xdf;
const quint8 NEGATIVE_FIXINT = 0xe0;
}
}
#endif // COMMON_H
#endif // MSGPACK_COMMON_H