Open
Description
It seems the session:receive fails continuously to decode a correct msgpack rpc string once it first correctly fails on non rpc mpack data.
I can't seem to find a way to fix it except for creating a new session.
Here's a small script to demonstrate.
local mpack = require('mpack')
-- these data were built on the msgpack website with their "try" page
-- JSON: [0,8,"add",[1,2]]
corr_rpc_hex = [[ 94 00 08 a3 61 64 64 92 01 02 ]]
-- JSON: {"this" : "that", "that" : "this", "numbers" : [1,2,3,4], "sub" : { "a" : 1, "b" : 2} }
corr_mpack_hex = [[ 84 a4 74 68 69 73 a4 74 68 61 74 a4 74 68 61 74
a4 74 68 69 73 a7 6e 75 6d 62 65 72 73 94 01 02
03 04 a3 73 75 62 82 a1 61 01 a1 62 02 ]]
--------------------------------------------------------------------------------
function string.remove_spaces(str)
return str:gsub("%s+", "")
end
--------------------------------------------------------------------------------
function string.fromhex(str)
return (str:gsub('..', function (cc)
return string.char(tonumber(cc, 16))
end))
end
--------------------------------------------------------------------------------
-- tests
local rpc_data = corr_rpc_hex:remove_spaces():fromhex()
--print(rpc_data)
local mpack_data = corr_mpack_hex:remove_spaces():fromhex()
--print (mpack_data)
local session = mpack.Session({unpack = mpack.Unpacker()})
-- correctly decodes rpc
ok, rpctype, id, method, args, pos = pcall(session.receive, session, rpc_data)
print(ok, rpctype, id, method, args, pos)
-- correctly detects error
--[-[
ok, rpctype, id, method, args, pos = pcall(session.receive, session, mpack_data)
print(ok, rpctype, id, method, args, pos)
--]]
-- fails to decode rpc
ok, rpctype, id, method, args, pos = pcall(session.receive, session, rpc_data)
print(ok, rpctype, id, method, args, pos)
-- correctly decodes again
local session = mpack.Session({unpack = mpack.Unpacker()})
ok, rpctype, id, method, args, pos = pcall(session.receive, session, rpc_data)
print(ok, rpctype, id, method, args, pos)
Metadata
Metadata
Assignees
Labels
No labels