[Tarantool-patches] [PATCH msgpuck 1.5/2] Provide more details at MP_EXT mp_fprint/snprint()

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri May 15 00:26:01 MSK 2020


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)


More information about the Tarantool-patches mailing list