Tarantool » 1.9 » Reference » Built-in modules reference » Module buffer

Module buffer

Module buffer

The buffer module returns a dynamically resizable buffer which is solely for use as an option for methods of the net.box module.

Ordinarily the net.box methods return a Lua table. If a buffer option is used, then the net.box methods return a raw MsgPack string. This saves time on the server, if the client application has its own routine for decoding MsgPack strings.

Return:a descriptor of a buffer.


Assume a Tarantool server is listening on farhost:3301. Assume it has a space T with one tuple: 'ABCDE', 12345. In this example we start up a server on localhost:3302 and then use net.box routines to connect to farhost. Then we create a buffer, and use it as an option for a conn.space...select() call. The result will be in MsgPack format. To show this, we will use msgpack.decode_unchecked() on ibuf.rpos (the “read position” of the buffer). Thus we do not decode on the remote server, but we do decode on the local server.

buffer = require('buffer')
ibuf = buffer.ibuf()
net_box = require('net.box')
conn = net_box.connect('farhost:3301')
buffer = require('buffer')
msgpack = require('msgpack')

The result of the final request looks like this:

tarantool> msgpack.decode_unchecked(ibuf.rpos)
- {48: [['ABCDE', 12345]]}
- 'cdata<char *>: 0x7f97ba10c041'


Before Tarantool version 1.7.7, the function to use for this case is msgpack.ibuf_decode(ibuf.rpos). Starting with Tarantool version 1.7.7, ibuf_decode is deprecated.