aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/msgpack_rpc/unpacker.h
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-05-23 19:53:19 +0200
committerbfredl <bjorn.linse@gmail.com>2022-06-02 16:05:24 +0200
commitd5f047bee04a42f40425c34061c84b39af846e1f (patch)
treed81bb803389467604e2ad319b54b211415594ce6 /src/nvim/msgpack_rpc/unpacker.h
parentd93ba03c717bee05fe6d239fd7faefe6e9698c85 (diff)
downloadrneovim-d5f047bee04a42f40425c34061c84b39af846e1f.tar.gz
rneovim-d5f047bee04a42f40425c34061c84b39af846e1f.tar.bz2
rneovim-d5f047bee04a42f40425c34061c84b39af846e1f.zip
refactor(api): use a unpacker based on libmpack instead of msgpack-c
Currently this is more or less a straight off reimplementation, but this allow further optimizations down the line, especially for avoiding memory allocations of rpc objects. Current score for "make functionaltest; make oldtest" on a -DEXITFREE build: is 117 055 352 xfree(ptr != NULL) calls (that's NUMBERWANG!).
Diffstat (limited to 'src/nvim/msgpack_rpc/unpacker.h')
-rw-r--r--src/nvim/msgpack_rpc/unpacker.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/nvim/msgpack_rpc/unpacker.h b/src/nvim/msgpack_rpc/unpacker.h
new file mode 100644
index 0000000000..bbd6b1ef4f
--- /dev/null
+++ b/src/nvim/msgpack_rpc/unpacker.h
@@ -0,0 +1,40 @@
+#ifndef NVIM_MSGPACK_RPC_UNPACKER_H
+#define NVIM_MSGPACK_RPC_UNPACKER_H
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "mpack/mpack_core.h"
+#include "mpack/object.h"
+#include "nvim/api/private/dispatch.h"
+#include "nvim/api/private/helpers.h"
+
+typedef struct {
+ mpack_parser_t parser;
+ mpack_tokbuf_t reader;
+
+ const char *read_ptr;
+ size_t read_size;
+
+#define MAX_EXT_LEN 9 // byte + 8-byte integer
+ char ext_buf[MAX_EXT_LEN];
+
+ int state;
+ MessageType type;
+ uint32_t request_id;
+ size_t method_name_len;
+ MsgpackRpcRequestHandler handler;
+ Object error; // error return
+ Object result; // arg list or result
+ Error unpack_error;
+} Unpacker;
+
+// unrecovareble error. unpack_error should be set!
+#define unpacker_closed(p) ((p)->state < 0)
+
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "msgpack_rpc/unpacker.h.generated.h"
+#endif
+
+#endif // NVIM_MSGPACK_RPC_UNPACKER_H