From c5a118a87e42e27ab50fb7b123d3b37790d06365 Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tsisyk.com> Date: Mon, 2 Feb 2015 18:20:18 +0300 Subject: [PATCH] Fix #596: msgpack and msgpackffi have different behaviour --- src/lua/msgpackffi.lua | 7 +++++-- test/app/msgpackffi.result | 4 +++- test/app/msgpackffi.test.lua | 12 ++++++++++-- test/box/tuple.result | 16 +++------------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua index 5b758c447e..d63d290512 100644 --- a/src/lua/msgpackffi.lua +++ b/src/lua/msgpackffi.lua @@ -289,6 +289,9 @@ on_encode(ffi.typeof('double'), encode_double) -- Decoder -------------------------------------------------------------------------------- +local array_mt = { __serialize = 'seq' } +local map_mt = { __serialize = 'map' } + local decode_r local function decode_u8(data) @@ -367,7 +370,7 @@ local function decode_array(data, size) for i=1,size,1 do table.insert(arr, decode_r(data)) end - return arr + return setmetatable(arr, array_mt) end local function decode_map(data, size) @@ -379,7 +382,7 @@ local function decode_map(data, size) local val = decode_r(data); map[key] = val end - return map + return setmetatable(map, map_mt) end local decoder_hint = { diff --git a/test/app/msgpackffi.result b/test/app/msgpackffi.result index 940ce93039..8432aab5d7 100644 --- a/test/app/msgpackffi.result +++ b/test/app/msgpackffi.result @@ -157,8 +157,10 @@ ok - table # offsets: end ok - offsets # other - 1..1 + 1..3 ok - gh-633 double decode + ok - array save __serialize + ok - map save __serialize # other: end ok - other # msgpackffi: end diff --git a/test/app/msgpackffi.test.lua b/test/app/msgpackffi.test.lua index e70bdf8ba8..60c01b06ad 100755 --- a/test/app/msgpackffi.test.lua +++ b/test/app/msgpackffi.test.lua @@ -36,12 +36,20 @@ local function test_offsets(test, s) end local function test_other(test, s) - test:plan(1) + test:plan(3) local buf = string.char(0x93, 0x6e, 0xcb, 0x42, 0x2b, 0xed, 0x30, 0x47, 0x6f, 0xff, 0xff, 0xac, 0x77, 0x6b, 0x61, 0x71, 0x66, 0x7a, 0x73, 0x7a, 0x75, 0x71, 0x71, 0x78) - local num = s.decode(buf)[2] + local num = s.decode(buf)[2] test:ok(num < 59971740600 and num > 59971740599, "gh-633 double decode") + + -- gh-596: msgpack and msgpackffi have different behaviour + local arr = {1, 2, 3} + local map = {k1 = 'v1', k2 = 'v2', k3 = 'v3'} + test:is(getmetatable(s.decode(s.encode(arr))).__serialize, "seq", + "array save __serialize") + test:is(getmetatable(s.decode(s.encode(map))).__serialize, "map", + "map save __serialize") end tap.test("msgpackffi", function(test) diff --git a/test/box/tuple.result b/test/box/tuple.result index 08db8a8078..39186ccb62 100644 --- a/test/box/tuple.result +++ b/test/box/tuple.result @@ -205,11 +205,11 @@ box.tuple.new{1, 2, 3, 4, 5} ... box.tuple.new({'a', 'b'}, {'c', 'd'}, {'e', 'f'}) --- -- [['a', b], ['c', 'd'], ['e', 'f']] +- [['a', 'b'], ['c', 'd'], ['e', 'f']] ... box.tuple.new{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}} --- -- [['a', b], ['c', 'd'], ['e', 'f']] +- [['a', 'b'], ['c', 'd'], ['e', 'f']] ... box.tuple.new({1, 2}, 'x', 'y', 'z', {c = 3, d = 4}, {e = 5, f = 6}) --- @@ -287,17 +287,7 @@ t=space:get{777}:totable() ... t[2], t[3], t[4], t[5] --- -- - a - - b - - c - - - d - - e - - - 0 - - 777 - - '0' - - '1' - - '2' - - '3' +- ['a', 'b', 'c', ['d', 'e', [0, 777, '0', '1', '2', '3']]] - null - null - null -- GitLab