Skip to content
Snippets Groups Projects
Commit 12a1228c authored by Roman Tsisyk's avatar Roman Tsisyk
Browse files

Merge branch 'tuple-msgpack-fix'

parents 5fb1508e 94d45213
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,9 @@ tuple_seek(struct tuple_iterator *it, uint32_t field_no);
const char *
tuple_next(struct tuple_iterator *it);
void
tuple_to_buf(struct tuple *tuple, char *buf);
]])
local builtin = ffi.C
......@@ -107,6 +110,15 @@ local function tuple_unpack(tuple)
return unpack(tuple_totable(tuple))
end
-- Set encode hooks for msgpackffi
local function tuple_to_msgpack(buf, tuple)
buf:reserve(tuple._bsize)
builtin.tuple_to_buf(tuple, buf.p)
buf.p = buf.p + tuple._bsize
end
msgpackffi.on_encode(ffi.typeof('const struct tuple &'), tuple_to_msgpack)
-- cfuncs table is set by C part
local methods = {
......
......@@ -442,6 +442,13 @@ tuple_to_obuf(struct tuple *tuple, struct obuf *buf);
void
tuple_to_tbuf(struct tuple *tuple, struct tbuf *buf);
/**
* Store tuple fields in the memory buffer. Buffer must have at least
* tuple->bsize bytes.
*/
extern "C" void
tuple_to_buf(struct tuple *tuple, char *buf);
/** Initialize tuple library */
void
tuple_init(float slab_alloc_arena, uint32_t slab_alloc_minimal,
......
......@@ -41,3 +41,9 @@ tuple_to_tbuf(struct tuple *tuple, struct tbuf *buf)
{
tbuf_append(buf, tuple->data, tuple->bsize);
}
void
tuple_to_buf(struct tuple *tuple, char *buf)
{
memcpy(buf, tuple->data, tuple->bsize);
}
......@@ -377,15 +377,15 @@ t:next(3)
...
t:next(4)
---
- error: '[string "-- tuple.lua (internal file)..."]:65: error: invalid key to ''next'''
- error: '[string "-- tuple.lua (internal file)..."]:68: error: invalid key to ''next'''
...
t:next(-1)
---
- error: '[string "-- tuple.lua (internal file)..."]:65: error: invalid key to ''next'''
- error: '[string "-- tuple.lua (internal file)..."]:68: error: invalid key to ''next'''
...
t:next("fdsaf")
---
- error: '[string "-- tuple.lua (internal file)..."]:48: error: invalid key to ''next'''
- error: '[string "-- tuple.lua (internal file)..."]:51: error: invalid key to ''next'''
...
box.tuple.new({'x', 'y', 'z'}):next()
---
......@@ -397,7 +397,7 @@ t=space:insert{1953719668}
...
t:next(1684234849)
---
- error: '[string "-- tuple.lua (internal file)..."]:65: error: invalid key to ''next'''
- error: '[string "-- tuple.lua (internal file)..."]:68: error: invalid key to ''next'''
...
t:next(1)
---
......@@ -552,7 +552,7 @@ r = {}
...
for _state, val in t:pairs(10) do table.insert(r, val) end
---
- error: '[string "-- tuple.lua (internal file)..."]:65: error: invalid key to ''next'''
- error: '[string "-- tuple.lua (internal file)..."]:68: error: invalid key to ''next'''
...
r
---
......@@ -582,6 +582,51 @@ t:pairs("fdsaf")
- ['a', 'b', 'c']
- fdsaf
...
--------------------------------------------------------------------------------
-- test msgpack.encode + tuple
--------------------------------------------------------------------------------
msgpackffi = require('msgpackffi')
---
...
t = box.tuple.new({'a', 'b', 'c'})
---
...
msgpack.decode(msgpackffi.encode(t))
---
- - a
- b
- c
...
msgpack.decode(msgpack.encode(t))
---
- - a
- b
- c
...
msgpack.decode(msgpackffi.encode({1, {'x', 'y', t, 'z'}, 2, 3}))
---
- - 1
- - x
- y
- - a
- b
- c
- z
- 2
- 3
...
msgpack.decode(msgpack.encode({1, {'x', 'y', t, 'z'}, 2, 3}))
---
- - 1
- - x
- y
- - a
- b
- c
- z
- 2
- 3
...
space:drop()
---
...
......@@ -180,4 +180,16 @@ r
t:pairs(nil)
t:pairs("fdsaf")
--------------------------------------------------------------------------------
-- test msgpack.encode + tuple
--------------------------------------------------------------------------------
msgpackffi = require('msgpackffi')
t = box.tuple.new({'a', 'b', 'c'})
msgpack.decode(msgpackffi.encode(t))
msgpack.decode(msgpack.encode(t))
msgpack.decode(msgpackffi.encode({1, {'x', 'y', t, 'z'}, 2, 3}))
msgpack.decode(msgpack.encode({1, {'x', 'y', t, 'z'}, 2, 3}))
space:drop()
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