[PATCH v3 5/7] net.box: add skip_header option to use with buffer
Alexander Turenko
alexander.turenko at tarantool.org
Tue Apr 30 21:39:12 MSK 2019
On Tue, Apr 30, 2019 at 04:16:25PM +0300, Vladimir Davydov wrote:
> On Wed, Apr 10, 2019 at 06:21:23PM +0300, Alexander Turenko wrote:
> > Needed for #3276.
> >
> > @TarantoolBot document
> > Title: net.box: skip_header option
> >
> > This option instructs net.box to skip {[IPROTO_DATA_KEY] = ...} wrapper
> > from a buffer. This may be needed to pass this buffer to some C function
> > when it expects some specific msgpack input.
> >
> > See src/box/lua/net_box.lua for examples.
> > ---
>
> Looks good to me, but can't push it now as it depends on the previous
> patch.
Konstantin found the description non-clear and so I have updated the
example in [1] to show skip_header option effect and put it into the
docbot comment.
Pushed to Totktonada/gh-3276-on-board-merger.
Cited the example below:
```lua
local net_box = require('net.box')
local buffer = require('buffer')
local ffi = require('ffi')
local msgpack = require('msgpack')
local yaml = require('yaml')
box.cfg{listen = 3301}
box.once('load_data', function()
box.schema.user.grant('guest', 'read,write,execute', 'universe')
box.schema.space.create('s')
box.space.s:create_index('pk')
box.space.s:insert({1})
box.space.s:insert({2})
box.space.s:insert({3})
box.space.s:insert({4})
end)
local function foo()
return box.space.s:select()
end
_G.foo = foo
local conn = net_box.connect('localhost:3301')
local buf = buffer.ibuf()
conn.space.s:select(nil, {buffer = buf})
local buf_str = ffi.string(buf.rpos, buf.wpos - buf.rpos)
local buf_lua = msgpack.decode(buf_str)
print('select:\n' .. yaml.encode(buf_lua))
-- {48: [[1], [2], [3], [4]]}
local buf = buffer.ibuf()
conn.space.s:select(nil, {buffer = buf, skip_header = true})
local buf_str = ffi.string(buf.rpos, buf.wpos - buf.rpos)
local buf_lua = msgpack.decode(buf_str)
print('select:\n' .. yaml.encode(buf_lua))
-- [[1], [2], [3], [4]]
local buf = buffer.ibuf()
conn:call('foo', nil, {buffer = buf})
local buf_str = ffi.string(buf.rpos, buf.wpos - buf.rpos)
local buf_lua = msgpack.decode(buf_str)
print('call:\n' .. yaml.encode(buf_lua))
-- {48: [[[1], [2], [3], [4]]]}
local buf = buffer.ibuf()
conn:call('foo', nil, {buffer = buf, skip_header = true})
local buf_str = ffi.string(buf.rpos, buf.wpos - buf.rpos)
local buf_lua = msgpack.decode(buf_str)
print('call:\n' .. yaml.encode(buf_lua))
-- [[[1], [2], [3], [4]]]
os.exit()
```
[1]: https://github.com/Totktonada/tarantool-merger-examples/tree/e65141ba18ff74f9c7f68b7a782ae00f920f8929#preparing-buffers
More information about the Tarantool-patches
mailing list