From 0a2948266538a3a83a280fb70bbfe6c9899f05e5 Mon Sep 17 00:00:00 2001 From: bigbes <bigbes@gmail.com> Date: Fri, 29 Jan 2016 23:35:19 +0300 Subject: [PATCH] Fix documentation markup --- doc/sphinx/book/administration.rst | 38 ++++-- doc/sphinx/book/app/c_lua_tutorial.rst | 8 +- doc/sphinx/book/box/box_index.rst | 18 ++- doc/sphinx/book/box/box_schema.rst | 137 +++++++++++--------- doc/sphinx/book/box/box_space.rst | 2 +- doc/sphinx/book/connectors/__c.rst | 172 +++++++++++++++---------- doc/sphinx/dev_guide/box-protocol.rst | 6 +- doc/sphinx/reference/msgpack.rst | 82 +++++++----- doc/sphinx/reference/net_box.rst | 2 +- 9 files changed, 279 insertions(+), 186 deletions(-) diff --git a/doc/sphinx/book/administration.rst b/doc/sphinx/book/administration.rst index 236d7c94c0..693d540077 100644 --- a/doc/sphinx/book/administration.rst +++ b/doc/sphinx/book/administration.rst @@ -9,17 +9,30 @@ reloading configuration, taking snapshots, log rotation. Server signal handling ===================================================================== -The server processes these signals during the main thread event loop: |br| -SIGHUP: may cause log file rotation, see :ref:`the example in section "Logging" <logging_example>`. |br| -SIGUSR1: may cause saving of a snapshot, see the description of :func:`box.snapshot`. |br| -SIGTERM: may cause graceful shutdown (information will be saved first). |br| -SIGINT also known as keyboard interrupt: may cause graceful shutdown. |br| -SIGKILL: causes shutdown. |br| +The server processes these signals during the main thread event loop: -Other signals will result in behavior defined by the operating system. -Signals other than SIGKILL may be ignored, especially if the -server is executing a long-running procedure which -prevents return to the main thread event loop. +.. glossary:: + + SIGHUP + may cause log file rotation, see + :ref:`the example in section "Logging" <logging_example>`. + + SIGUSR1 + may cause saving of a snapshot, see the description of + :func:`box.snapshot`. + + SIGTERM + may cause graceful shutdown (information will be saved first). + + SIGINT + (also known as keyboard interrupt) may cause graceful shutdown. + + SIGKILL + causes shutdown. + +Other signals will result in behavior defined by the operating system. Signals +other than SIGKILL may be ignored, especially if the server is executing a +long-running procedure which prevents return to the main thread event loop. ===================================================================== @@ -313,9 +326,10 @@ A user can initiate, for boot time, an init.d set of instructions: A user can set up a further configuration file for log rotation, like this: -.. code-block:: lua +.. cssclass:: highlight +.. parsed-literal:: - /path/to/tarantool/*.log { + /path/to/tarantool/\*.log { daily size 512k missingok diff --git a/doc/sphinx/book/app/c_lua_tutorial.rst b/doc/sphinx/book/app/c_lua_tutorial.rst index 2c9d4398ad..6e95ecc788 100644 --- a/doc/sphinx/book/app/c_lua_tutorial.rst +++ b/doc/sphinx/book/app/c_lua_tutorial.rst @@ -505,11 +505,10 @@ that are declared in line 1, because all of them are for use only within the fun **LINE 5: WHY "PAIRS()".** Our job is to go through all the rows and there are two ways to do it: with :func:`box.space.space_object:pairs() <space_object.pairs>` or with -:code:`variable = select(...)` followed by -:codenormal:`for i,`:codeitalic:`n`:codenormal:`,1 do` :codeitalic:`some-function`:codenormal:`(variable[i]) end`. +``variable = select(...)`` followed by :samp:`for i, {n}, 1 do {some-function}(variable[i]) end`. We preferred ``pairs()`` for this example. -**LINE 5: START THE MAIN LOOP.** Everything inside this ":code:`for`" loop will be +**LINE 5: START THE MAIN LOOP.** Everything inside this "``for``" loop will be repeated as long as there is another index key. A tuple is fetched and can be referenced with variable :code:`t`. @@ -527,7 +526,8 @@ where the JSON string was inserted. For example, we're assuming a tuple looks li .. _protected call: http://www.lua.org/pil/8.4.html -.. code-block:: json +.. cssclass:: highlight +.. parsed-literal:: field[1]: 444 field[2]: '{"Hello": "world", "Quantity": 15}' diff --git a/doc/sphinx/book/box/box_index.rst b/doc/sphinx/book/box/box_index.rst index 785e127159..07b3c851bd 100644 --- a/doc/sphinx/book/box/box_index.rst +++ b/doc/sphinx/book/box/box_index.rst @@ -30,8 +30,6 @@ API is a direct binding to corresponding methods of index objects of type * :samp:`{index_object}` = an :ref:`object reference <object-reference>`. - :rtype: - .. data:: parts An array describing index key fields. @@ -95,9 +93,9 @@ API is a direct binding to corresponding methods of index objects of type Complexity Factors: Index size, Index type, Number of tuples accessed. - A search-value can be a number (for example :codenormal:`1234`), a string - (for example :codenormal:`'abcd'`), - or a table of numbers and strings (for example :codenormal:`{1234,'abcd'}`). + A search-value can be a number (for example ``1234``), a string + (for example ``'abcd'``), + or a table of numbers and strings (for example ``{1234, 'abcd'}``). Each part of a search-value will be compared to each part of an index key. .. container:: table @@ -481,7 +479,7 @@ API is a direct binding to corresponding methods of index objects of type Complexity Factors: Index size, Index type. - Note re storage engine: sophia does not support :codenormal:`min()`. + Note re storage engine: sophia does not support ``min()``. **Example:** @@ -512,7 +510,7 @@ API is a direct binding to corresponding methods of index objects of type Complexity Factors: Index size, Index type. - Note re storage engine: sophia does not support :codenormal:`max()`. + Note re storage engine: sophia does not support ``max()``. **Example:** @@ -541,7 +539,7 @@ API is a direct binding to corresponding methods of index objects of type Complexity Factors: Index size, Index type. - Note re storage engine: sophia does not support :codenormal:`random()`. + Note re storage engine: sophia does not support ``random()``. **Example:** @@ -571,7 +569,7 @@ API is a direct binding to corresponding methods of index objects of type is only applicable for the memtx storage engine. :rtype: number - Note re storage engine: sophia does not support :codenormal:`count()`. + Note re storage engine: sophia does not support ``count()``. **Example:** @@ -640,7 +638,7 @@ API is a direct binding to corresponding methods of index objects of type the first index cannot be changed to {unique = false}, or the alter function is only applicable for the memtx storage engine. - Note re storage engine: sophia does not support :codenormal:`alter()`. + Note re storage engine: sophia does not support ``alter()``. **Example:** diff --git a/doc/sphinx/book/box/box_schema.rst b/doc/sphinx/book/box/box_schema.rst index f167140de7..87a8c291ee 100644 --- a/doc/sphinx/book/box/box_schema.rst +++ b/doc/sphinx/book/box/box_schema.rst @@ -47,8 +47,7 @@ for spaces, users, roles, and function tuples. :param num space-id: the numeric identifier established by box.schema.space.create Note: for symmetry, there are other box.schema functions targeting - space objects, for example - :codenormal:`box.schema.space.drop(`:codeitalic:`space-id`:codenormal:`)` + space objects, for example :samp:`box.schema.space.drop({space-id})` will drop a space. However, the common approach is to use functions attached to the space objects, for example :func:`space_object:drop() <space_object.drop>`. @@ -95,10 +94,13 @@ available for insert, select, and all the other :mod:`box.space` functions. :return: nil - Examples: |br| - :codenormal:`box.schema.user.create('Lena')` |br| - :codenormal:`box.schema.user.create('Lena', {password='X'})` |br| - :codenormal:`box.schema.user.create('Lena', {if_not_exists=false})` + **Examples:** + + .. code-block:: lua + + box.schema.user.create('Lena') + box.schema.user.create('Lena', {password = 'X'}) + box.schema.user.create('Lena', {if_not_exists = false}) .. function:: box.schema.user.drop(user-name) @@ -106,10 +108,13 @@ available for insert, select, and all the other :mod:`box.space` functions. For explanation of how Tarantool maintains user data, see section :ref:`Users and the _user space <authentication-users>`. - :param string user-name: the name of the user + :param string user-name: the name of the user + + **Example:** + + .. code-block:: lua - Example: |br| - :codenormal:`box.schema.user.drop('Lena')` + box.schema.user.drop('Lena') .. function:: box.schema.user.exists(user-name) @@ -118,8 +123,11 @@ available for insert, select, and all the other :mod:`box.space` functions. :param string user-name: the name of the user :rtype: bool - Example: |br| - :codenormal:`box.schema.user.exists('Lena')` + **Example:** + + .. code-block:: lua + + box.schema.user.exists('Lena') .. function:: box.schema.user.grant(user-name, privileges) @@ -132,11 +140,12 @@ available for insert, select, and all the other :mod:`box.space` functions. and object-type = 'space' or 'function'. Or: role-name. - Examples: |br| - :codenormal:`box.schema.user.grant('Lena','read', 'space', 'tester')` |br| - :codenormal:`box.schema.user.grant('Lena','execute', 'function', 'f')` |br| - :codenormal:`box.schema.user.grant('Lena','read,write', 'universe')` |br| - :codenormal:`box.schema.user.grant('Lena', 'Accountant')` + **Examples:** + + box.schema.user.grant('Lena', 'read', 'space', 'tester') + box.schema.user.grant('Lena', 'execute', 'function', 'f') + box.schema.user.grant('Lena', 'read,write', 'universe') + box.schema.user.grant('Lena', 'Accountant') .. function:: box.schema.user.revoke(user-name, privileges) @@ -149,11 +158,12 @@ available for insert, select, and all the other :mod:`box.space` functions. and object-type = 'space' or 'function'. Or: role-name. - Examples: |br| - :codenormal:`box.schema.user.revoke('Lena','read', 'space', 'tester')` |br| - :codenormal:`box.schema.user.revoke('Lena','execute', 'function', 'f')` |br| - :codenormal:`box.schema.user.revoke('Lena','read,write', 'universe')` |br| - :codenormal:`box.schema.user.revoke('Lena', 'Accountant')` + **Examples:** + + box.schema.user.revoke('Lena', 'read', 'space', 'tester') + box.schema.user.revoke('Lena', 'execute', 'function', 'f') + box.schema.user.revoke('Lena', 'read,write', 'universe') + box.schema.user.revoke('Lena', 'Accountant') .. function:: box.schema.user.password(password) @@ -162,8 +172,9 @@ available for insert, select, and all the other :mod:`box.space` functions. :param string password: password :rtype: string - Example: |br| - :codenormal:`box.schema.user.password('ЛЕÐÐ')` + **Example:** + + box.schema.user.password('ЛЕÐÐ') .. function:: box.schema.user.passwd([user-name,] password) @@ -177,9 +188,10 @@ available for insert, select, and all the other :mod:`box.space` functions. :param string user-name: user-name :param string password: password - Examples: |br| - :codenormal:`box.schema.user.passwd('ЛЕÐÐ')` |br| - :codenormal:`box.schema.user.passwd('Lena', 'ЛЕÐÐ')` + **Examples:** + + box.schema.user.passwd('ЛЕÐÐ') + box.schema.user.passwd('Lena', 'ЛЕÐÐ') .. function:: box.schema.user.info([user-name]) @@ -191,9 +203,10 @@ available for insert, select, and all the other :mod:`box.space` functions. will be for the user who is currently logged in. - Example: |br| - :codenormal:`box.schema.user.info()` |br| - :codenormal:`box.schema.user.info('Lena')` + **Example:** + + box.schema.user.info() + box.schema.user.info('Lena') .. function:: box.schema.role.create(role-name [, {options} ]) @@ -207,9 +220,10 @@ available for insert, select, and all the other :mod:`box.space` functions. :return: nil - Examples: |br| - :codenormal:`box.schema.role.create('Accountant')` |br| - :codenormal:`box.schema.role.create('Accountant', {if_not_exists=false})` + **Examples:** + + box.schema.role.create('Accountant') + box.schema.role.create('Accountant', {if_not_exists = false}) .. function:: box.schema.role.drop(role-name) @@ -217,10 +231,11 @@ available for insert, select, and all the other :mod:`box.space` functions. For explanation of how Tarantool maintains role data, see section :ref:`Roles <authentication-roles>`. - :param string role-name: the name of the role + :param string role-name: the name of the role - Example: |br| - :codenormal:`box.schema.role.drop('Accountant')` + **Example:** + + box.schema.role.drop('Accountant') .. function:: box.schema.role.exists(role-name) @@ -229,8 +244,9 @@ available for insert, select, and all the other :mod:`box.space` functions. :param string role-name: the name of the role :rtype: bool - Example: |br| - :codenormal:`box.schema.role.exists('Accountant')` + **Example:** + + box.schema.role.exists('Accountant') .. function:: box.schema.role.grant(role-name, privileges) @@ -243,11 +259,12 @@ available for insert, select, and all the other :mod:`box.space` functions. and object-type = 'space' or 'function'. Or: role-name. - Examples: |br| - :codenormal:`box.schema.role.grant('Accountant','read', 'space', 'tester')` |br| - :codenormal:`box.schema.role.grant('Accountant','execute', 'function', 'f')` |br| - :codenormal:`box.schema.role.grant('Accountant','read,write', 'universe')` |br| - :codenormal:`box.schema.role.grant('public', 'Accountant')` + **Examples:** + + box.schema.role.grant('Accountant', 'read', 'space', 'tester') + box.schema.role.grant('Accountant', 'execute', 'function', 'f') + box.schema.role.grant('Accountant', 'read,write', 'universe') + box.schema.role.grant('public', 'Accountant') .. function:: box.schema.role.revoke(role-name, privileges) @@ -259,11 +276,12 @@ available for insert, select, and all the other :mod:`box.space` functions. 'read' or 'write' or 'execute' or a combination and object-type = 'space' or 'function' - Examples: |br| - :codenormal:`box.schema.role.revoke('Accountant','read', 'space', 'tester')` |br| - :codenormal:`box.schema.role.revoke('Accountant','execute', 'function', 'f')` |br| - :codenormal:`box.schema.role.revoke('Accountant','read,write', 'universe')` |br| - :codenormal:`box.schema.role.revoke('public', 'Accountant')` + **Examples:** + + box.schema.role.revoke('Accountant', 'read', 'space', 'tester') + box.schema.role.revoke('Accountant', 'execute', 'function', 'f') + box.schema.role.revoke('Accountant', 'read,write', 'universe') + box.schema.role.revoke('public', 'Accountant') .. function:: box.schema.role.info([role-name]) @@ -271,8 +289,9 @@ available for insert, select, and all the other :mod:`box.space` functions. :param string role-name: the name of the role. - Example: |br| - :codenormal:`box.schema.role.info('Accountant')` + **Example:** + + box.schema.role.info('Accountant') .. function:: box.schema.func.create(func-name [, {options} ]) @@ -289,11 +308,12 @@ available for insert, select, and all the other :mod:`box.space` functions. :return: nil - Examples: |br| - :codenormal:`box.schema.func.create('calculate')` |br| - :codenormal:`box.schema.func.create('calculate', {if_not_exists=false})` |br| - :codenormal:`box.schema.func.create('calculate', {setuid=false})` |br| - :codenormal:`box.schema.func.create('calculate', {language='LUA'})` + **Examples:** + + box.schema.func.create('calculate') + box.schema.func.create('calculate', {if_not_exists = false}) + box.schema.func.create('calculate', {setuid = false}) + box.schema.func.create('calculate', {language = 'LUA'}) .. function:: box.schema.func.drop(func-name) @@ -303,8 +323,9 @@ available for insert, select, and all the other :mod:`box.space` functions. :param string func-name: the name of the function - Example: |br| - :codenormal:`box.schema.func.drop('calculate')` + **Example:** + + box.schema.func.drop('calculate') .. function:: box.schema.func.exists(func-name) @@ -313,6 +334,6 @@ available for insert, select, and all the other :mod:`box.space` functions. :param string func-name: the name of the function :rtype: bool - Example: |br| - :codenormal:`box.schema.func.exists('calculate')` + **Example:** + box.schema.func.exists('calculate') diff --git a/doc/sphinx/book/box/box_space.rst b/doc/sphinx/book/box/box_space.rst index e459100841..f268efe106 100644 --- a/doc/sphinx/book/box/box_space.rst +++ b/doc/sphinx/book/box/box_space.rst @@ -634,7 +634,7 @@ A list of all ``box.space`` functions follows, then comes a list of all :return: nil - Note re storage engine: sophia does not support :codenormal:`truncate`. + Note re storage engine: sophia does not support ``truncate``. **Example:** diff --git a/doc/sphinx/book/connectors/__c.rst b/doc/sphinx/book/connectors/__c.rst index 6f987c6ecf..eb3c16a832 100644 --- a/doc/sphinx/book/connectors/__c.rst +++ b/doc/sphinx/book/connectors/__c.rst @@ -33,9 +33,12 @@ space :code:`examples` via the high-level C API. tnt_stream_free(tnt); } -.. parsed-literal:: - - :ref:`SETUP <c_setup>`, :ref:`CONNECT <c_connect>`, :ref:`MAKE REQUEST <c_make_request>`, :ref:`SEND REQUEST <c_make_request>`, :ref:`GET REPLY <c_get_reply>`, :ref:`TEARDOWN <c_teardown>` +:ref:`SETUP <c_setup>`,|br| +:ref:`CONNECT <c_connect>`,|br| +:ref:`MAKE REQUEST <c_make_request>`,|br| +:ref:`SEND REQUEST <c_send_request>`,|br| +:ref:`GET REPLY <c_get_reply>`,|br| +:ref:`TEARDOWN <c_teardown>` To prepare, paste the code into a file named example.c and install tarantool-c. One way to install tarantool-c (using Ubuntu) is: @@ -82,9 +85,13 @@ The most important option is TNT_OPT_URI. In this program the URI is ``localhost:3301``, since that is where the Tarantool server is supposed to be listening. -Function description: |br| -:codenormal:`struct tnt_stream *tnt_net(struct tnt_stream *s)` |br| -:codenormal:`int tnt_set(struct tnt_stream *s, int option, variant option-value)` +Function description: + +.. cssclass:: highlight +.. parsed-literal:: + + `struct tnt_stream *tnt_net(struct tnt_stream *s)` + `int tnt_set(struct tnt_stream *s, int option, variant option-value)` .. _c_connect: @@ -96,8 +103,12 @@ URI, this example program can connect to the server. if (tnt_connect(tnt) < 0) { printf("Connection refused\n"); exit(-1); } -Function description: |br| -:codenormal:`int tnt_connect(struct tnt_stream *s)` +Function description: + +.. cssclass:: highlight +.. parsed-literal:: + + int tnt_connect(struct tnt_stream \*s) The connect might fail for a variety of reasons, such as: the server is not running, or the URI contains an invalid password. @@ -122,8 +133,12 @@ the same sort of arguments that one would use with a C ``printf()`` function: ``%d`` for the integer, ``%s`` for the string, then the integer value, then a pointer to the string value. -Function description: |br| -:codenormal:`ssize_t tnt_object_format(struct tnt_stream *s, const char *fmt, ...)` +Function description: + +.. cssclass:: highlight +.. parsed-literal:: + + ssize_t tnt_object_format(struct tnt_stream \*s, const char \*fmt, ...) .. _c_send_request: @@ -139,11 +154,18 @@ In this program the choice is to do an insert request, so the program passes the tnt_stream that was used for connection (:code:`tnt`) and the stream that was set up with tnt_object_format (:code:`tuple`). -Function description: |br| -:codenormal:`ssize_t tnt_insert(struct tnt_stream *s, uint32_t space, struct tnt_stream *tuple)` |br| -:codenormal:`ssize_t tnt_replace(struct tnt_stream *s, uint32_t space, struct tnt_stream *tuple)` |br| -:codenormal:`ssize_t tnt_select(struct tnt_stream *s, uint32_t space, uint32_t index, uint32_t limit, uint32_t offset, uint8_t iterator, struct tnt_stream *key)` |br| -:codenormal:`ssize_t tnt_update(struct tnt_stream *s, uint32_t space, uint32_t index, struct tnt_stream *key, struct tnt_stream *ops)` +Function description: + +.. cssclass:: highlight +.. parsed-literal:: + + ssize_t tnt_insert(struct tnt_stream \*s, uint32_t space, struct tnt_stream \*tuple) + ssize_t tnt_replace(struct tnt_stream \*s, uint32_t space, struct tnt_stream \*tuple) + ssize_t tnt_select(struct tnt_stream \*s, uint32_t space, uint32_t index, + uint32_t limit, uint32_t offset, uint8_t iterator, + struct tnt_stream \*key) + ssize_t tnt_update(struct tnt_stream \*s, uint32_t space, uint32_t index, + struct tnt_stream \*key, struct tnt_stream \*ops) .. _c_get_reply: @@ -157,12 +179,16 @@ whether the result was successful, and a set of tuples. if (reply.code != 0) { printf("Insert failed %lu.\n", reply.code); } -This program checks for success but does not decode the rest of the reply. |br| +This program checks for success but does not decode the rest of the reply. + +Function description: -Function description: |br| -:codenormal:`struct tnt_reply *tnt_reply_init(struct tnt_reply *r)` |br| -:codenormal:`tnt->read_reply(struct tnt_stream *s, struct tnt_reply *r)` |br| -:codenormal:`void tnt_reply_free(struct tnt_reply *r)` +.. cssclass:: highlight +.. parsed-literal:: + + struct tnt_reply \*tnt_reply_init(struct tnt_reply \*r) + tnt->read_reply(struct tnt_stream \*s, struct tnt_reply \*r) + void tnt_reply_free(struct tnt_reply \*r) .. _c_teardown: @@ -176,9 +202,13 @@ should be destroyed. tnt_stream_free(tuple); tnt_stream_free(tnt); -Function description: |br| -:codenormal:`void tnt_close(struct tnt_stream *s)` |br| -:codenormal:`void tnt_stream_free(struct tnt_stream *s)` +Function description: + +.. cssclass:: highlight +.. parsed-literal:: + + void tnt_close(struct tnt_stream \*s) + void tnt_stream_free(struct tnt_stream \*s) A second example. Here is a complete C program that selects, using index key :code:`[99999]`, from @@ -192,51 +222,61 @@ To display the results the program uses functions in the #include <tarantool/tarantool.h> #include <tarantool/tnt_net.h> #include <tarantool/tnt_opt.h> + void main() { - struct tnt_stream *tnt = tnt_net(NULL); - tnt_set(tnt, TNT_OPT_URI, "localhost:3301"); - if (tnt_connect(tnt) < 0) {printf("Connection refused\n"); exit(1);} - struct tnt_stream *tuple = tnt_object(NULL); - tnt_object_format(tuple, "[%d]", 99999); /* tuple = search key */ - tnt_select(tnt, 999, 0, (2^32) - 1, 0, 0, tuple); - tnt_flush(tnt); - struct tnt_reply reply; tnt_reply_init(&reply); - tnt->read_reply(tnt, &reply); - if (reply.code != 0) {printf("Select failed.\n"); exit(1); } - char field_type; - field_type= mp_typeof(*reply.data); - if (field_type != MP_ARRAY) {printf("no tuple array\n"); exit(1); } - long unsigned int row_count; - uint32_t tuple_count= mp_decode_array(&reply.data); - printf("tuple count=%u\n", tuple_count); - unsigned int i,j; - for (i= 0; i < tuple_count; ++i) - { - field_type= mp_typeof(*reply.data); - if (field_type != MP_ARRAY) {printf("no field array\n"); exit(1); } - uint32_t field_count= mp_decode_array(&reply.data); - printf(" field count=%u\n", field_count); - for (j= 0; j < field_count; ++j) - { - field_type= mp_typeof(*reply.data); - if (field_type == MP_UINT) - { - uint64_t num_value= mp_decode_uint(&reply.data); - printf(" value=%lu.\n", num_value); - } - else if (field_type == MP_STR) - { - const char *str_value; - uint32_t str_value_length; - str_value= mp_decode_str(&reply.data,&str_value_length); - printf(" value=%.*s.\n", str_value_length, str_value); - } - else {printf("wrong field type\n"); exit(1); } + struct tnt_stream *tnt = tnt_net(NULL); + tnt_set(tnt, TNT_OPT_URI, "localhost:3301"); + if (tnt_connect(tnt) < 0) { + printf("Connection refused\n"); + exit(1); + } + struct tnt_stream *tuple = tnt_object(NULL); + tnt_object_format(tuple, "[%d]", 99999); /* tuple = search key */ + tnt_select(tnt, 999, 0, (2^32) - 1, 0, 0, tuple); + tnt_flush(tnt); + struct tnt_reply reply; tnt_reply_init(&reply); + tnt->read_reply(tnt, &reply); + if (reply.code != 0) { + printf("Select failed.\n"); + exit(1); + } + char field_type; + field_type = mp_typeof(*reply.data); + if (field_type != MP_ARRAY) { + printf("no tuple array\n"); + exit(1); + } + long unsigned int row_count; + uint32_t tuple_count = mp_decode_array(&reply.data); + printf("tuple count=%u\n", tuple_count); + unsigned int i, j; + for (i = 0; i < tuple_count; ++i) { + field_type = mp_typeof(*reply.data); + if (field_type != MP_ARRAY) { + printf("no field array\n"); + exit(1); + } + uint32_t field_count = mp_decode_array(&reply.data); + printf(" field count=%u\n", field_count); + for (j = 0; j < field_count; ++j) { + field_type = mp_typeof(*reply.data); + if (field_type == MP_UINT) { + uint64_t num_value = mp_decode_uint(&reply.data); + printf(" value=%lu.\n", num_value); + } else if (field_type == MP_STR) { + const char *str_value; + uint32_t str_value_length; + str_value = mp_decode_str(&reply.data, &str_value_length); + printf(" value=%.*s.\n", str_value_length, str_value); + } else { + printf("wrong field type\n"); + exit(1); + } + } } - } - tnt_close(tnt); - tnt_stream_free(tuple); - tnt_stream_free(tnt); + tnt_close(tnt); + tnt_stream_free(tuple); + tnt_stream_free(tnt); } The example programs only shows two requests and do not show all that's diff --git a/doc/sphinx/dev_guide/box-protocol.rst b/doc/sphinx/dev_guide/box-protocol.rst index 3ad90567a7..939be1534e 100644 --- a/doc/sphinx/dev_guide/box-protocol.rst +++ b/doc/sphinx/dev_guide/box-protocol.rst @@ -70,9 +70,9 @@ IPROTO is a binary request/response protocol. 64 107 127 The server begins the dialogue by sending a fixed-size (128 bytes) text greeting -to the client. The greeting always contains two 64 byte lines of ASCII text, each line -ending with newline character ('\\n'). The first line contains the server version and -protocol type. The second line contains up to 44 bytes of base64-encoded +to the client. The greeting always contains two 64 byte lines of ASCII text, each +line ending with newline character ('\\n'). The first line contains the server +version and protocol type. The second line contains up to 44 bytes of base64-encoded random string, to use in authentication packet, and ends with up to 23 spaces. ================================================================================ diff --git a/doc/sphinx/reference/msgpack.rst b/doc/sphinx/reference/msgpack.rst index e08b2c21c2..11368529ce 100644 --- a/doc/sphinx/reference/msgpack.rst +++ b/doc/sphinx/reference/msgpack.rst @@ -54,36 +54,56 @@ takes a series of non-MsgPack values and encodes them. - [20, null, 20] ... -The MsgPack output structure can be specified with ``__serialize``: |br| -* ``__serialize = "seq" or "sequence"`` for an array |br| -* ``__serialize = "map" or "mapping"`` for a map |br| -Serializing 'A' and 'B' with different ``__serialize`` values causes different results. -To show this, here is a routine which encodes -{'A','B'} both as an array and as a map, then -displays each result in hexadecimal. |br| -|nbsp| |nbsp| :codenormal:`msgpack = require('msgpack')` |br| -|nbsp| |nbsp| :codenormal:`m=msgpack.encode(setmetatable({'A', 'B'},` |br| -|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`{ __serialize="seq"}))` |br| -|nbsp| |nbsp| :codenormal:`o1 = ''` |br| -|nbsp| |nbsp| :codenormal:`for i=1,string.len(m),1 do` |br| -|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`o1=o1..string.format("%x",string.byte(m,i))..' '` |br| -|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`end` |br| -|nbsp| |nbsp| :codenormal:`m = msgpack.encode(setmetatable({'A', 'B'},` |br| -|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`{ __serialize="map"}))` |br| -|nbsp| |nbsp| :codenormal:`o2 = ''` |br| -|nbsp| |nbsp| :codenormal:`for i=1,string.len(m),1 do` |br| -|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`o2=o2..string.format("%x",string.byte(m,i))..' '` |br| -|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`end` |br| -|nbsp| |nbsp| :codenormal:`print('array encoding:',o1)` |br| -|nbsp| |nbsp| :codenormal:`print('map encoding: ',o2)` |br| -Result: |br| -|nbsp| |nbsp| :codenormal:`array encoding: 92 a1 41 a1 42` |br| -|nbsp| |nbsp| :codenormal:`map encoding: 82 1 a1 41 2 a1 42` |br| -The MsgPack Specification_ page explains that -the first encoding means |br| -fixarray(2), fixstr(1),"A",fixstr(1),"B" |br| -and the second encoding means |br| -fixmap(2), key(1), fixstr(1),"A",key(2),fixstr(2),"B". +The MsgPack output structure can be specified with ``__serialize``: + +* ``__serialize = "seq" or "sequence"`` for an array +* ``__serialize = "map" or "mapping"`` for a map + +Serializing 'A' and 'B' with different ``__serialize`` values causes different +results. To show this, here is a routine which encodes `{'A','B'}` both as an +array and as a map, then displays each result in hexadecimal. + +.. code-block:: lua + + local function hexdump(bytes) + local result = '' + for i = 1, #m do + result = result .. string.format("%x", string.byte(m, i)) .. ' ' + end + return result + end + + local msgpack = require('msgpack') + local m1 = msgpack.encode(setmetatable({'A', 'B'}, { + __serialize = "seq" + } + local m2 = msgpack.encode(setmetatable({'A', 'B'}, { + __serialize = "map" + } + print('array encoding: ', hexdump(m1)) + print('map encoding: ', hexdump(m2)) + +**Result:** + +.. cssclass:: highlight +.. parsed-literal:: + + **array** encoding: 92 a1 41 a1 42 + **map** encoding: 82 1 a1 41 2 a1 42 + +The MsgPack Specification_ page explains that the first encoding means: + +.. cssclass:: highlight +.. parsed-literal:: + + fixarray(2), fixstr(1), "A", fixstr(1), "B" + +and the second encoding means: + +.. cssclass:: highlight +.. parsed-literal:: + + fixmap(2), key(1), fixstr(1), "A", key(2), fixstr(2), "B". .. _MsgPack: http://msgpack.org/ -.. _Specification: http://github.com/msgpack/msgpack/blob/master/spec.md \ No newline at end of file +.. _Specification: http://github.com/msgpack/msgpack/blob/master/spec.md diff --git a/doc/sphinx/reference/net_box.rst b/doc/sphinx/reference/net_box.rst index 5aabd39096..8e39fd068e 100644 --- a/doc/sphinx/reference/net_box.rst +++ b/doc/sphinx/reference/net_box.rst @@ -159,7 +159,7 @@ necessary to prioritize requests or to use different authentication ids. in Lua-string, which may be any statement or series of statements. An :ref:`execute privilege <privileges>` is required; if the user does not have it, an administrator may grant it with - :codenormal:`box.schema.user.grant(`:codeitalic:`username`:codenormal:`,'execute','universe')`. + :samp:`box.schema.user.grant({username}, 'execute', 'universe')`. Example: ``conn:eval('return 5+5')`` -- GitLab