diff options
Diffstat (limited to 'test/client/msgpack_rpc_stream.lua')
-rw-r--r-- | test/client/msgpack_rpc_stream.lua | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/test/client/msgpack_rpc_stream.lua b/test/client/msgpack_rpc_stream.lua index 5711616b17..ff054ae62b 100644 --- a/test/client/msgpack_rpc_stream.lua +++ b/test/client/msgpack_rpc_stream.lua @@ -3,13 +3,19 @@ local mpack = require('mpack') -- temporary hack to be able to manipulate buffer/window/tabpage local Buffer = {} Buffer.__index = Buffer -function Buffer.new(id) return setmetatable({id=id}, Buffer) end +function Buffer.new(id) + return setmetatable({ id = id }, Buffer) +end local Window = {} Window.__index = Window -function Window.new(id) return setmetatable({id=id}, Window) end +function Window.new(id) + return setmetatable({ id = id }, Window) +end local Tabpage = {} Tabpage.__index = Tabpage -function Tabpage.new(id) return setmetatable({id=id}, Tabpage) end +function Tabpage.new(id) + return setmetatable({ id = id }, Tabpage) +end local Response = {} Response.__index = Response @@ -17,7 +23,7 @@ Response.__index = Response function Response.new(msgpack_rpc_stream, request_id) return setmetatable({ _msgpack_rpc_stream = msgpack_rpc_stream, - _request_id = request_id + _request_id = request_id, }, Response) end @@ -41,19 +47,31 @@ function MsgpackRpcStream.new(stream) _stream = stream, _pack = mpack.Packer({ ext = { - [Buffer] = function(o) return 0, mpack.encode(o.id) end, - [Window] = function(o) return 1, mpack.encode(o.id) end, - [Tabpage] = function(o) return 2, mpack.encode(o.id) end - } + [Buffer] = function(o) + return 0, mpack.encode(o.id) + end, + [Window] = function(o) + return 1, mpack.encode(o.id) + end, + [Tabpage] = function(o) + return 2, mpack.encode(o.id) + end, + }, }), _session = mpack.Session({ unpack = mpack.Unpacker({ ext = { - [0] = function(_c, s) return Buffer.new(mpack.decode(s)) end, - [1] = function(_c, s) return Window.new(mpack.decode(s)) end, - [2] = function(_c, s) return Tabpage.new(mpack.decode(s)) end - } - }) + [0] = function(_c, s) + return Buffer.new(mpack.decode(s)) + end, + [1] = function(_c, s) + return Window.new(mpack.decode(s)) + end, + [2] = function(_c, s) + return Tabpage.new(mpack.decode(s)) + end, + }, + }), }), }, MsgpackRpcStream) end @@ -67,7 +85,7 @@ function MsgpackRpcStream:write(method, args, response_cb) data = self._session:notify() end - data = data .. self._pack(method) .. self._pack(args) + data = data .. self._pack(method) .. self._pack(args) self._stream:write(data) end @@ -80,12 +98,10 @@ function MsgpackRpcStream:read_start(request_cb, notification_cb, eof_cb) local pos = 1 local len = #data while pos <= len do - type, id_or_cb, method_or_error, args_or_result, pos = - self._session:receive(data, pos) + type, id_or_cb, method_or_error, args_or_result, pos = self._session:receive(data, pos) if type == 'request' or type == 'notification' then if type == 'request' then - request_cb(method_or_error, args_or_result, Response.new(self, - id_or_cb)) + request_cb(method_or_error, args_or_result, Response.new(self, id_or_cb)) else notification_cb(method_or_error, args_or_result) end |