Re: [edk2-devel] [PATCH 3/3] RedfishPkg/JsonLib: add object clear interface
[AMD Official Use Only - General] Reviewed-by: Abner Chang > -Original Message- > From: Nickle Wang > Sent: Monday, July 3, 2023 9:21 PM > To: devel@edk2.groups.io > Cc: Chang, Abner ; Igor Kulchytskyy > ; Nick Ramirez > Subject: [PATCH 3/3] RedfishPkg/JsonLib: add object clear interface > > Caution: This message originated from an External Source. Use proper caution > when opening attachments, clicking links, or responding. > > > -Add JsonObjectClear() interface for application to clear > all elements in JSON object. > -Fix typo. > > Signed-off-by: Nickle Wang > Cc: Abner Chang > Cc: Igor Kulchytskyy > Cc: Nick Ramirez > --- > 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. > (C) Copyright 2021 Hewlett Packard Enterprise Development LP > + 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 ( >INEDKII_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_ABORTEDSome error occur and operation aborted. > + @retval EFI_SUCCESSJSON value has been appended to the > end of > the JSON array. > + > +**/ > +EFI_STATUS > +EFIAPI > +JsonObjectClear ( > + INEDKII_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_ABORTEDSome error occur and operation aborted. >@retval EFI_SUCCESSThe 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] BufferBufffer to the JSON payload > + @param[in] BufferBuffier to the
[edk2-devel] [PATCH 3/3] 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 Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez --- 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. (C) Copyright 2021 Hewlett Packard Enterprise Development LP + 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 ( INEDKII_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_ABORTEDSome error occur and operation aborted. + @retval EFI_SUCCESSJSON value has been appended to the end of the JSON array. + +**/ +EFI_STATUS +EFIAPI +JsonObjectClear ( + INEDKII_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_ABORTEDSome error occur and operation aborted. @retval EFI_SUCCESSThe 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] BufferBufffer to the JSON payload + @param[in] BufferBuffier 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