aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/msgpack_rpc.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-06-18 12:16:53 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-06-18 12:16:53 -0300
commit090870ca047dee8d136f863ba742922fc265d6f4 (patch)
tree28b5852d5c6ed9ebc415209d9c42bafa651b53b3 /src/nvim/os/msgpack_rpc.c
parentd199d18159c624844c9c8052d1a98b91084fb803 (diff)
parenta7d027c8ab289d76eda91b6afe3be63a165d4adf (diff)
downloadrneovim-090870ca047dee8d136f863ba742922fc265d6f4.tar.gz
rneovim-090870ca047dee8d136f863ba742922fc265d6f4.tar.bz2
rneovim-090870ca047dee8d136f863ba742922fc265d6f4.zip
Merge PR #853
Diffstat (limited to 'src/nvim/os/msgpack_rpc.c')
-rw-r--r--src/nvim/os/msgpack_rpc.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/nvim/os/msgpack_rpc.c b/src/nvim/os/msgpack_rpc.c
index 932a7717fd..63e1245028 100644
--- a/src/nvim/os/msgpack_rpc.c
+++ b/src/nvim/os/msgpack_rpc.c
@@ -79,11 +79,13 @@ void msgpack_rpc_call(uint64_t id, msgpack_object *req, msgpack_packer *res)
"Request array size is %u, it should be 4",
req->via.array.size);
msgpack_rpc_error(error_msg, res);
+ return;
}
if (req->via.array.ptr[1].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
msgpack_pack_int(res, 0); // no message id yet
msgpack_rpc_error("Id must be a positive integer", res);
+ return;
}
// Set the response id, which is the same as the request
@@ -398,6 +400,31 @@ void msgpack_rpc_free_dictionary(Dictionary value)
free(value.items);
}
+UnpackResult msgpack_rpc_unpack(msgpack_unpacker* unpacker,
+ msgpack_unpacked* result)
+{
+ if (result->zone != NULL) {
+ msgpack_zone_free(result->zone);
+ }
+
+ int res = msgpack_unpacker_execute(unpacker);
+
+ if (res > 0) {
+ result->zone = msgpack_unpacker_release_zone(unpacker);
+ result->data = msgpack_unpacker_data(unpacker);
+ msgpack_unpacker_reset(unpacker);
+ return kUnpackResultOk;
+ }
+
+ if (res < 0) {
+ // Since we couldn't parse it, destroy the data consumed so far
+ msgpack_unpacker_reset(unpacker);
+ return kUnpackResultFail;
+ }
+
+ return kUnpackResultNeedMore;
+}
+
REMOTE_FUNCS_IMPL(Buffer, buffer)
REMOTE_FUNCS_IMPL(Window, window)
REMOTE_FUNCS_IMPL(Tabpage, tabpage)