[edk2-devel] [PATCH v2] RedfishPkg/JsonLib: Add JsonLoadString function

Abner Chang posted 1 patch 3 years, 2 months ago
Failed in applying to current master (apply log)
RedfishPkg/Include/Library/JsonLib.h | 21 +++++++++++++++++++++
RedfishPkg/Library/JsonLib/JsonLib.c | 26 ++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
[edk2-devel] [PATCH v2] RedfishPkg/JsonLib: Add JsonLoadString function
Posted by Abner Chang 3 years, 2 months ago
Add JsonLoadString function to load a NULL terminated-string JSON

Signed-off-by: Abner Chang <abner.chang@hpe.com>

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
---
 RedfishPkg/Include/Library/JsonLib.h | 21 +++++++++++++++++++++
 RedfishPkg/Library/JsonLib/JsonLib.c | 26 ++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/RedfishPkg/Include/Library/JsonLib.h b/RedfishPkg/Include/Library/JsonLib.h
index 3c10f67d27..8a30c5250b 100644
--- a/RedfishPkg/Include/Library/JsonLib.h
+++ b/RedfishPkg/Include/Library/JsonLib.h
@@ -664,6 +664,27 @@ JsonDumpString (
   IN    UINTN               Flags
   );
 
+/**
+  Convert a string to JSON object.
+  The function is used to convert a NULL terminated CHAR8 string to a JSON
+  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.
+
+  Caller needs to cleanup the root value by calling JsonValueFree().
+
+  @param[in]   String        The NULL terminated CHAR8 string to convert.
+
+  @retval      Array JSON value or object JSON value, or NULL when any error occurs.
+
+**/
+EDKII_JSON_VALUE
+EFIAPI
+JsonLoadString (
+  IN   CONST CHAR8*    String
+  );
+
 /**
   Load JSON from a buffer.
 
diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/JsonLib.c
index 34ff381aee..3693299afb 100644
--- a/RedfishPkg/Library/JsonLib/JsonLib.c
+++ b/RedfishPkg/Library/JsonLib/JsonLib.c
@@ -819,6 +819,32 @@ JsonDumpString (
     return json_dumps((json_t *)JsonValue, Flags);
 }
 
+/**
+  Convert a string to JSON object.
+  The function is used to convert a NULL terminated CHAR8 string to a JSON
+  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.
+
+  Caller needs to cleanup the root value by calling JsonValueFree().
+
+  @param[in]   String        The NULL terminated CHAR8 string to convert.
+
+  @retval      Array JSON value or object JSON value, or NULL when any error occurs.
+
+**/
+EDKII_JSON_VALUE
+EFIAPI
+JsonLoadString (
+  IN    CONST CHAR8*    String
+  )
+{
+  json_error_t    JsonError;
+
+  return (EDKII_JSON_VALUE) json_loads ((const char *)String, 0, &JsonError);
+}
+
 /**
   Load JSON from a buffer.
 
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#71776): https://edk2.groups.io/g/devel/message/71776
Mute This Topic: https://groups.io/mt/80722392/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH v2] RedfishPkg/JsonLib: Add JsonLoadString function
Posted by Nickle Wang 3 years, 2 months ago
Thanks for addressing my comment. The function header looks good to me now.

Reviewed-by: Nickle Wang <nickle.wang@hpe.com>

Thanks,
Nickle

> -----Original Message-----
> From: Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>
> Sent: Thursday, February 18, 2021 11:12 AM
> To: devel@edk2.groups.io
> Cc: Leif Lindholm <leif@nuviainc.com>; Wang, Nickle (HPS SW)
> <nickle.wang@hpe.com>; Michael D Kinney <michael.d.kinney@intel.com>
> Subject: [PATCH v2] RedfishPkg/JsonLib: Add JsonLoadString function
> 
> Add JsonLoadString function to load a NULL terminated-string JSON
> 
> Signed-off-by: Abner Chang <abner.chang@hpe.com>
> 
> Cc: Leif Lindholm <leif@nuviainc.com>
> Cc: Nickle Wang <nickle.wang@hpe.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> ---
>  RedfishPkg/Include/Library/JsonLib.h | 21 +++++++++++++++++++++
> RedfishPkg/Library/JsonLib/JsonLib.c | 26 ++++++++++++++++++++++++++
>  2 files changed, 47 insertions(+)
> 
> diff --git a/RedfishPkg/Include/Library/JsonLib.h
> b/RedfishPkg/Include/Library/JsonLib.h
> index 3c10f67d27..8a30c5250b 100644
> --- a/RedfishPkg/Include/Library/JsonLib.h
> +++ b/RedfishPkg/Include/Library/JsonLib.h
> @@ -664,6 +664,27 @@ JsonDumpString (
>    IN    UINTN               Flags
>    );
> 
> +/**
> +  Convert a string to JSON object.
> +  The function is used to convert a NULL terminated CHAR8 string to a
> +JSON
> +  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.
> +
> +  Caller needs to cleanup the root value by calling JsonValueFree().
> +
> +  @param[in]   String        The NULL terminated CHAR8 string to convert.
> +
> +  @retval      Array JSON value or object JSON value, or NULL when any error
> occurs.
> +
> +**/
> +EDKII_JSON_VALUE
> +EFIAPI
> +JsonLoadString (
> +  IN   CONST CHAR8*    String
> +  );
> +
>  /**
>    Load JSON from a buffer.
> 
> diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c
> b/RedfishPkg/Library/JsonLib/JsonLib.c
> index 34ff381aee..3693299afb 100644
> --- a/RedfishPkg/Library/JsonLib/JsonLib.c
> +++ b/RedfishPkg/Library/JsonLib/JsonLib.c
> @@ -819,6 +819,32 @@ JsonDumpString (
>      return json_dumps((json_t *)JsonValue, Flags);  }
> 
> +/**
> +  Convert a string to JSON object.
> +  The function is used to convert a NULL terminated CHAR8 string to a
> +JSON
> +  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.
> +
> +  Caller needs to cleanup the root value by calling JsonValueFree().
> +
> +  @param[in]   String        The NULL terminated CHAR8 string to convert.
> +
> +  @retval      Array JSON value or object JSON value, or NULL when any error
> occurs.
> +
> +**/
> +EDKII_JSON_VALUE
> +EFIAPI
> +JsonLoadString (
> +  IN    CONST CHAR8*    String
> +  )
> +{
> +  json_error_t    JsonError;
> +
> +  return (EDKII_JSON_VALUE) json_loads ((const char *)String, 0,
> +&JsonError); }
> +
>  /**
>    Load JSON from a buffer.
> 
> --
> 2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72039): https://edk2.groups.io/g/devel/message/72039
Mute This Topic: https://groups.io/mt/80722392/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-