diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-04-12 03:12:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-12 03:12:08 +0200 |
commit | e11a9d351a9f0ae278755e3c18bcc9aab05c1266 (patch) | |
tree | 1e90f9c9ae08f13688443cbbe22c6437fd716967 /src/nvim/msgpack_rpc/helpers.c | |
parent | b4ca56d96dcf0fe14150115a8826206710d0567a (diff) | |
parent | 8dbf23181add0393556bdb3f4d026e46c7dcbf1e (diff) | |
download | rneovim-e11a9d351a9f0ae278755e3c18bcc9aab05c1266.tar.gz rneovim-e11a9d351a9f0ae278755e3c18bcc9aab05c1266.tar.bz2 rneovim-e11a9d351a9f0ae278755e3c18bcc9aab05c1266.zip |
Merge pull request #9887 from justinmk/chan-notif-response-id
RPC: eliminate NO_RESPONSE
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; } |