Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Mergen Imeev <imeevma@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [PATCH v1 2/2] netbox: define formats for tuple from netbox
Date: Tue, 18 Jun 2019 12:00:42 +0300	[thread overview]
Message-ID: <20190618090042.cuzqje3n62qyhfdp@esperanza> (raw)
In-Reply-To: <20190614122920.GA3535@tarantool.org>

On Fri, Jun 14, 2019 at 03:29:21PM +0300, Mergen Imeev wrote:
> Second new patch:
> 
> From f9e959e3f0f38e8f6b8f1294ba29c28d41f30968 Mon Sep 17 00:00:00 2001
> Date: Tue, 11 Jun 2019 16:36:39 +0300
> Subject: [PATCH] netbox: define formats for tuple from netbox
> 
> This patch creates tuple_formats for the tuples obtained through
> the netbox.
> 
> Closes #2978
> 
> @TarantoolBot document
> Title: Field names for tuples received from net.box
> 
> It is possible now to access by field name for tuples received
> from net.box. For example:
> 
> box.cfg{listen = 3302}
> box.schema.user.grant('guest','read, write, execute', 'space')
> box.schema.user.grant('guest', 'create', 'space')
> 
> box.schema.create_space("named", {format = {{name = "id"}}})
> box.space.named:create_index('id', {parts = {{1, 'unsigned'}}})
> box.space.named:insert({1})
> require('net.box').connect('localhost', 3302).space.named:get(1).id
> 
> Result:
> 
> tarantool> require('net.box').connect('localhost', 3302).space.named:get(1).id
> ---
> - 1
> ...
> 
> diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c
> index 7484a86..946d397 100644
> --- a/src/box/lua/net_box.c
> +++ b/src/box/lua/net_box.c
> @@ -590,12 +590,11 @@ netbox_encode_execute(lua_State *L)
>   * @param data MessagePack.
>   */
>  static void
> -netbox_decode_data(struct lua_State *L, const char **data)
> +netbox_decode_data(struct lua_State *L, const char **data,
> +		   struct tuple_format *format)
>  {
>  	uint32_t count = mp_decode_array(data);
>  	lua_createtable(L, count, 0);
> -	struct tuple_format *format =
> -		box_tuple_format_default();
>  	for (uint32_t j = 0; j < count; ++j) {
>  		const char *begin = *data;
>  		mp_next(data);
> @@ -618,6 +617,15 @@ static int
>  netbox_decode_select(struct lua_State *L)
>  {
>  	uint32_t ctypeid;
> +	int top = lua_gettop(L);
> +	assert(top == 1 || top == 2);
> +	struct tuple_format *format;
> +	if (top == 2 && lua_type(L, 2) == LUA_TCDATA) {
> +		format = *(struct tuple_format **)luaL_checkcdata(L, 2,
> +								  &ctypeid);

I think we should use lbox_check_tuple_format helper from the previous
patch here.

Other than that, this patch looks good to me.

> +	} else {
> +		format = tuple_format_runtime;
> +	}
>  	const char *data = *(const char **)luaL_checkcdata(L, 1, &ctypeid);
>  	assert(mp_typeof(*data) == MP_MAP);
>  	uint32_t map_size = mp_decode_map(&data);

  parent reply	other threads:[~2019-06-18  9:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-10 10:02 [PATCH v1 0/2] " imeevma
2019-06-10 10:02 ` [PATCH v1 1/2] netbox: store method_encoder args in request imeevma
2019-06-11  8:15   ` Vladimir Davydov
2019-06-14 11:50     ` Mergen Imeev
2019-06-18  8:38       ` Vladimir Davydov
2019-06-10 10:02 ` [PATCH v1 2/2] netbox: define formats for tuple from netbox imeevma
2019-06-11  8:55   ` Vladimir Davydov
2019-06-14 12:29     ` Mergen Imeev
2019-06-18  8:55       ` Vladimir Davydov
2019-06-18  9:00       ` Vladimir Davydov [this message]
2019-06-11  8:55 ` [PATCH v1 0/2] " Vladimir Davydov
2019-06-14 12:32   ` Mergen Imeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190618090042.cuzqje3n62qyhfdp@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v1 2/2] netbox: define formats for tuple from netbox' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox