diff options
Diffstat (limited to 'src/nvim/msgpack_rpc/helpers.c')
-rw-r--r-- | src/nvim/msgpack_rpc/helpers.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c index 19cc31f6a6..3925dc546a 100644 --- a/src/nvim/msgpack_rpc/helpers.c +++ b/src/nvim/msgpack_rpc/helpers.c @@ -489,7 +489,7 @@ void msgpack_rpc_from_dictionary(Dictionary result, msgpack_packer *res) } /// Serializes a msgpack-rpc request or notification(id == 0) -void msgpack_rpc_serialize_request(uint64_t request_id, +void msgpack_rpc_serialize_request(uint32_t request_id, const String method, Array args, msgpack_packer *pac) @@ -499,7 +499,7 @@ void msgpack_rpc_serialize_request(uint64_t request_id, msgpack_pack_int(pac, request_id ? 0 : 2); if (request_id) { - msgpack_pack_uint64(pac, request_id); + msgpack_pack_uint32(pac, request_id); } msgpack_rpc_from_string(method, pac); @@ -507,7 +507,7 @@ void msgpack_rpc_serialize_request(uint64_t request_id, } /// Serializes a msgpack-rpc response -void msgpack_rpc_serialize_response(uint64_t response_id, +void msgpack_rpc_serialize_response(uint32_t response_id, Error *err, Object arg, msgpack_packer *pac) @@ -515,7 +515,7 @@ void msgpack_rpc_serialize_response(uint64_t response_id, { msgpack_pack_array(pac, 4); msgpack_pack_int(pac, 1); - msgpack_pack_uint64(pac, response_id); + msgpack_pack_uint32(pac, response_id); if (ERROR_SET(err)) { // error represented by a [type, message] array @@ -561,58 +561,57 @@ static msgpack_object *msgpack_rpc_msg_id(msgpack_object *req) return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER ? obj : NULL; } -void msgpack_rpc_validate(uint64_t *response_id, - msgpack_object *req, - Error *err) +MessageType msgpack_rpc_validate(uint32_t *response_id, msgpack_object *req, + Error *err) { - // response id not known yet - - *response_id = NO_RESPONSE; + *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; + return kMessageTypeUnknown; } if (req->via.array.size == 0) { api_set_error(err, kErrorTypeValidation, "Message is empty"); - return; + 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; + return kMessageTypeUnknown; } - uint64_t type = req->via.array.ptr[0].via.u64; + MessageType type = (MessageType)req->via.array.ptr[0].via.u64; if (type != kMessageTypeRequest && type != kMessageTypeNotification) { api_set_error(err, kErrorTypeValidation, "Unknown message type"); - return; + 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; + 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; + return type; } - *response_id = id_obj->via.u64; + *response_id = (uint32_t)id_obj->via.u64; } if (!msgpack_rpc_method(req)) { api_set_error(err, kErrorTypeValidation, "Method must be a string"); - return; + return type; } if (!msgpack_rpc_args(req)) { api_set_error(err, kErrorTypeValidation, "Parameters must be an array"); - return; + return type; } + + return type; } |