aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-02-26 14:46:32 +0100
committerbfredl <bjorn.linse@gmail.com>2024-02-26 14:47:47 +0100
commitcdcdc10411b460b6f69aeb01bcd8bb8dcd97c5c4 (patch)
treecb5573cf68871dbfc7c47590121691eb6fc6ba88
parent7038fdeee2561ef29bd41e3f5ac54823c76d8143 (diff)
downloadrneovim-cdcdc10411b460b6f69aeb01bcd8bb8dcd97c5c4.tar.gz
rneovim-cdcdc10411b460b6f69aeb01bcd8bb8dcd97c5c4.tar.bz2
rneovim-cdcdc10411b460b6f69aeb01bcd8bb8dcd97c5c4.zip
refactor(msgpack): remove dead unpacker code in helpers
Unpacker code now lives in unpacker.c This was part of the old unpacker which I forgor to remove.
-rw-r--r--src/nvim/msgpack_rpc/helpers.c87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c
index c0c519848c..bc1eefb270 100644
--- a/src/nvim/msgpack_rpc/helpers.c
+++ b/src/nvim/msgpack_rpc/helpers.c
@@ -1,7 +1,6 @@
#include <msgpack/object.h>
#include <msgpack/sbuffer.h>
#include <msgpack/unpack.h>
-#include <msgpack/zone.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -19,19 +18,16 @@
# include "msgpack_rpc/helpers.c.generated.h"
#endif
-static msgpack_zone zone;
static msgpack_sbuffer sbuffer;
void msgpack_rpc_helpers_init(void)
{
- msgpack_zone_init(&zone, 0xfff);
msgpack_sbuffer_init(&sbuffer);
}
#ifdef EXITFREE
void msgpack_rpc_helpers_free_all_mem(void)
{
- msgpack_zone_destroy(&zone);
msgpack_sbuffer_destroy(&sbuffer);
}
#endif
@@ -247,86 +243,3 @@ void msgpack_rpc_serialize_response(uint32_t response_id, Error *err, Object *ar
msgpack_rpc_from_object(arg, pac);
}
}
-
-static bool msgpack_rpc_is_notification(msgpack_object *req)
-{
- return req->via.array.ptr[0].via.u64 == 2;
-}
-
-msgpack_object *msgpack_rpc_method(msgpack_object *req)
-{
- msgpack_object *obj = req->via.array.ptr
- + (msgpack_rpc_is_notification(req) ? 1 : 2);
- return obj->type == MSGPACK_OBJECT_STR || obj->type == MSGPACK_OBJECT_BIN
- ? obj : NULL;
-}
-
-msgpack_object *msgpack_rpc_args(msgpack_object *req)
-{
- msgpack_object *obj = req->via.array.ptr
- + (msgpack_rpc_is_notification(req) ? 2 : 3);
- return obj->type == MSGPACK_OBJECT_ARRAY ? obj : NULL;
-}
-
-static msgpack_object *msgpack_rpc_msg_id(msgpack_object *req)
-{
- if (msgpack_rpc_is_notification(req)) {
- return NULL;
- }
- msgpack_object *obj = &req->via.array.ptr[1];
- return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER ? obj : NULL;
-}
-
-MessageType msgpack_rpc_validate(uint32_t *response_id, msgpack_object *req, Error *err)
-{
- *response_id = 0;
- // Validate the basic structure of the msgpack-rpc payload
- if (req->type != MSGPACK_OBJECT_ARRAY) {
- api_set_error(err, kErrorTypeValidation, "Message is not an array");
- return kMessageTypeUnknown;
- }
-
- if (req->via.array.size == 0) {
- api_set_error(err, kErrorTypeValidation, "Message is empty");
- return kMessageTypeUnknown;
- }
-
- if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
- api_set_error(err, kErrorTypeValidation, "Message type must be an integer");
- return kMessageTypeUnknown;
- }
-
- MessageType type = (MessageType)req->via.array.ptr[0].via.u64;
- if (type != kMessageTypeRequest && type != kMessageTypeNotification) {
- api_set_error(err, kErrorTypeValidation, "Unknown message type");
- return kMessageTypeUnknown;
- }
-
- if ((type == kMessageTypeRequest && req->via.array.size != 4)
- || (type == kMessageTypeNotification && req->via.array.size != 3)) {
- api_set_error(err, kErrorTypeValidation,
- "Request array size must be 4 (request) or 3 (notification)");
- return type;
- }
-
- if (type == kMessageTypeRequest) {
- msgpack_object *id_obj = msgpack_rpc_msg_id(req);
- if (!id_obj) {
- api_set_error(err, kErrorTypeValidation, "ID must be a positive integer");
- return type;
- }
- *response_id = (uint32_t)id_obj->via.u64;
- }
-
- if (!msgpack_rpc_method(req)) {
- api_set_error(err, kErrorTypeValidation, "Method must be a string");
- return type;
- }
-
- if (!msgpack_rpc_args(req)) {
- api_set_error(err, kErrorTypeValidation, "Parameters must be an array");
- return type;
- }
-
- return type;
-}