[edk2-devel] [PATCH 3/3] RedfishPkg/JsonLib: add object clear interface
Nickle Wang via groups.io
nicklew=nvidia.com at groups.io
Mon Jul 3 13:20:30 UTC 2023
-Add JsonObjectClear() interface for application to clear
all elements in JSON object.
-Fix typo.
Signed-off-by: Nickle Wang <nicklew at nvidia.com>
Cc: Abner Chang <abner.chang at amd.com>
Cc: Igor Kulchytskyy <igork at ami.com>
Cc: Nick Ramirez <nramirez at nvidia.com>
---
RedfishPkg/Include/Library/JsonLib.h | 33 +++++++++++++++++------
RedfishPkg/Library/JsonLib/JsonLib.c | 39 ++++++++++++++++++++++------
2 files changed, 56 insertions(+), 16 deletions(-)
diff --git a/RedfishPkg/Include/Library/JsonLib.h b/RedfishPkg/Include/Library/JsonLib.h
index f98f4e779ede..8f31d9341481 100644
--- a/RedfishPkg/Include/Library/JsonLib.h
+++ b/RedfishPkg/Include/Library/JsonLib.h
@@ -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.
diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/JsonLib.c
index 69f2455c00ed..9b758b940293 100644
--- a/RedfishPkg/Library/JsonLib/JsonLib.c
+++ b/RedfishPkg/Library/JsonLib/JsonLib.c
@@ -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.
--
2.17.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106605): https://edk2.groups.io/g/devel/message/106605
Mute This Topic: https://groups.io/mt/99926326/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list