mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
api/msgpack-rpc: Use EXT type to serialize Buffer/Window/Tabpage
This commit is contained in:
@@ -7,16 +7,46 @@
|
|||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
|
|
||||||
#define REMOTE_FUNCS_IMPL(t, lt) \
|
static msgpack_zone zone;
|
||||||
|
static msgpack_sbuffer sbuffer;
|
||||||
|
|
||||||
|
#define HANDLE_TYPE_CONVERSION_IMPL(t, lt) \
|
||||||
bool msgpack_rpc_to_##lt(msgpack_object *obj, t *arg) \
|
bool msgpack_rpc_to_##lt(msgpack_object *obj, t *arg) \
|
||||||
{ \
|
{ \
|
||||||
*arg = obj->via.u64; \
|
if (obj->type != MSGPACK_OBJECT_EXT \
|
||||||
return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER; \
|
|| obj->via.ext.type != kObjectType##t) { \
|
||||||
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void msgpack_rpc_from_##lt(t result, msgpack_packer *res) \
|
msgpack_object data; \
|
||||||
|
msgpack_unpack_return ret = msgpack_unpack(obj->via.ext.ptr, \
|
||||||
|
obj->via.ext.size, \
|
||||||
|
NULL, \
|
||||||
|
&zone, \
|
||||||
|
&data); \
|
||||||
|
\
|
||||||
|
if (ret != MSGPACK_UNPACK_SUCCESS) { \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
*arg = data.via.u64; \
|
||||||
|
return true; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
void msgpack_rpc_from_##lt(t o, msgpack_packer *res) \
|
||||||
{ \
|
{ \
|
||||||
msgpack_pack_uint64(res, result); \
|
msgpack_packer pac; \
|
||||||
|
msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \
|
||||||
|
msgpack_pack_uint64(&pac, o); \
|
||||||
|
msgpack_pack_ext(res, sbuffer.size, kObjectType##t); \
|
||||||
|
msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \
|
||||||
|
msgpack_sbuffer_clear(&sbuffer); \
|
||||||
|
}
|
||||||
|
|
||||||
|
void msgpack_rpc_helpers_init(void)
|
||||||
|
{
|
||||||
|
msgpack_zone_init(&zone, 0xfff);
|
||||||
|
msgpack_sbuffer_init(&sbuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool msgpack_rpc_to_boolean(msgpack_object *obj, Boolean *arg)
|
bool msgpack_rpc_to_boolean(msgpack_object *obj, Boolean *arg)
|
||||||
@@ -88,6 +118,15 @@ bool msgpack_rpc_to_object(msgpack_object *obj, Object *arg)
|
|||||||
arg->type = kObjectTypeDictionary;
|
arg->type = kObjectTypeDictionary;
|
||||||
return msgpack_rpc_to_dictionary(obj, &arg->data.dictionary);
|
return msgpack_rpc_to_dictionary(obj, &arg->data.dictionary);
|
||||||
|
|
||||||
|
case MSGPACK_OBJECT_EXT:
|
||||||
|
switch (obj->via.ext.type) {
|
||||||
|
case kObjectTypeBuffer:
|
||||||
|
return msgpack_rpc_to_buffer(obj, &arg->data.buffer);
|
||||||
|
case kObjectTypeWindow:
|
||||||
|
return msgpack_rpc_to_window(obj, &arg->data.window);
|
||||||
|
case kObjectTypeTabpage:
|
||||||
|
return msgpack_rpc_to_tabpage(obj, &arg->data.tabpage);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -303,6 +342,6 @@ void msgpack_rpc_free_dictionary(Dictionary value)
|
|||||||
free(value.items);
|
free(value.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
REMOTE_FUNCS_IMPL(Buffer, buffer)
|
HANDLE_TYPE_CONVERSION_IMPL(Buffer, buffer)
|
||||||
REMOTE_FUNCS_IMPL(Window, window)
|
HANDLE_TYPE_CONVERSION_IMPL(Window, window)
|
||||||
REMOTE_FUNCS_IMPL(Tabpage, tabpage)
|
HANDLE_TYPE_CONVERSION_IMPL(Tabpage, tabpage)
|
||||||
|
@@ -9,6 +9,8 @@
|
|||||||
#include "nvim/func_attr.h"
|
#include "nvim/func_attr.h"
|
||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
|
|
||||||
|
void msgpack_rpc_helpers_init(void);
|
||||||
|
|
||||||
/// Functions for validating and converting from msgpack types to C types.
|
/// Functions for validating and converting from msgpack types to C types.
|
||||||
/// These are used by `msgpack_rpc_dispatch` to validate and convert each
|
/// These are used by `msgpack_rpc_dispatch` to validate and convert each
|
||||||
/// argument.
|
/// argument.
|
||||||
|
@@ -55,6 +55,7 @@
|
|||||||
#include "nvim/os/signal.h"
|
#include "nvim/os/signal.h"
|
||||||
#include "nvim/os/job.h"
|
#include "nvim/os/job.h"
|
||||||
#include "nvim/os/msgpack_rpc.h"
|
#include "nvim/os/msgpack_rpc.h"
|
||||||
|
#include "nvim/os/msgpack_rpc_helpers.h"
|
||||||
|
|
||||||
#if defined(HAVE_SYS_IOCTL_H)
|
#if defined(HAVE_SYS_IOCTL_H)
|
||||||
# include <sys/ioctl.h>
|
# include <sys/ioctl.h>
|
||||||
@@ -166,6 +167,7 @@ void mch_init(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
msgpack_rpc_init();
|
msgpack_rpc_init();
|
||||||
|
msgpack_rpc_helpers_init();
|
||||||
event_init();
|
event_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user