RedfishPkg/JsonLib: add object clear interface

-Add JsonObjectClear() interface for application to clear
all elements in JSON object.
-Fix typo.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
This commit is contained in:
Nickle Wang 2023-07-03 20:38:17 +08:00 committed by mergify[bot]
parent b164b6d149
commit 60475162a6
2 changed files with 56 additions and 16 deletions

View File

@ -3,6 +3,7 @@
Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@ -97,7 +98,7 @@ typedef enum {
More details for reference count strategy can refer to the API description for JsonValueFree().
@retval The created JSON value which contains a JSON array or NULL if intial a JSON array
@retval The created JSON value which contains a JSON array or NULL if initial a JSON array
is failed.
**/
@ -116,7 +117,7 @@ JsonValueInitArray (
More details for reference count strategy can refer to the API description for JsonValueFree().
@retval The created JSON value which contains a JSON object or NULL if intial a JSON object
@retval The created JSON value which contains a JSON object or NULL if initial a JSON object
is failed.
**/
@ -571,6 +572,22 @@ JsonObjectSize (
IN EDKII_JSON_OBJECT JsonObject
);
/**
The function removes all elements from object. Returns 0 on success and -1 if object is not
a JSON object. The reference count of all removed values are decremented.
@param[in] JsonObject The provided JSON object.
@retval EFI_ABORTED Some error occur and operation aborted.
@retval EFI_SUCCESS JSON value has been appended to the end of the JSON array.
**/
EFI_STATUS
EFIAPI
JsonObjectClear (
IN EDKII_JSON_OBJECT JsonObject
);
/**
The function is used to enumerate all keys in a JSON object.
@ -705,7 +722,7 @@ JsonArrayAppendValue (
More details for reference count strategy can refer to the API description for JsonValueFree().
@param[in] JsonArray The provided JSON array.
@param[in] Index The Index position before removement.
@param[in] Index The Index position before removal.
@retval EFI_ABORTED Some error occur and operation aborted.
@retval EFI_SUCCESS The JSON array has been removed at position index.
@ -722,7 +739,7 @@ JsonArrayRemoveValue (
Dump JSON to a buffer.
@param[in] JsonValue The provided JSON value.
@param[in] Flags The Index position before removement. The value
@param[in] Flags The Index position before removal. The value
could be the combination of below flags.
- EDKII_JSON_INDENT(n)
- EDKII_JSON_COMPACT
@ -737,7 +754,7 @@ JsonArrayRemoveValue (
https://jansson.readthedocs.io/en/2.13/apiref.html#encoding
@retval CHAR8 * Dump fail if NULL returned, otherwise the buffer
contain JSON paylaod in ASCII string. The return
contain JSON payload in ASCII string. The return
value must be freed by the caller FreePool().
**/
CHAR8 *
@ -753,7 +770,7 @@ JsonDumpString (
value. Only object and array represented strings can be converted successfully,
since they are the only valid root values of a JSON text for UEFI usage.
Real number and number with exponent part are not supportted by UEFI.
Real number and number with exponent part are not supported by UEFI.
Caller needs to cleanup the root value by calling JsonValueFree().
@ -775,7 +792,7 @@ JsonLoadString (
/**
Load JSON from a buffer.
@param[in] Buffer Bufffer to the JSON payload
@param[in] Buffer Buffier to the JSON payload
@param[in] BufferLen Length of the buffer
@param[in] Flags Flag of loading JSON buffer, the value
could be the combination of below flags.
@ -807,7 +824,7 @@ JsonLoadBuffer (
When the reference count drops to zero, there are no references left and the
value can be destroyed.
This funciton decrement the reference count of EDKII_JSON_VALUE. As soon as
This function decrement the reference count of EDKII_JSON_VALUE. As soon as
a call to json_decref() drops the reference count to zero, the value is
destroyed and it can no longer be used.

View File

@ -28,7 +28,7 @@
More details for reference count strategy can refer to the API description for JsonValueFree().
@retval The created JSON value which contains a JSON array or NULL if intial a JSON array
@retval The created JSON value which contains a JSON array or NULL if initial a JSON array
is failed.
**/
@ -50,7 +50,7 @@ JsonValueInitArray (
More details for reference count strategy can refer to the API description for JsonValueFree().
@retval The created JSON value which contains a JSON object or NULL if intial a JSON object
@retval The created JSON value which contains a JSON object or NULL if initial a JSON object
is failed.
**/
@ -672,6 +672,29 @@ JsonObjectSize (
return json_object_size ((json_t *)JsonObject);
}
/**
The function removes all elements from object. Returns 0 on success and -1 if object is not
a JSON object. The reference count of all removed values are decremented.
@param[in] JsonObject The provided JSON object.
@retval EFI_ABORTED Some error occur and operation aborted.
@retval EFI_SUCCESS JSON value has been appended to the end of the JSON array.
**/
EFI_STATUS
EFIAPI
JsonObjectClear (
IN EDKII_JSON_OBJECT JsonObject
)
{
if (json_object_clear ((json_t *)JsonObject) != 0) {
return EFI_ABORTED;
}
return EFI_SUCCESS;
}
/**
The function is used to enumerate all keys in a JSON object.
@ -864,7 +887,7 @@ JsonArrayAppendValue (
More details for reference count strategy can refer to the API description for JsonValueFree().
@param[in] JsonArray The provided JSON array.
@param[in] Index The Index position before removement.
@param[in] Index The Index position before removal.
@retval EFI_ABORTED Some error occur and operation aborted.
@retval EFI_SUCCESS The JSON array has been removed at position index.
@ -888,7 +911,7 @@ JsonArrayRemoveValue (
Dump JSON to a buffer.
@param[in] JsonValue The provided JSON value.
@param[in] Flags The Index position before removement. The value
@param[in] Flags The Index position before removal. The value
could be the combination of below flags.
- EDKII_JSON_INDENT(n)
- EDKII_JSON_COMPACT
@ -903,7 +926,7 @@ JsonArrayRemoveValue (
https://jansson.readthedocs.io/en/2.13/apiref.html#encoding
@retval CHAR8 * Dump fail if NULL returned, otherwise the buffer
contain JSON paylaod in ASCII string. The return
contain JSON payload in ASCII string. The return
value must be freed by the caller using FreePool().
**/
CHAR8 *
@ -926,7 +949,7 @@ JsonDumpString (
value. Only object and array represented strings can be converted successfully,
since they are the only valid root values of a JSON text for UEFI usage.
Real number and number with exponent part are not supportted by UEFI.
Real number and number with exponent part are not supported by UEFI.
Caller needs to cleanup the root value by calling JsonValueFree().
@ -951,7 +974,7 @@ JsonLoadString (
/**
Load JSON from a buffer.
@param[in] Buffer Bufffer to the JSON payload
@param[in] Buffer Buffier to the JSON payload
@param[in] BufferLen Length of the buffer
@param[in] Flags Flag of loading JSON buffer, the value
could be the combination of below flags.
@ -986,7 +1009,7 @@ JsonLoadBuffer (
When the reference count drops to zero, there are no references left and the
value can be destroyed.
This funciton decrement the reference count of EDKII_JSON_VALUE. As soon as
This function decrement the reference count of EDKII_JSON_VALUE. As soon as
a call to json_decref() drops the reference count to zero, the value is
destroyed and it can no longer be used.