[Tarantool-patches] [PATCH v5 4/8] box, datetime: messagepack support for datetime
Serge Petrenko
sergepetrenko at tarantool.org
Tue Aug 17 15:15:51 MSK 2021
16.08.2021 03:20, Safin Timur via Tarantool-patches пишет:
>
>
> On 16.08.2021 2:59, Timur Safin wrote:
>> Serialize datetime_t as newly introduced MP_EXT type.
>> It saves 1 required integer field and upto 2 optional
>> unsigned fields in very compact fashion.
>> - secs is required field;
>> - but nsec, offset are both optional;
>>
>> * json, yaml serialization formats, lua output mode
>> supported;
>> * exported symbols for datetime messagepack size calculations
>> so they are available for usage on Lua side.
>>
>> Part of #5941
>> Part of #5946
> ...
>
>> diff --git a/src/lib/core/mp_datetime.c b/src/lib/core/mp_datetime.c
>> new file mode 100644
>> index 000000000..d0a3e562c
>> --- /dev/null
>> +++ b/src/lib/core/mp_datetime.c
> ...
>
>> +
>> +int
>> +mp_snprint_datetime(char *buf, int size, const char **data, uint32_t
>> len)
>> +{
>> + struct datetime date = {0};
>
> Due to old gcc compiler used by CentOS7 I had to modify these 2
> functions - see incremental patch below...
>> +
>> + if (datetime_unpack(data, len, &date) == NULL)
>> + return -1;
>> +
>> + return datetime_to_string(&date, buf, size);
>> +}
>> +
>> +int
>> +mp_fprint_datetime(FILE *file, const char **data, uint32_t len)
>> +{
>> + struct datetime date;
>> +
>> + if (datetime_unpack(data, len, &date) == NULL)
>> + return -1;
>> +
>> + char buf[48];
>> + datetime_to_string(&date, buf, sizeof buf);
>> +
>> + return fprintf(file, "%s", buf);
>> +}
>> +
>
> ----------------------------------------------------------------
> 03:15 $ git diff
> diff --git a/src/lib/core/mp_datetime.c b/src/lib/core/mp_datetime.c
> index d0a3e562c..7e475d5f1 100644
> --- a/src/lib/core/mp_datetime.c
> +++ b/src/lib/core/mp_datetime.c
> @@ -165,7 +165,7 @@ mp_encode_datetime(char *data, const struct
> datetime *date)
> int
> mp_snprint_datetime(char *buf, int size, const char **data, uint32_t
> len)
> {
> - struct datetime date = {0};
> + struct datetime date = {0, 0, 0};
Please, use designated initializers here:
struct datetime date = {
.secs = ...,
.nsec = ...,
...
>
> if (datetime_unpack(data, len, &date) == NULL)
> return -1;
> @@ -176,7 +176,7 @@ mp_snprint_datetime(char *buf, int size, const
> char **data, uint32_t len)
> int
> mp_fprint_datetime(FILE *file, const char **data, uint32_t len)
> {
> - struct datetime date;
> + struct datetime date = {0, 0, 0};
>
> if (datetime_unpack(data, len, &date) == NULL)
> return -1;
> ----------------------------------------------------------------
>
> Sorry for the inconvenience!
>
> [Applied and force pushed]
>
> Timur
--
Serge Petrenko
More information about the Tarantool-patches
mailing list