public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function
@ 2021-01-29  4:20 Abner Chang
  2021-02-01  1:55 ` 回复: [edk2-devel] " gaoliming
  0 siblings, 1 reply; 3+ messages in thread
From: Abner Chang @ 2021-01-29  4:20 UTC (permalink / raw)
  To: devel; +Cc: Leif Lindholm, Nickle Wang, Michael D Kinney

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* 回复: [edk2-devel] [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function
  2021-01-29  4:20 [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function Abner Chang
@ 2021-02-01  1:55 ` gaoliming
  2021-02-01  3:02   ` Abner Chang
  0 siblings, 1 reply; 3+ messages in thread
From: gaoliming @ 2021-02-01  1:55 UTC (permalink / raw)
  To: devel, abner.chang
  Cc: 'Leif Lindholm', 'Nickle Wang',
	'Michael D Kinney'

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
> 
> 
> 
> 
> 




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function
  2021-02-01  1:55 ` 回复: [edk2-devel] " gaoliming
@ 2021-02-01  3:02   ` Abner Chang
  0 siblings, 0 replies; 3+ messages in thread
From: Abner Chang @ 2021-02-01  3:02 UTC (permalink / raw)
  To: gaoliming, devel@edk2.groups.io
  Cc: 'Leif Lindholm', Wang, Nickle (HPS SW),
	'Michael D Kinney'

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
> >
> >
> >
> > 
> >
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-01  3:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-29  4:20 [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function Abner Chang
2021-02-01  1:55 ` 回复: [edk2-devel] " gaoliming
2021-02-01  3:02   ` Abner Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox