tuple: add JSON path field accessor to module API
Added a function (see the API in the documentation request below), which reflects the `tuple[json_path]` Lua API (see #1285). Part of #7228 @TarantoolBot document Title: tuple: access a field using JSON path via module API The following function is added into the module API: ```c /** * Return a raw tuple field in the MsgPack format pointed by * a JSON path. * * The JSON path includes the outmost field. For example, "c" in * ["a", ["b", "c"], "d"] can be accessed using "[2][2]" path (if * index_base is 1, as in Lua). If index_base is set to 0, the * same field will be pointed by the "[1][1]" path. * * The first JSON path token may be a field name if the tuple * has associated format with named fields. A field of a nested * map can be accessed in the same way: "foo.bar" or ".foo.bar". * * The return value is valid until the tuple is destroyed, see * box_tuple_ref(). * * Return NULL if the field does not exist or if the JSON path is * malformed or invalid. Multikey JSON path token [*] is treated * as invalid in this context. * * \param tuple a tuple * \param path a JSON path * \param path_len a length of @a path * \param index_base 0 if array element indexes in @a path are * zero-based (like in C) or 1 if they're one-based (like * in Lua) * \retval a pointer to a field data if the field exists or NULL */ API_EXPORT const char * box_tuple_field_by_path(box_tuple_t *tuple, const char *path, uint32_t path_len, int index_base); ```
Showing
- changelogs/unreleased/get-tuple-field-by-json-path-from-c.md 4 additions, 0 deletionschangelogs/unreleased/get-tuple-field-by-json-path-from-c.md
- extra/exports 1 addition, 0 deletionsextra/exports
- src/box/tuple.c 18 additions, 0 deletionssrc/box/tuple.c
- src/box/tuple.h 31 additions, 0 deletionssrc/box/tuple.h
- test/app-tap/module_api.c 35 additions, 0 deletionstest/app-tap/module_api.c
- test/app-tap/module_api.test.lua 191 additions, 1 deletiontest/app-tap/module_api.test.lua
Loading
Please register or sign in to comment