Tarantool development patches archive
 help / color / mirror / Atom feed
From: AlexeyIvushkin <ivushkinalex@gmail.com>
To: tarantool-patches@freelists.org
Cc: Morgan-iv <ivushkinalex@gmail.com>
Subject: [tarantool-patches] [PATCH] box: add tuple:size function
Date: Thu, 27 Sep 2018 20:55:23 +0300	[thread overview]
Message-ID: <1538070923-23087-1-git-send-email-ivushkinalex@gmail.com> (raw)

From: Morgan-iv <ivushkinalex@gmail.com>

When operating with tuples, we only have tuple:bsize function
to get size of tuple. tuple:bsize returns only size of MessagePack
part of struct tuple, without tuple_meta. New function tuple:size
returns size of all tuple, with MessagePack and tuple_meta

Closes #2256
---
https://github.com/tarantool/tarantool/issues/2256
https://github.com/tarantool/tarantool/tree/Morgan-iv/gh-2256
 src/box/lua/tuple.c     | 10 ++++++++++
 src/box/lua/tuple.lua   |  1 +
 test/box/tuple.result   | 12 ++++++++++++
 test/box/tuple.test.lua |  6 ++++++
 4 files changed, 29 insertions(+)

diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
index 65660ce..1ae49d6 100644
--- a/src/box/lua/tuple.c
+++ b/src/box/lua/tuple.c
@@ -489,6 +489,15 @@ lbox_tuple_to_string(struct lua_State *L)
 	return 1;
 }
 
+static int
+lbox_tuple_size(struct lua_State *L)
+{
+	struct tuple *tuple = lua_checktuple(L, 1);
+	size_t size = tuple_size(tuple);
+	lua_pushinteger(L, size);
+	return 1;
+}
+
 void
 luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple)
 {
@@ -506,6 +515,7 @@ static const struct luaL_Reg lbox_tuple_meta[] = {
 	{"__gc", lbox_tuple_gc},
 	{"tostring", lbox_tuple_to_string},
 	{"slice", lbox_tuple_slice},
+	{"size", lbox_tuple_size},
 	{"transform", lbox_tuple_transform},
 	{"tuple_to_map", lbox_tuple_to_map},
 	{"tuple_field_by_path", lbox_tuple_field_by_path},
diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua
index 63ea73e..801ee3c 100644
--- a/src/box/lua/tuple.lua
+++ b/src/box/lua/tuple.lua
@@ -286,6 +286,7 @@ local methods = {
     ["update"]      = tuple_update;
     ["upsert"]      = tuple_upsert;
     ["bsize"]       = tuple_bsize;
+    ["size"]        = internal.tuple.size;
     ["tomap"]       = internal.tuple.tuple_to_map;
 }
 
diff --git a/test/box/tuple.result b/test/box/tuple.result
index e035cb9..418f5f8 100644
--- a/test/box/tuple.result
+++ b/test/box/tuple.result
@@ -186,6 +186,18 @@ t:bsize()
 ---
 - 5
 ...
+-- tuple:size()
+t = box.tuple.new('abc')
+---
+...
+t
+---
+- ['abc']
+...
+t:size()
+---
+- 15
+...
 --
 -- Test cases for #106 box.tuple.new fails on multiple items
 --
diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua
index 9df978d..7f4e2b3 100644
--- a/test/box/tuple.test.lua
+++ b/test/box/tuple.test.lua
@@ -49,6 +49,12 @@ t = box.tuple.new('abc')
 t
 t:bsize()
 
+-- tuple:size()
+
+t = box.tuple.new('abc')
+t
+t:size()
+
 --
 -- Test cases for #106 box.tuple.new fails on multiple items
 --
-- 
2.7.4

             reply	other threads:[~2018-09-27 17:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-27 17:55 AlexeyIvushkin [this message]
2018-10-03 14:20 ` [tarantool-patches] " Vladislav Shpilevoy
2018-10-03 15:05   ` Vladislav Shpilevoy
2018-10-05 10:23 ` [tarantool-patches] " Vladimir Davydov
2018-10-06 13:58   ` [tarantool-patches] " Vladislav Shpilevoy
2018-10-08 10:16     ` Vladimir Davydov
2018-10-10 10:25       ` Vladislav Shpilevoy
2018-10-16 18:21 ` Konstantin Osipov
2018-10-17  7:28   ` Alexander Turenko
2018-10-17 15:29     ` Konstantin Osipov
2018-10-17 15:50       ` Alexander Turenko
2018-10-18 18:11         ` Konstantin Osipov
2018-10-18 18:15           ` Alexander Turenko
2018-10-17 18:06       ` Vladislav Shpilevoy
2018-10-17 18:10         ` Vladislav Shpilevoy
2018-10-17 18:14         ` Konstantin Osipov
2018-10-17 18:20           ` Alexander Turenko
2018-10-17 20:36           ` Vladislav Shpilevoy
2018-10-02 20:50 [tarantool-patches] [PATCH 0/2] First part of SQLite error codes refactoring AlexeyIvushkin
2018-10-02 20:50 ` [tarantool-patches] [PATCH] box: add tuple:size function AlexeyIvushkin

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=1538070923-23087-1-git-send-email-ivushkinalex@gmail.com \
    --to=ivushkinalex@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] box: add tuple:size function' \
    /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