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

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue May 19 23:48:43 MSK 2020


Hi! Thanks for the review!

On 19/05/2020 14:14, Alexander Turenko wrote:
>>  	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);						\
> 
> The header file still contains this comment:
> 
>  | /**
>  |  * \brief Default MP_EXT serializer into a file. Skips the object,
>  |  * ignores all the other arguments, and writes 'undefined'.
>  |                                         ^^^^^^^^^^^^^^^^^^
>  |  */
>  | int
>  | mp_fprint_ext_default(FILE *file, const char **data, int depth);
> 
> (Same for mp_snprint_ext_default).

Shame on me, I didn't notice it. Changed on the branch in this commit.
See below diff. Also I changed comments in the third commit. See in the
other email.

====================
diff --git a/msgpuck.h b/msgpuck.h
index 5dfbbd9..82e078b 100644
--- a/msgpuck.h
+++ b/msgpuck.h
@@ -970,7 +970,19 @@ mp_vformat(char *data, size_t data_size, const char *format, va_list args);
 
 /**
  * \brief print MsgPack data \a file using JSON-like format.
- * MP_EXT is printed as "undefined"
+ * MP_EXT is printed as a non-standard JSON 'list':
+ *
+ *     (extension: type <type>, len <len>)
+ *
+ * For example:
+ *
+ *     (extension: type 10, len 35)
+ *
+ * Type is the MP_EXT type. Length is of the MP_EXT body, not
+ * counting its header. Since the 'list' and what is in it is not
+ * a standard JSON, printing a MessagePack buffer, having MP_EXT
+ * in it, may lead to an invalid JSON.
+ *
  * \param file - pointer to file (or NULL for stdout)
  * \param data - pointer to buffer containing msgpack object
  * \retval >=0 - the number of bytes printed
@@ -982,6 +994,8 @@ mp_fprint(FILE *file, const char *data);
 
 /**
  * \brief format MsgPack data to \a buf using JSON-like format.
+ * Behaves the same as \sa mp_fprint(), but with snprintf()
+ * semantics.
  * \sa mp_fprint()
  * \param buf - buffer to use
  * \param size - buffer size. This function write at most size bytes


More information about the Tarantool-patches mailing list