Skip to content

Commit fc6de68

Browse files
committed
Fixes gh-859 No information about msgpack.cfg
1 parent 590800c commit fc6de68

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

doc/1.10/reference/reference_lua/json.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ invalid numbers or types. They are all boolean ``true``/``false`` values
184184
* ``cfg.encode_invalid_as_nil`` (default is false) -- use null for all
185185
unrecognizable types
186186
* ``cfg.encode_load_metatables`` (default is false) -- load metatables
187+
* ``cfg.encode_max_depth`` (default is 32) -- maximum nesting depth in a structure
188+
* ``cfg.decode_invalid_numbers`` (default is true) -- allow nan and inf
189+
* ``cfg.decode_use_tostring`` (default is false) -- use tostring for
190+
unrecognizable types
191+
* ``cfg.encode_invalid_as_nil`` (default is false) -- use null for all
192+
unrecognizable types
193+
* ``cfg.decode_load_metatables`` (default is false) -- load metatables
194+
* ``cfg.decode_max_depth`` (default is 32) -- maximum nesting depth in a structure
187195

188196
For example, the following code will interpret 0/0 (which is "not a number")
189197
and 1/0 (which is "infinity") as special values rather than nulls or errors:

doc/1.10/reference/reference_lua/msgpack.rst

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Below is a list of all ``msgpack`` functions and members.
3939
| :ref:`msgpack.NULL | Analog of Lua's "nil" |
4040
| <msgpack-null>` | |
4141
+--------------------------------------+---------------------------------+
42+
| :ref:`msgpack.cfg | Change configuration |
43+
| <msgpack-cfg>` | |
44+
+--------------------------------------+---------------------------------+
45+
4246

4347
.. module:: msgpack
4448

@@ -226,8 +230,38 @@ with the MsgPack format name and encoding on the right.
226230
| 1.5 | 'float 64' = cb 3f f8 00 00 00 00 00 00 |
227231
+--------------+-------------------------------------------------+
228232

229-
Also, some MsgPack configuration settings for encoding can be changed, in the
230-
same way that they can be changed for :ref:`JSON <json-module_cfg>`.
233+
.. _msgpack-cfg:
234+
235+
.. function:: cfg(table)
236+
237+
Some MsgPack configuration settings can be changed, in the
238+
same way that they can be changed for json.
239+
See :ref:`Module JSON <json-module_cfg>` for a list of some configuration settings.
240+
(The same configuration settings exist for json, for MsgPack, and for :ref:`YAML <yaml-module>`.)
241+
242+
For example, if ``msgpack.cfg.encode_invalid_numbers = true`` (the default),
243+
then nan and inf are legal values. If that is not desirable, then
244+
ensure that ``msgpack.encode()`` will not accept them, by saying
245+
``msgpack.cfg{encode_invalid_numbers = false}``, thus:
246+
247+
.. code-block:: none
248+
249+
tarantool> msgpack = require('msgpack'); msgpack.cfg{encode_invalid_numbers = true}
250+
---
251+
...
252+
tarantool> msgpack.decode(msgpack.encode{1, 0 / 0, 1 / 0, false})
253+
---
254+
- [1, -nan, inf, false]
255+
- 22
256+
...
257+
tarantool> msgpack.cfg{encode_invalid_numbers = false}
258+
---
259+
...
260+
tarantool> msgpack.decode(msgpack.encode{1, 0 / 0, 1 / 0, false})
261+
---
262+
- error: ... number must not be NaN or Inf'
263+
...
264+
231265
232266
.. _MsgPack: http://msgpack.org/
233267
.. _Specification: http://github.com/msgpack/msgpack/blob/master/spec.md

0 commit comments

Comments
 (0)