From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4A4BB4696C3 for ; Tue, 28 Apr 2020 00:29:17 +0300 (MSK) References: <0d4129e35ccfa9cbfd8e4204e8179acb545cf46b.1587600640.git.v.shpilevoy@tarantool.org> <20200427151408.GD30870@tarantool.org> From: Vladislav Shpilevoy Message-ID: <8c6e8f5f-f5b4-48f3-6214-cbc62be3af8f@tarantool.org> Date: Mon, 27 Apr 2020 23:29:15 +0200 MIME-Version: 1.0 In-Reply-To: <20200427151408.GD30870@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH v2 2/3] box: introduce box_return_mp() public C function List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nikita Pettik Cc: tarantool-patches@dev.tarantool.org Thanks for the question! On 27/04/2020 17:14, Nikita Pettik wrote: > On 23 Apr 02:12, Vladislav Shpilevoy wrote: >> + >> +int >> +test_return_mp(box_function_ctx_t *ctx, const char *args, const char *args_end) >> +{ >> + (void) args; >> + (void) args_end; >> + char buf[512]; >> + char *pos = mp_encode_uint(buf, 1); >> + int rc = box_return_mp(ctx, buf, pos); >> + if (rc != 0) >> + return rc; >> + >> + pos = mp_encode_int(buf, -1); >> + rc = box_return_mp(ctx, buf, pos); >> + if (rc != 0) >> + return rc; >> + >> + pos = mp_encode_uint(buf, UINT64_MAX); >> + rc = box_return_mp(ctx, buf, pos); >> + if (rc != 0) >> + return rc; >> + >> + const char *str = "123456789101112131415"; >> + pos = mp_encode_str(buf, str, strlen(str)); >> + rc = box_return_mp(ctx, buf, pos); >> + if (rc != 0) >> + return rc; >> + >> + pos = mp_encode_array(buf, 1); >> + pos = mp_encode_uint(pos, 2); >> + box_tuple_t *tuple = box_tuple_new(box_tuple_format_default(), >> + buf, pos); >> + if (tuple == NULL) >> + return -1; >> + rc = box_return_tuple(ctx, tuple); > > Probably I'm missing something (since I've never used C API) but > when I do: > > res = net:connect(box.cfg.listen):call(name) > print(type(res[5])) > > I get table. But shouldn't it be tuple (cdata), since it (last member) > is explicitly wrapped into tuple)? I guess it is due to certain > convention but failed to find it in docs. Could you please clarify? That is not about C functions. It is about tuple data type lost during its marshaling over network. You will get the same result, if you write that in a Lua stored function. We solve that problem by introducing MP_EXT to be able to restore types on the client side for uuids, errors, decimals. But not for tuples. So they turn into tables when serialized-deserialized from MessagePack during sending over the network. Exception is IPROTO_SELECT and other DML/DQL mapped onto exact IPROTO_* commands, because client always knows they return tuples, and can create them on the client side instead of tables.