msgpack-rpc: Refactor initializer and dispatcher

Use Map(String, rpc_method_handler_fn) for storing/retrieving rpc method
handlers in msgpack_rpc_init and msgpack_rpc_dispatch.

Also refactor serialization/validation functions in the
msgpack_rpc.c/msgpack_rpc_helpers.c modules to accept the new STR and BIN types.
This commit is contained in:
Thiago de Arruda
2014-09-03 14:26:16 -03:00
parent c39ae3e4d4
commit 74aff19691
3 changed files with 33 additions and 26 deletions

View File

@@ -235,7 +235,8 @@ static char *msgpack_rpc_validate(uint64_t *response_id, msgpack_object *req)
}
if (req->via.array.ptr[2].type != MSGPACK_OBJECT_POSITIVE_INTEGER
&& req->via.array.ptr[2].type != MSGPACK_OBJECT_BIN) {
&& req->via.array.ptr[2].type != MSGPACK_OBJECT_BIN
&& req->via.array.ptr[2].type != MSGPACK_OBJECT_STR) {
return "Method must be a positive integer or a string";
}

View File

@@ -81,12 +81,13 @@ bool msgpack_rpc_to_float(msgpack_object *obj, Float *arg)
bool msgpack_rpc_to_string(msgpack_object *obj, String *arg)
{
if (obj->type != MSGPACK_OBJECT_BIN) {
if (obj->type == MSGPACK_OBJECT_BIN || obj->type == MSGPACK_OBJECT_STR) {
arg->data = xmemdupz(obj->via.bin.ptr, obj->via.bin.size);
arg->size = obj->via.bin.size;
} else {
return false;
}
arg->data = xmemdupz(obj->via.bin.ptr, obj->via.bin.size);
arg->size = obj->via.bin.size;
return true;
}
@@ -111,6 +112,7 @@ bool msgpack_rpc_to_object(msgpack_object *obj, Object *arg)
return msgpack_rpc_to_float(obj, &arg->data.floating);
case MSGPACK_OBJECT_BIN:
case MSGPACK_OBJECT_STR:
arg->type = kObjectTypeString;
return msgpack_rpc_to_string(obj, &arg->data.string);