You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I use mspack.encode/decode to pass Lua tables between Lua scripts I expect that the encoded table after decoding will be exactly the same. But this isn't always true. When the table represents a sparse array msgpack.encode could serialize it to msgpack array, and after decoding in another Lua script my table will consist mspack.NULL's that not the same as Lua nil's.
unix/:/var/run/tarantool/xtaz_1.control> t = { [1] = 1, [3] = 3 }
---
...
unix/:/var/run/tarantool/xtaz_1.control> tt = {} for _, n in pairs(t) do table.insert(tt, n) end
---
...
unix/:/var/run/tarantool/xtaz_1.control> tt
---
- - 3
- 1
...
unix/:/var/run/tarantool/xtaz_1.control> t = msgpack.decode(msgpack.encode((t)))
---
...
unix/:/var/run/tarantool/xtaz_1.control> t
---
- [1, null, 3]
...
unix/:/var/run/tarantool/xtaz_1.control> tt = {} for _, n in pairs(t) do table.insert(tt, n) end
---
...
unix/:/var/run/tarantool/xtaz_1.control> tt
---
- - 1
- null
- 3
...
unix/:/var/run/tarantool/xtaz_1.control>
I know that there is a hint in metatable (__serialize = 'map') that force msgpack.encode to always serialize table as a msgpack map, but in my opinion, it's better to serialize sparse array as a map by default and serialize it as an array using the hint. It's more expected behavior rather than trying to guess.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When I use mspack.encode/decode to pass Lua tables between Lua scripts I expect that the encoded table after decoding will be exactly the same. But this isn't always true. When the table represents a sparse array msgpack.encode could serialize it to msgpack array, and after decoding in another Lua script my table will consist mspack.NULL's that not the same as Lua nil's.
I know that there is a hint in metatable (__serialize = 'map') that force msgpack.encode to always serialize table as a msgpack map, but in my opinion, it's better to serialize sparse array as a map by default and serialize it as an array using the hint. It's more expected behavior rather than trying to guess.
Beta Was this translation helpful? Give feedback.
All reactions