Skip to content
Snippets Groups Projects
Commit a06908d2 authored by ocelot-inc's avatar ocelot-inc
Browse files

gh-963 serializer is not documented

parent 28908a51
No related branches found
No related tags found
No related merge requests found
...@@ -663,7 +663,7 @@ is Rectangle#2", and "Rectangle#3 is entirely inside Rectangle#2". ...@@ -663,7 +663,7 @@ is Rectangle#2", and "Rectangle#3 is entirely inside Rectangle#2".
Now let us create a space and add an RTREE index. Now let us create a space and add an RTREE index.
| :codebold:`s = box.schema.create_space('rectangles')` | :codebold:`s = box.schema.space.create('rectangles')`
| :codebold:`i = s:create_index('primary',{type='HASH',parts={1,'NUM'}})` | :codebold:`i = s:create_index('primary',{type='HASH',parts={1,'NUM'}})`
| :codebold:`r = s:create_index('spatial',{type='RTREE',unique=false,parts={2,'ARRAY'}})` | :codebold:`r = s:create_index('spatial',{type='RTREE',unique=false,parts={2,'ARRAY'}})`
......
...@@ -95,5 +95,14 @@ The json package provides JSON manipulation routines. It is based on the ...@@ -95,5 +95,14 @@ The json package provides JSON manipulation routines. It is based on the
| :codenormal:`- '{"field2":null,"field1":"a","field3":"c"}'` | :codenormal:`- '{"field2":null,"field1":"a","field3":"c"}'`
| :codenormal:`...` | :codenormal:`...`
The JSON output structure can be specified with :code:`__serialize`:
__serialize="seq" for an array,
__serialize="map" for a map.
Serializing 'A' and 'B' with different __serialize values causes different results: |br|
:codebold:`json.encode(setmetatable({'A', 'B'}, { __serialize="seq"}))` |br|
:codenormal:`- '["A","B"]'` |br|
:codebold:`json.encode({setmetatable({f1 = 'A', f2 = 'B'}, { __serialize="map"})})` |br|
:codenormal:`- '[{"f2":"B","f1":"A"}]'` |br|
.. _Lua-CJSON package by Mark Pulford: http://www.kyne.com.au/~mark/software/lua-cjson.php .. _Lua-CJSON package by Mark Pulford: http://www.kyne.com.au/~mark/software/lua-cjson.php
.. _the official documentation: http://www.kyne.com.au/~mark/software/lua-cjson-manual.html .. _the official documentation: http://www.kyne.com.au/~mark/software/lua-cjson-manual.html
...@@ -33,27 +33,45 @@ series of non-YAML values and encodes them. ...@@ -33,27 +33,45 @@ series of non-YAML values and encodes them.
Example Example
================================================= =================================================
.. code-block:: lua | :codenormal:`tarantool>` :codebold:`yaml = require('yaml')`
| :codenormal:`---`
tarantool> yaml = require('yaml') | :codenormal:`...`
--- | :codenormal:`tarantool>` :codebold:`y = yaml.encode({'a',1,'b',2})`
... | :codenormal:`---`
tarantool> y = yaml.encode({'a',1,'b',2}) | :codenormal:`...`
--- | :codenormal:`tarantool>` :codebold:`z = yaml.decode(y)`
... | :codenormal:`---`
tarantool> z = yaml.decode(y) | :codenormal:`...`
--- | :codenormal:`tarantool>` :codebold:`z[1],z[2],z[3],z[4]`
... | :codenormal:`---`
tarantool> z[1],z[2],z[3],z[4] | :codenormal:`- a`
--- | :codenormal:`- 1`
- a | :codenormal:`- b`
- 1 | :codenormal:`- 2`
- b | :codenormal:`...`
- 2 | :codenormal:`tarantool>` :codebold:`if yaml.NULL == nil then print('hi') end`
... | :codenormal:`hi`
tarantool> if yaml.NULL == nil then print('hi') end | :codenormal:`---`
hi | :codenormal:`...`
---
... The `YAML collection style <http://yaml.org/spec/1.1/#id930798>`_ can be specified with :code:`__serialize`:
__serialize="sequence" for a Block Sequence array,
__serialize="seq" for a Flow Sequence array,
__serialize="mapping" for a Block Mapping map,
__serialize="map" for a Flow Mapping map.
Serializing 'A' and 'B' with different __serialize values causes different results: |br|
:codebold:`yaml.encode(setmetatable({'A', 'B'}, { __serialize="sequence"}))` |br|
:codenormal:`- A` |br|
:codenormal:`- B` |br|
:codebold:`yaml.encode(setmetatable({'A', 'B'}, { __serialize="seq"}))` |br|
:codenormal:`- ['A', 'B']` |br|
:codebold:`yaml.encode({setmetatable({f1 = 'A', f2 = 'B'}, { __serialize="map"})})` |br|
:codenormal:`- f2: B` |br|
:codenormal:`- f1: A` |br|
:codebold:`yaml.encode({setmetatable({f1 = 'A', f2 = 'B'}, { __serialize="mapping"})})` |br|
:codenormal:`- {'f2': 'B', 'f1': 'A'}` |br|
.. _YAML: http://yaml.org/ .. _YAML: http://yaml.org/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment