1
1
.. _index-box_connectors :
2
2
3
- -------------------------------------------------------------------------------
4
- Connectors
5
- -------------------------------------------------------------------------------
3
+ Connectors
4
+ ==========
6
5
7
6
Connectors are APIs that allow using Tarantool with various programming languages.
8
7
9
8
Connectors can be divided into two groups -- those maintained by the Tarantool team
10
9
and those supported by the community.
11
10
The Tarantool team maintains the :ref: `high-level C API <index_connector_c >`, the :ref: `Go <index_connector_go >`
12
11
and :ref: `Java <index_connector_java >` connectors, and a synchronous :ref: `Python <index_connector_py >` connector.
13
- All other connectors are community-supported, which means that support for new Tarantool features may be delayed.
12
+ All other connectors are :ref: ` community-supported < connectors-community-supported >` , which means that support for new Tarantool features may be delayed.
14
13
Besides, the Tarantool support team cannot prioritize issues that arise while working through these connectors.
15
14
16
- This chapter documents the following connectors:
17
-
18
- * :doc: `C++ <connectors/cxx/tntcxx_api >`
19
- * :ref: `Java <index_connector_java >`
20
- * :ref: `Go <index_connector_go >`
21
- * :ref: `R <index_connector_r >`
22
- * :ref: `Erlang <index_connector_erlang >`
23
- * :ref: `Perl <index_connector_perl >`
24
- * :ref: `PHP <index_connector_php >`
25
- * :ref: `Python <index_connector_py >`
26
- * :ref: `Node.js <index_connector_nodejs >`
27
- * :ref: `C# <index_connector_csharp >`
28
- * :ref: `C <index_connector_c >`
15
+ This chapter documents APIs for various programming languages:
29
16
30
17
.. toctree ::
31
- :hidden:
18
+ :maxdepth: 1
32
19
33
- C++ <connectors/cxx/tntcxx_api >
20
+ connectors/c
21
+ connectors/go
22
+ connectors/java
23
+ connectors/python
24
+ connectors/community
34
25
35
- =====================================================================
36
- Protocol
37
- =====================================================================
26
+ Protocol
27
+ --------
38
28
39
29
Tarantool's binary protocol was designed with a focus on asynchronous I/O and
40
30
easy integration with proxies. Each client request starts with a variable-length
@@ -55,9 +45,9 @@ in the source tree. For detailed examples and diagrams of all binary-protocol
55
45
requests and responses, see
56
46
:ref: `Tarantool's binary protocol <box_protocol-iproto_protocol >`.
57
47
58
- ====================================================================
59
- Packet example
60
- ====================================================================
48
+
49
+ Packet example
50
+ --------------
61
51
62
52
The Tarantool API exists so that a client program can send a request packet to
63
53
a server instance, and receive a response. Here is an example of a what the client
@@ -103,9 +93,8 @@ exist for drivers for Perl, Python, PHP, and so on.
103
93
104
94
.. _index-connector_setting :
105
95
106
- ====================================================================
107
- Setting up the server for connector examples
108
- ====================================================================
96
+ Setting up the server for connector examples
97
+ --------------------------------------------
109
98
110
99
This chapter has examples that show how to connect to a Tarantool instance via
111
100
the Perl, PHP, Python, node.js, and C connectors. The examples contain hard code that
@@ -131,44 +120,91 @@ script:
131
120
box.schema.user.grant('guest','read,write','space','examples')
132
121
box.schema.user.grant('guest','read','space','_space')
133
122
134
- .. _index_connector_java :
135
-
136
- .. include :: connectors/__java.rst
137
-
138
- .. _index_connector_go :
139
-
140
- .. include :: connectors/__go.rst
141
-
142
- .. _index_connector_r :
143
-
144
- .. include :: connectors/__r.rst
145
-
146
- .. _index_connector_erlang :
147
-
148
- .. include :: connectors/__erlang.rst
149
-
150
- .. _index_connector_perl :
151
-
152
- .. include :: connectors/__perl.rst
153
-
154
- .. _index_connector_php :
155
-
156
- .. include :: connectors/__php.rst
157
-
158
- .. _index_connector_py :
159
-
160
- .. include :: connectors/__python.rst
161
-
162
- .. _index_connector_nodejs :
163
-
164
- .. include :: connectors/__nodejs.rst
165
-
166
- .. _index_connector_csharp :
167
-
168
- .. include :: connectors/__csharp.rst
169
-
170
- .. _index_connector_c :
171
-
172
- .. include :: connectors/__c.rst
173
123
174
- .. include :: connectors/__results.rst
124
+ Interpreting function return values
125
+ -----------------------------------
126
+
127
+ For all connectors, calling a function via Tarantool causes a return in the
128
+ MsgPack format. If the function is called using the connector's API, some
129
+ conversions may occur. All scalar values are returned as tuples (with a MsgPack
130
+ type-identifier followed by a value); all non-scalar values are returned as a
131
+ group of tuples (with a MsgPack array-identifier followed by the scalar values).
132
+ If the function is called via the binary protocol command layer -- "eval" --
133
+ rather than via the connector's API, no conversions occur.
134
+
135
+ In the following example, a Lua function will be created. Since it will be
136
+ accessed externally by a :ref: `'guest' user<box_space-user> `, a
137
+ :doc: `grant </reference/reference_lua/box_schema/user_grant >` of an execute privilege will
138
+ be necessary. The function returns an empty array, a scalar string, two booleans,
139
+ and a short integer. The values are the ones described in the table
140
+ :ref: `Common Types and MsgPack Encodings <msgpack-common_types_and_msgpack_encodings >`.
141
+
142
+ .. code-block :: tarantoolsession
143
+
144
+ tarantool> box.cfg{listen=3301}
145
+ 2016-03-03 18:45:52.802 [27381] main/101/interactive I> ready to accept requests
146
+ ---
147
+ ...
148
+ tarantool> function f() return {},'a',false,true,127; end
149
+ ---
150
+ ...
151
+ tarantool> box.schema.func.create('f')
152
+ ---
153
+ ...
154
+ tarantool> box.schema.user.grant('guest','execute','function','f')
155
+ ---
156
+ ...
157
+
158
+ Here is a C program which calls the function. Although C is being used for the
159
+ example, the result would be precisely the same if the calling program was
160
+ written in Perl, PHP, Python, Go, or Java.
161
+
162
+ .. code-block :: c
163
+
164
+ #include <stdio.h>
165
+ #include <stdlib.h>
166
+ #include <tarantool/tarantool.h>
167
+ #include <tarantool/tnt_net.h>
168
+ #include <tarantool/tnt_opt.h>
169
+ void main() {
170
+ struct tnt_stream *tnt = tnt_net(NULL); /* SETUP */
171
+ tnt_set(tnt, TNT_OPT_URI, "localhost:3301");
172
+ if (tnt_connect(tnt) < 0) { /* CONNECT */
173
+ printf("Connection refused\n");
174
+ exit(-1);
175
+ }
176
+ struct tnt_stream *arg; arg = tnt_object(NULL); /* MAKE REQUEST */
177
+ tnt_object_add_array(arg, 0);
178
+ struct tnt_request *req1 = tnt_request_call(NULL); /* CALL function f() */
179
+ tnt_request_set_funcz(req1, "f");
180
+ uint64_t sync1 = tnt_request_compile(tnt, req1);
181
+ tnt_flush(tnt); /* SEND REQUEST */
182
+ struct tnt_reply reply; tnt_reply_init(&reply); /* GET REPLY */
183
+ tnt->read_reply(tnt, &reply);
184
+ if (reply.code != 0) {
185
+ printf("Call failed %lu.\n", reply.code);
186
+ exit(-1);
187
+ }
188
+ const unsigned char *p= (unsigned char*)reply.data; /* PRINT REPLY */
189
+ while (p < (unsigned char *) reply.data_end)
190
+ {
191
+ printf("%x ", *p);
192
+ ++p;
193
+ }
194
+ printf("\n");
195
+ tnt_close(tnt); /* TEARDOWN */
196
+ tnt_stream_free(arg);
197
+ tnt_stream_free(tnt);
198
+ }
199
+
200
+ When this program is executed, it will print:
201
+
202
+ .. code-block :: console
203
+
204
+ dd 0 0 0 5 90 91 a1 61 91 c2 91 c3 91 7f
205
+
206
+ The first five bytes -- ``dd 0 0 0 5 `` -- are the MsgPack encoding for
207
+ "32-bit array header with value 5" (see
208
+ `MsgPack specification <http://github.com/msgpack/msgpack/blob/master/spec.md >`__).
209
+ The rest are as described in the
210
+ table :ref: `Common Types and MsgPack Encodings <msgpack-common_types_and_msgpack_encodings >`.
0 commit comments