diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-09-03 16:22:05 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-09-12 13:25:28 -0300 |
commit | cd70b9c0152f79887ed548e6cf8992ae2121fedb (patch) | |
tree | a57bca6386d4156382b14a54f5d5b343bc16b7d9 /src | |
parent | 19bc29ee834516ff76944741b25fe158d2282b15 (diff) | |
download | rneovim-cd70b9c0152f79887ed548e6cf8992ae2121fedb.tar.gz rneovim-cd70b9c0152f79887ed548e6cf8992ae2121fedb.tar.bz2 rneovim-cd70b9c0152f79887ed548e6cf8992ae2121fedb.zip |
msgpack-rpc: Refactor API metadata discovery method
A new method is now exposed via msgpack-rpc: "get_api_metadata". This method has
the same job as the old method '0', it returns an object with API metadata for
use by generators.
There's one difference in the return value though: instead of returning a
string containing another serialized msgpack document, the metadata object is
returned directly(a separate deserialization step by clients is not required).
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/os/msgpack_rpc.c | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/src/nvim/os/msgpack_rpc.c b/src/nvim/os/msgpack_rpc.c index 4a586e8e01..b06c8ee597 100644 --- a/src/nvim/os/msgpack_rpc.c +++ b/src/nvim/os/msgpack_rpc.c @@ -17,8 +17,7 @@ # include "os/msgpack_rpc.c.generated.h" #endif -extern const uint8_t msgpack_metadata[]; -extern const unsigned int msgpack_metadata_size; +extern msgpack_unpacked msgpack_unpacked_metadata; /// Validates the basic structure of the msgpack-rpc call and fills `res` /// with the basic response structure. @@ -39,11 +38,6 @@ WBuffer *msgpack_rpc_call(uint64_t channel_id, return serialize_response(response_id, err, NIL, sbuffer); } - if (req->via.array.ptr[2].type == MSGPACK_OBJECT_POSITIVE_INTEGER - && req->via.array.ptr[2].via.u64 == 0) { - return serialize_metadata(response_id, channel_id, sbuffer); - } - // dispatch the call Error error = { .set = false }; Object rv = msgpack_rpc_dispatch(channel_id, req, &error); @@ -125,6 +119,19 @@ Object msgpack_rpc_handle_missing_method(uint64_t channel_id, return NIL; } +/// Handler for retrieving API metadata through a msgpack-rpc call +Object msgpack_rpc_handle_get_api_metadata(uint64_t channel_id, + msgpack_object *req, + Error *error) +{ + Array rv = ARRAY_DICT_INIT; + Object metadata; + msgpack_rpc_to_object(&msgpack_unpacked_metadata.data, &metadata); + ADD(rv, INTEGER_OBJ((int64_t)channel_id)); + ADD(rv, metadata); + return ARRAY_OBJ(rv); +} + /// Serializes a msgpack-rpc request or notification(id == 0) WBuffer *serialize_request(uint64_t request_id, String method, @@ -190,31 +197,6 @@ WBuffer *serialize_response(uint64_t response_id, return rv; } -WBuffer *serialize_metadata(uint64_t id, - uint64_t channel_id, - msgpack_sbuffer *sbuffer) - FUNC_ATTR_NONNULL_ALL -{ - msgpack_packer pac; - msgpack_packer_init(&pac, sbuffer, msgpack_sbuffer_write); - msgpack_pack_array(&pac, 4); - msgpack_pack_int(&pac, 1); - msgpack_pack_uint64(&pac, id); - // Nil error - msgpack_pack_nil(&pac); - // The result is the [channel_id, metadata] array - msgpack_pack_array(&pac, 2); - msgpack_pack_uint64(&pac, channel_id); - msgpack_pack_bin(&pac, msgpack_metadata_size); - msgpack_pack_bin_body(&pac, msgpack_metadata, msgpack_metadata_size); - WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size), - sbuffer->size, - 1, - free); - msgpack_sbuffer_clear(sbuffer); - return rv; -} - static char *msgpack_rpc_validate(uint64_t *response_id, msgpack_object *req) { // response id not known yet |