From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 6387723777 for ; Sat, 31 Aug 2019 17:32:41 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oDxYBLerx3bd for ; Sat, 31 Aug 2019 17:32:41 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id ADF50237D3 for ; Sat, 31 Aug 2019 17:32:40 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH v2 1/8] tuple: expose JSON go_to_key and go_to_index functions Date: Sat, 31 Aug 2019 23:35:51 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org They are needed in JSON path update for a case, when a final part of the path may not exist, and go_to_path returns an error. That case is '=' and '!' on not existing fields. For example, in {'=', '[1][2][3]', 20} field [3] can be not existing. For these cases JSON update will have its own implementation of go_to_path allowing optional last field. Needed for #1261 --- src/box/tuple.c | 21 ++------------------- src/box/tuple.h | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/box/tuple.c b/src/box/tuple.c index bf4ea711d..261505f9a 100644 --- a/src/box/tuple.c +++ b/src/box/tuple.c @@ -385,15 +385,7 @@ tuple_free(void) /* {{{ tuple_field_* getters */ -/** - * Propagate @a field to MessagePack(field)[index]. - * @param[in][out] field Field to propagate. - * @param index 0-based index to propagate to. - * - * @retval 0 Success, the index was found. - * @retval -1 Not found. - */ -static inline int +int tuple_field_go_to_index(const char **field, uint64_t index) { enum mp_type type = mp_typeof(**field); @@ -428,16 +420,7 @@ tuple_field_go_to_index(const char **field, uint64_t index) return -1; } -/** - * Propagate @a field to MessagePack(field)[key]. - * @param[in][out] field Field to propagate. - * @param key Key to propagate to. - * @param len Length of @a key. - * - * @retval 0 Success, the index was found. - * @retval -1 Not found. - */ -static inline int +int tuple_field_go_to_key(const char **field, const char *key, int len) { enum mp_type type = mp_typeof(**field); diff --git a/src/box/tuple.h b/src/box/tuple.h index 4c4050ca8..ab0c7a99b 100644 --- a/src/box/tuple.h +++ b/src/box/tuple.h @@ -551,6 +551,29 @@ int tuple_go_to_path(const char **data, const char *path, uint32_t path_len, int multikey_idx); +/** + * Propagate @a field to MessagePack(field)[index]. + * @param[in][out] field Field to propagate. + * @param index 0-based index to propagate to. + * + * @retval 0 Success, the index was found. + * @retval -1 Not found. + */ +int +tuple_field_go_to_index(const char **field, uint64_t index); + +/** + * Propagate @a field to MessagePack(field)[key]. + * @param[in][out] field Field to propagate. + * @param key Key to propagate to. + * @param len Length of @a key. + * + * @retval 0 Success, the index was found. + * @retval -1 Not found. + */ +int +tuple_field_go_to_key(const char **field, const char *key, int len); + /** * Get tuple field by field index, relative JSON path and * multikey_idx. -- 2.20.1 (Apple Git-117)