From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 33D1C469710 for ; Fri, 15 May 2020 00:26:06 +0300 (MSK) From: Vladislav Shpilevoy References: Message-ID: <1c487bc6-4209-d4b4-6d69-1269037121ba@tarantool.org> Date: Thu, 14 May 2020 23:26:01 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: [Tarantool-patches] [PATCH msgpuck 1.5/2] Provide more details at MP_EXT mp_fprint/snprint() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org, korablev@tarantool.org It was printed as 'undefined'. Which is not really helpful. The very least what can be done - print type and size. --- msgpuck.c | 9 +++++++-- test/msgpuck.c | 9 ++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/msgpuck.c b/msgpuck.c index 7ea86e8..bdaa4ae 100644 --- a/msgpuck.c +++ b/msgpuck.c @@ -316,9 +316,14 @@ mp_format(char *data, size_t data_size, const char *format, ...) PRINTF("%lg", mp_decode_double(data)); \ break; \ case MP_EXT: \ - mp_next(data); \ - PRINTF("undefined"); \ + { \ + int8_t type; \ + uint32_t len; \ + mp_decode_ext(data, &type, &len); \ + PRINTF("(extension: type %d, len %u)", (int)type, \ + (unsigned)len); \ break; \ + } \ default: \ mp_unreachable(); \ return -1; \ diff --git a/test/msgpuck.c b/test/msgpuck.c index ecc2b26..eaf50e0 100644 --- a/test/msgpuck.c +++ b/test/msgpuck.c @@ -883,8 +883,10 @@ test_mp_print() d = mp_encode_double(d, 3.14); d = mp_encode_uint(d, 100); d = mp_encode_uint(d, 500); - /* let's pack zero-length ext */ - d = mp_encode_extl(d, 0, 0); + /* MP_EXT with type 123 and of size 3 bytes. */ + d = mp_encode_extl(d, 123, 3); + memcpy(d, "str", 3); + d += 3; char bin[] = "\x12test\x34\b\t\n\"bla\\-bla\"\f\r"; d = mp_encode_bin(d, bin, sizeof(bin)); d = mp_encode_map(d, 0); @@ -893,7 +895,8 @@ test_mp_print() const char *expected = "[-5, 42, \"kill bill\", [], " "{\"bool true\": true, \"bool false\": false, \"null\": null, " - "\"float\": 3.14, \"double\": 3.14, 100: 500}, undefined, " + "\"float\": 3.14, \"double\": 3.14, 100: 500}, " + "(extension: type 123, len 3), " "\"\\u0012test4\\b\\t\\n\\\"bla\\\\-bla\\\"\\f\\r\\u0000\", {}]"; int esize = strlen(expected); -- 2.21.1 (Apple Git-122.3)