New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decimal to string serialization #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch!
Please see some of my comments below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test and check out my 2 comments below.
Regarding the test encode some simple decimal here
https://github.com/tarantool/msgpuck/blob/master/test/msgpuck.c#L887
You may say char decimal[] = "\xd6\x01\x02\x03\x45\x6d"
, this is -34.56 encoded,
and then print it with mp_snprint
Otherwise LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fixes.
Please consider one last nit below. Otherwise LGTM
I will forward this to @Totktonada to take a look and merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks. @Totktonada, take a look, please.
(use https://github.com/parihaaraka/msgpuck.git or wait for tarantool/msgpuck#10 to be merged)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parihaaraka Thank you for your work on that, but I think it should not be done in this way (see more below). Maybe it would be better to file an issue to tarantool/tarantool or this repository and describe what exactly you want to achieve.
msgpuck.c
Outdated
@@ -232,6 +232,94 @@ mp_format(char *data, size_t data_size, const char *format, ...) | |||
return res; | |||
} | |||
|
|||
size_t | |||
print_decimal(char **buf, size_t buf_size, const char *val, uint32_t val_bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be part of msgpuck library, but our mp_decimal implementation.
We should however provide an ability to set custom handlers for MP_EXT subtypes for mp_[v]format
and mp_{f,sn}print
.
I propose to provide subroutines and (maybe) mp_format percent-placeholders for extension types via defines that should exist before including of msgpuck.h.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be part of mp_decimal, gmp or any other library. We convert messagepack to string here. Any decimal library internals are out of scope. This repository is a tarantool's one, so we may relay on ext subtypes being used by tarantool. But callbacks to encode/decode external data (e.g. mp_decimal) to/from decimal are expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the general purpose library, so it would be good to handle all operations with decimals from mp_decimal. Of course, if this will not block usage of this library by, say, tarantool connectors developers. That is why I keep asking you about your case.
Maybe we should provide mp_decimal.h with tarantool-dev/devel packages. Or ship extensions with msgpuck and allow to enable / disable them at build time.
test/msgpuck.c
Outdated
assert(d <= msgpack + sizeof(msgpack)); | ||
|
||
const char *expected = | ||
"[-5, 42, \"kill bill\", [], " | ||
"[" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unneeded change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need it to match the mess with the array size. Unneeded reproval.
msgpuck.c
Outdated
scale = mp_decode_int(&val); | ||
|
||
if (scale_head == val || !val_bytes) | ||
return 0; /* "undefined" (is ext mp type 1 misused?) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't got why the comment is indented with 9 whitespaces. We usually avoid comments on the same line with code.
The same for comments below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msgpuck.c
Outdated
if (ext_type != 1) { \ | ||
PRINTF("undefined"); \ | ||
} else { \ | ||
char static_buf[128]; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use PRINTF
inside print_decimal
and don't create static (automatic really) / dynamic buffers explicitly in this part of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You the boss (the second one)
test/msgpuck.c
Outdated
int esize = strlen(expected); | ||
|
||
char result[256]; | ||
char result[512]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: the branch contains commits from rtsisyk/master, they should be removed. Other commits should be squashed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?!
256 bytes is not enougth
I want to print all the mp types supported by tarantool. |
Usage example: parihaaraka/cpp2tnt@3ead452 |
…s to print decimal values
I added @alyapunov to make final decisions and proceed somehow (or decline). |
@Totktonada Same stands for each other ext type used in tarantool. And msgpack has mp_snprint_ext stub, which is replaced by tarantool's msgpack_snprint_ext. |
External application doesn't deal with internal tarantool's structures. It needs to print msgpack (and convert to mpdecimal or another corresponding stuff). BTW string to tnt ext types conversion would be great too. |
@alyapunov please proceed with review |
Hi, thanks for effort! |
No description provided.