@@ -106,6 +106,10 @@ For example, in a successful response to ``box.space:select()``,
106
106
the Response-Code-Indicator value will be 0 = ``IPROTO_OK `` and the
107
107
array will have all the tuples of the result.
108
108
109
+ Read the source code file `net_box.c <https://github.com/tarantool/tarantool/blob/master/src/box/lua/net_box.c >`_
110
+ where the function "decode_metadata_optional" is an example of how Tarantool
111
+ itself decodes extra items.
112
+
109
113
Body
110
114
~~~~
111
115
@@ -114,3 +118,130 @@ be absent or be an empty map. Both these states will be interpreted equally.
114
118
Responses will contain the ``<body> `` anyway even for an
115
119
:ref: `IPROTO_PING <box_protocol-ping >` request.
116
120
121
+
122
+ .. cssclass :: highlight
123
+ .. parsed-literal ::
124
+
125
+ # <size>
126
+ msgpack(:samp: `{ {MP_UINT unsigned integer = size(<header>) + size(<body>) } } `)
127
+ # <header>
128
+ msgpack({
129
+ Response-Code-Indicator: IPROTO_OK,
130
+ IPROTO_SYNC: :samp: `{ {MP_UINT unsigned integer, may be 64-bit } } `,
131
+ IPROTO_SCHEMA_VERSION: :samp: `{ {MP_UINT unsigned integer } } `
132
+ })
133
+ # <body>
134
+ msgpack({
135
+ IPROTO_DATA: :samp: `{ {any type } } `
136
+ })
137
+
138
+ - For :ref: `IPROTO_PING <box_protocol-ping >` the body will be an empty map.
139
+
140
+
141
+ IPROTO_DATA is what we get with net_box and :ref: `Module buffer <buffer-module >`
142
+ so if we were using net_box we could decode with
143
+ :ref: `msgpack.decode_unchecked() <msgpack-decode_unchecked_string >`,
144
+ or we could convert to a string with :samp: `ffi.string({ pointer } ,{ length } ) `.
145
+ The :ref: `pickle.unpack() <pickle-unpack >` function might also be helpful.
146
+
147
+ Response body
148
+ ~~~~~~~~~~~~~
149
+
150
+ After the :ref: `header <box_protocol-header >`, for a response,
151
+ there will be a body.
152
+ If there was no error, it will contain IPROTO_OK (0x00).
153
+ If there was an error, it will contain an error code other than IPROTO_OK.
154
+ Responses to SQL statements are slightly different and will be described
155
+ in the later section,
156
+ :ref: `Binary protocol -- responses for SQL <box_protocol-sql_protocol >`.
157
+
158
+ For IPROTO_OK, the header Response-Code-Indicator will be 0 and the body is a 1-item map.
159
+
160
+ .. cssclass :: highlight
161
+ .. parsed-literal ::
162
+
163
+ # <size>
164
+ msgpack(:samp: `{ {MP_UINT unsigned integer = size(<header>) + size(<body>) } } `)
165
+ # <header>
166
+ msgpack({
167
+ Response-Code-Indicator: IPROTO_OK,
168
+ IPROTO_SYNC: :samp: `{ {MP_UINT unsigned integer, may be 64-bit } } `,
169
+ IPROTO_SCHEMA_VERSION: :samp: `{ {MP_UINT unsigned integer } } `
170
+ })
171
+ # <body>
172
+ msgpack({
173
+ IPROTO_DATA: :samp: `{ {any type } } `
174
+ })
175
+
176
+ Responses for SQL
177
+ -----------------
178
+
179
+ After the :ref: `header <box_protocol-header >`, for a response to an SQL statement,
180
+ there will be a body that is slightly different from the body for
181
+ :ref: `Binary protocol -- responses if no error and no SQL <box_protocol-responses >`.
182
+
183
+ If the SQL request is not SELECT or VALUES or PRAGMA, then the response body
184
+ contains only IPROTO_SQL_INFO (0x42). Usually IPROTO_SQL_INFO is a map with only
185
+ one item -- SQL_INFO_ROW_COUNT (0x00) -- which is the number of changed rows.
186
+
187
+ .. _box_protocol-responses_error :
188
+
189
+ Responses for errors
190
+ --------------------
191
+
192
+ For a response other than IPROTO_OK, the header Response-Code-Indicator will be
193
+ ``0x8XXX `` and the body will be a 1-item map.
194
+
195
+ .. cssclass :: highlight
196
+ .. parsed-literal ::
197
+
198
+ # <size>
199
+ msgpack(32)
200
+ # <header>
201
+ msgpack({
202
+ Response-Code-Indicator: :samp: `{ {0x8XXX } } `,
203
+ IPROTO_SYNC: :samp: `{ {MP_UINT unsigned integer, may be 64-bit } } `,
204
+ IPROTO_SCHEMA_VERSION: :samp: `{ {MP_UINT unsigned integer } } `
205
+ })
206
+ # <body>
207
+ msgpack({
208
+ IPROTO_ERROR: :samp: `{ {MP_STRING string } } `
209
+ })
210
+
211
+ where ``0x8XXX `` is the indicator for an error and ``XXX `` is a value in
212
+ `src/box/errcode.h <https://github.com/tarantool/tarantool/blob/master/src/box/errcode.h >`_.
213
+ ``src/box/errcode.h `` also has some convenience macros which define hexadecimal
214
+ constants for return codes.
215
+
216
+ Example: in version 2.4.0 and earlier,
217
+ if this is the fifth message and the request is to create a duplicate
218
+ space with
219
+ ``conn:eval([[box.schema.space.create('_space');]]) ``
220
+ the unsuccessful response will look like this:
221
+
222
+ .. code-block :: none
223
+
224
+ # <size>
225
+ msgpack(32)
226
+ # <header>
227
+ msgpack({
228
+ Response-Code-Indicator: 0x800a,
229
+ IPROTO_SYNC: 5,
230
+ IPROTO_SCHEMA_VERSION: 0x78
231
+ })
232
+ # <body>
233
+ msgpack({
234
+ IPROTO_ERROR: "Space '_space' already exists"
235
+ })
236
+
237
+ Later in :ref: `Binary protocol -- illustration <box_protocol-illustration >`
238
+ we will show actual byte codes of the response to the IPROTO_EVAL message.
239
+
240
+ Looking in errcode.h we find that error code 0x0a (decimal 10) is
241
+ ER_SPACE_EXISTS, and the string associated with ER_SPACE_EXISTS is
242
+ "Space '%s' already exists".
243
+
244
+ Since version :doc: `2.4.1 </release/2.4.1 >`, responses for errors have extra information
245
+ following what was described above. This extra information is given via
246
+ MP_ERROR extension type. See details in :ref: `MessagePack extensions
247
+ <msgpack_ext-error>` section.
0 commit comments