From: "Abner Chang" <abner.chang@hpe.com>
To: devel@edk2.groups.io
Cc: Leif Lindholm <leif@nuviainc.com>,
Nickle Wang <nickle.wang@hpe.com>,
Michael D Kinney <michael.d.kinney@intel.com>
Subject: [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function
Date: Fri, 29 Jan 2021 12:20:04 +0800 [thread overview]
Message-ID: <20210129042004.20663-1-abner.chang@hpe.com> (raw)
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
next reply other threads:[~2021-01-29 5:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 4:20 Abner Chang [this message]
2021-02-01 1:55 ` 回复: [edk2-devel] [PATCH] RedfishPkg/JsonLib: Add JsonLoadString function gaoliming
2021-02-01 3:02 ` Abner Chang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210129042004.20663-1-abner.chang@hpe.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox