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

Abner Chang posted 1 patch 3 years, 2 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
RedfishPkg/Include/Library/JsonLib.h | 21 +++++++++++++++++++++
RedfishPkg/Library/JsonLib/JsonLib.c | 26 ++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
[edk2-devel] [PATCH] 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..82ca4bad60 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 UTF8 encoded 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 UTF8 encoded 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..00dedc1c60 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 UTF8 encoded 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 UTF8 encoded 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 (#70886): https://edk2.groups.io/g/devel/message/70886
Mute This Topic: https://groups.io/mt/80203698/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


回复: [edk2-devel] [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function
Posted by gaoliming 3 years, 2 months ago
Abner:
  What's the usage for this new API?

Thanks
Liming
> -----邮件原件-----
> 发件人: bounce+27952+70886+4905953+8761045@groups.io
> <bounce+27952+70886+4905953+8761045@groups.io> 代表 Abner Chang
> 发送时间: 2021年1月29日 12:20
> 收件人: devel@edk2.groups.io
> 抄送: Leif Lindholm <leif@nuviainc.com>; Nickle Wang
> <nickle.wang@hpe.com>; Michael D Kinney <michael.d.kinney@intel.com>
> 主题: [edk2-devel] [PATCH] 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..82ca4bad60 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 UTF8 encoded 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 UTF8 encoded 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..00dedc1c60 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 UTF8 encoded 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 UTF8 encoded 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 (#70994): https://edk2.groups.io/g/devel/message/70994
Mute This Topic: https://groups.io/mt/80274421/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function
Posted by Abner Chang 3 years, 2 months ago
It loads a JSON payload in the format of NULL terminated string to a JSON object. 
This function is used by either edk2 Redfish client applications or other edk2 modules which manipulate JSON properties.

Regards,
Abner

> -----Original Message-----
> From: gaoliming [mailto:gaoliming@byosoft.com.cn]
> Sent: Monday, February 1, 2021 9:55 AM
> To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist)
> <abner.chang@hpe.com>
> Cc: 'Leif Lindholm' <leif@nuviainc.com>; Wang, Nickle (HPS SW)
> <nickle.wang@hpe.com>; 'Michael D Kinney' <michael.d.kinney@intel.com>
> Subject: 回复: [edk2-devel] [PATCH] RedfishPkg/JsonLib: Add JsonLoadString
> function
> 
> Abner:
>   What's the usage for this new API?
> 
> Thanks
> Liming
> > -----邮件原件-----
> > 发件人: bounce+27952+70886+4905953+8761045@groups.io
> > <bounce+27952+70886+4905953+8761045@groups.io> 代表 Abner Chang
> > 发送时间: 2021年1月29日 12:20
> > 收件人: devel@edk2.groups.io
> > 抄送: Leif Lindholm <leif@nuviainc.com>; Nickle Wang
> > <nickle.wang@hpe.com>; Michael D Kinney
> <michael.d.kinney@intel.com>
> > 主题: [edk2-devel] [PATCH] 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..82ca4bad60 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 UTF8 encoded
> > +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 UTF8 encoded 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..00dedc1c60 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 UTF8 encoded
> > +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 UTF8 encoded 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 (#70999): https://edk2.groups.io/g/devel/message/70999
Mute This Topic: https://groups.io/mt/80276326/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-