Tarantool development patches archive
 help / color / mirror / Atom feed
From: Timur Safin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH resend v2 07/11] lua, datetime: proper datetime encoding
Date: Wed, 28 Jul 2021 13:34:09 +0300
Message-ID: <509f7a039e57914ef5a869735b1136fbd969a52b.1627468002.git.tsafin@tarantool.org> (raw)
In-Reply-To: <cover.1627468002.git.tsafin@tarantool.org>

* correct incorrect encoding of MP_EXT sizes for datetime
  messagepack values;
* export necessary symbols for datetime messagepack size calculations
  so they will be available for Lua consumption.

Part of #5941
---
 src/exports.h           |  2 ++
 src/lib/core/datetime.c | 15 ++++++++++-----
 src/lua/msgpackffi.lua  | 10 ++++++++++
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/exports.h b/src/exports.h
index 586444b65..3a1e8854c 100644
--- a/src/exports.h
+++ b/src/exports.h
@@ -437,6 +437,7 @@ EXPORT(mp_encode_decimal)
 EXPORT(mp_encode_double)
 EXPORT(mp_encode_float)
 EXPORT(mp_encode_uuid)
+EXPORT(mp_encode_datetime)
 EXPORT(mp_ext_hint)
 EXPORT(mp_format)
 EXPORT(mp_fprint)
@@ -446,6 +447,7 @@ EXPORT(mp_fprint_recursion)
 EXPORT(mp_parser_hint)
 EXPORT(mp_sizeof_decimal)
 EXPORT(mp_sizeof_uuid)
+EXPORT(mp_sizeof_datetime)
 EXPORT(mp_snprint)
 EXPORT(mp_snprint_ext)
 EXPORT(mp_snprint_ext_default)
diff --git a/src/lib/core/datetime.c b/src/lib/core/datetime.c
index 26ba8a702..76b06eae5 100755
--- a/src/lib/core/datetime.c
+++ b/src/lib/core/datetime.c
@@ -83,8 +83,8 @@ mp_decode_Xint(const char **data)
 	return 0;
 }
 
-uint32_t
-mp_sizeof_datetime(const struct datetime_t *date)
+static inline uint32_t
+mp_sizeof_datetime_raw(const struct datetime_t *date)
 {
 	uint32_t sz = mp_sizeof_Xint(date->secs);
 
@@ -94,10 +94,15 @@ mp_sizeof_datetime(const struct datetime_t *date)
 		sz += mp_sizeof_Xint(date->nsec);
 	if (date->offset)
 		sz += mp_sizeof_Xint(date->offset);
-
 	return sz;
 }
 
+uint32_t
+mp_sizeof_datetime(const struct datetime_t *date)
+{
+	return mp_sizeof_ext(mp_sizeof_datetime_raw(date));
+}
+
 struct datetime_t *
 datetime_unpack(const char **data, uint32_t len, struct datetime_t *date)
 {
@@ -112,7 +117,7 @@ datetime_unpack(const char **data, uint32_t len, struct datetime_t *date)
 		return date;
 
 	svp = *data;
-	date->secs = mp_decode_Xint(data);
+	date->nsec = mp_decode_Xint(data);
 	len -= *data - svp;
 
 	if (len <= 0)
@@ -153,7 +158,7 @@ datetime_pack(char *data, const struct datetime_t *date)
 char *
 mp_encode_datetime(char *data, const struct datetime_t *date)
 {
-	uint32_t len = mp_sizeof_datetime(date);
+	uint32_t len = mp_sizeof_datetime_raw(date);
 
 	data = mp_encode_extl(data, MP_DATETIME, len);
 
diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua
index 271be857a..c47d77acb 100644
--- a/src/lua/msgpackffi.lua
+++ b/src/lua/msgpackffi.lua
@@ -26,6 +26,10 @@ char *
 mp_encode_uuid(char *data, const struct tt_uuid *uuid);
 uint32_t
 mp_sizeof_uuid();
+uint32_t
+mp_sizeof_datetime(const struct t_datetime_tz *date);
+char *
+mp_encode_datetime(char *data, const struct t_datetime_tz *date);
 float
 mp_decode_float(const char **data);
 double
@@ -144,6 +148,11 @@ local function encode_uuid(buf, uuid)
     builtin.mp_encode_uuid(p, uuid)
 end
 
+local function encode_datetime(buf, date)
+    local p = buf:alloc(builtin.mp_sizeof_datetime(date))
+    builtin.mp_encode_datetime(p, date)
+end
+
 local function encode_int(buf, num)
     if num >= 0 then
         if num <= 0x7f then
@@ -322,6 +331,7 @@ on_encode(ffi.typeof('float'), encode_float)
 on_encode(ffi.typeof('double'), encode_double)
 on_encode(ffi.typeof('decimal_t'), encode_decimal)
 on_encode(ffi.typeof('struct tt_uuid'), encode_uuid)
+on_encode(ffi.typeof('struct datetime_t'), encode_datetime)
 
 --------------------------------------------------------------------------------
 -- Decoder
-- 
2.29.2


  parent reply	other threads:[~2021-07-28 10:37 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28 10:34 [Tarantool-patches] [PATCH resend v2 00/11] Initial datetime support Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 01/11] build: add Christian Hansen c-dt to the build Timur Safin via Tarantool-patches
2021-07-29 23:40   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-31  9:22     ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 02/11] lua: built-in module datetime Timur Safin via Tarantool-patches
2021-07-29 18:55   ` Oleg Babin via Tarantool-patches
2021-07-30 19:00     ` Timur Safin via Tarantool-patches
2021-07-31  6:29       ` Oleg Babin via Tarantool-patches
2021-07-31 16:51         ` Timur Safin via Tarantool-patches
2021-07-29 23:36   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-30 15:39     ` Timur Safin via Tarantool-patches
2021-08-01 17:01       ` Vladislav Shpilevoy via Tarantool-patches
2021-08-01 20:23         ` Timur Safin via Tarantool-patches
2021-08-04 23:57           ` Vladislav Shpilevoy via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 03/11] lua, datetime: datetime tests Timur Safin via Tarantool-patches
2021-07-29 18:55   ` Oleg Babin via Tarantool-patches
2021-07-30 20:45     ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 04/11] lua, datetime: display datetime Timur Safin via Tarantool-patches
2021-07-29 18:55   ` Oleg Babin via Tarantool-patches
2021-07-30 21:48     ` Timur Safin via Tarantool-patches
2021-07-31  6:29       ` Oleg Babin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 05/11] box, datetime: add messagepack support for datetime Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 06/11] box, datetime: datetime comparison for indices Timur Safin via Tarantool-patches
2021-07-29 18:56   ` Oleg Babin via Tarantool-patches
2021-07-30 22:18     ` Timur Safin via Tarantool-patches
2021-07-31  6:30       ` Oleg Babin via Tarantool-patches
2021-07-31  9:31         ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` Timur Safin via Tarantool-patches [this message]
2021-07-29 18:57   ` [Tarantool-patches] [PATCH resend v2 07/11] lua, datetime: proper datetime encoding Oleg Babin via Tarantool-patches
2021-07-30 22:20     ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 08/11] lua, datetime: calculated attributes for datetimes Timur Safin via Tarantool-patches
2021-07-29 18:57   ` Oleg Babin via Tarantool-patches
2021-07-30 22:30     ` Timur Safin via Tarantool-patches
2021-07-31  6:31       ` Oleg Babin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 09/11] lua, datetime: time intervals support Timur Safin via Tarantool-patches
2021-07-29 18:58   ` Oleg Babin via Tarantool-patches
2021-07-30 22:58     ` Timur Safin via Tarantool-patches
2021-07-31  6:31       ` Oleg Babin via Tarantool-patches
2021-07-31  9:20         ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 10/11] lua, datetime: unixtime, timestamp setters in datetime.lua Timur Safin via Tarantool-patches
2021-07-29 18:58   ` Oleg Babin via Tarantool-patches
2021-07-30 23:11     ` Timur Safin via Tarantool-patches
2021-07-31  6:31       ` Oleg Babin via Tarantool-patches
2021-07-31  9:54         ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 11/11] datetime: changelog for datetime module Timur Safin via Tarantool-patches
2021-07-29 18:55 ` [Tarantool-patches] [PATCH resend v2 00/11] Initial datetime support Oleg Babin via Tarantool-patches

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=509f7a039e57914ef5a869735b1136fbd969a52b.1627468002.git.tsafin@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=tsafin@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    /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

Tarantool development patches archive

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lists.tarantool.org/tarantool-patches/0 tarantool-patches/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 tarantool-patches tarantool-patches/ https://lists.tarantool.org/tarantool-patches \
		tarantool-patches@dev.tarantool.org.
	public-inbox-index tarantool-patches

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git