Skip to content

Commit 4bf4721

Browse files
lePicimichalvasko
authored andcommitted
parser json REFACTOR code snippet to function
The changes apply to the lydjson_parse_opaq function.
1 parent 0791e80 commit 4bf4721

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

src/parser_json.c

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -864,13 +864,8 @@ lydjson_maintain_children(struct lyd_node_inner *parent, struct lyd_node **first
864864
}
865865
}
866866

867-
static LY_ERR lydjson_subtree_r(struct lyd_json_ctx *lydctx, struct lyd_node *parent, struct lyd_node **first_p,
868-
struct ly_set *parsed);
869-
870867
/**
871-
* @brief Parse opaq node from the input.
872-
*
873-
* In case of processing array, the whole array is being processed and the resulting @p node_p is the last item of the array.
868+
* @brief Wrapper for ::lyd_create_opaq().
874869
*
875870
* @param[in] lydctx JSON data parser context.
876871
* @param[in] name Name of the opaq node to create.
@@ -879,18 +874,14 @@ static LY_ERR lydjson_subtree_r(struct lyd_json_ctx *lydctx, struct lyd_node *pa
879874
* @param[in] prefix_len Length of the @p prefx string.
880875
* @param[in] parent Data parent of the opaq node to create, can be NULL in case of top level,
881876
* but must be set if @p first is not.
882-
* @param[in,out] status_p Pointer to the current status of the parser context,
883-
* since the function manipulates with the context and process the input, the status can be updated.
884877
* @param[in,out] status_inner_p In case of processing JSON array, this parameter points to a standalone
885878
* context status of the array content. Otherwise, it is supposed to be the same as @p status_p.
886-
* @param[in,out] first_p First top-level/parent sibling, must be set if @p parent is not.
887879
* @param[out] node_p Pointer to the created opaq node.
888880
* @return LY_ERR value.
889881
*/
890882
static LY_ERR
891-
lydjson_parse_opaq(struct lyd_json_ctx *lydctx, const char *name, size_t name_len, const char *prefix, size_t prefix_len,
892-
struct lyd_node_inner *parent, enum LYJSON_PARSER_STATUS *status_p,
893-
enum LYJSON_PARSER_STATUS *status_inner_p, struct lyd_node **first_p, struct lyd_node **node_p)
883+
lydjson_create_opaq(struct lyd_json_ctx *lydctx, const char *name, size_t name_len, const char *prefix, size_t prefix_len,
884+
struct lyd_node_inner *parent, enum LYJSON_PARSER_STATUS *status_inner_p, struct lyd_node **node_p)
894885
{
895886
LY_ERR ret = LY_SUCCESS;
896887
const char *value = NULL, *module_name;
@@ -915,6 +906,41 @@ lydjson_parse_opaq(struct lyd_json_ctx *lydctx, const char *name, size_t name_le
915906
if (dynamic) {
916907
free((char *)value);
917908
}
909+
910+
return ret;
911+
}
912+
913+
static LY_ERR lydjson_subtree_r(struct lyd_json_ctx *lydctx, struct lyd_node *parent, struct lyd_node **first_p,
914+
struct ly_set *parsed);
915+
916+
/**
917+
* @brief Parse opaq node from the input.
918+
*
919+
* In case of processing array, the whole array is being processed and the resulting @p node_p is the last item of the array.
920+
*
921+
* @param[in] lydctx JSON data parser context.
922+
* @param[in] name Name of the opaq node to create.
923+
* @param[in] name_len Length of the @p name string.
924+
* @param[in] prefix Prefix of the opaq node to create.
925+
* @param[in] prefix_len Length of the @p prefx string.
926+
* @param[in] parent Data parent of the opaq node to create, can be NULL in case of top level,
927+
* but must be set if @p first is not.
928+
* @param[in,out] status_p Pointer to the current status of the parser context,
929+
* since the function manipulates with the context and process the input, the status can be updated.
930+
* @param[in,out] status_inner_p In case of processing JSON array, this parameter points to a standalone
931+
* context status of the array content. Otherwise, it is supposed to be the same as @p status_p.
932+
* @param[in,out] first_p First top-level/parent sibling, must be set if @p parent is not.
933+
* @param[out] node_p Pointer to the created opaq node.
934+
* @return LY_ERR value.
935+
*/
936+
static LY_ERR
937+
lydjson_parse_opaq(struct lyd_json_ctx *lydctx, const char *name, size_t name_len, const char *prefix, size_t prefix_len,
938+
struct lyd_node_inner *parent, enum LYJSON_PARSER_STATUS *status_p,
939+
enum LYJSON_PARSER_STATUS *status_inner_p, struct lyd_node **first_p, struct lyd_node **node_p)
940+
{
941+
LY_ERR ret = LY_SUCCESS;
942+
943+
ret = lydjson_create_opaq(lydctx, name, name_len, prefix, prefix_len, parent, status_inner_p, node_p);
918944
LY_CHECK_RET(ret);
919945

920946
if ((*status_p == LYJSON_OBJECT) || (*status_p == LYJSON_OBJECT_EMPTY)) {

0 commit comments

Comments
 (0)