VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Include/Library/JsonLib.h@ 101291

Last change on this file since 101291 was 101291, checked in by vboxsync, 17 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • Property svn:eol-style set to native
File size: 26.8 KB
Line 
1/** @file
2 APIs for JSON operations.
3
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
6 Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
7
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10**/
11
12#ifndef JSON_LIB_H_
13#define JSON_LIB_H_
14
15typedef VOID *EDKII_JSON_VALUE;
16typedef VOID *EDKII_JSON_ARRAY;
17typedef VOID *EDKII_JSON_OBJECT;
18
19///
20/// Map to json_int_t in jansson.h
21///
22typedef INT64 EDKII_JSON_INT_T; // #JSON_INTEGER_IS_LONG_LONG is set to 1
23 // in jansson_Config.h
24
25///
26/// Map to the definitions in jansson.h
27/// See below URI for the JSON encoding flags reference.
28/// https://jansson.readthedocs.io/en/2.13/apiref.html#encoding
29///
30#define EDKII_JSON_MAX_INDENT 0x1F
31#define EDKII_JSON_INDENT(n) ((n) & EDKII_JSON_MAX_INDENT)
32
33#define EDKII_JSON_COMPACT 0x20
34#define EDKII_JSON_ENSURE_ASCII 0x40
35#define EDKII_JSON_SORT_KEYS 0x80
36#define EDKII_JSON_PRESERVE_ORDER 0x100
37#define EDKII_JSON_ENCODE_ANY 0x200
38#define EDKII_JSON_ESCAPE_SLASH 0x400
39#define EDKII_JSON_REAL_PRECISION(n) (((n) & 0x1F) << 11)
40#define EDKII_JSON_EMBED 0x10000
41
42///
43/// Map to the definitions in jansson.h
44/// See below URI for the JSON decoding flags reference.
45/// https://jansson.readthedocs.io/en/2.13/apiref.html?highlight=json_loadb#decoding
46///
47#define EDKII_JSON_REJECT_DUPLICATES 0x1
48#define EDKII_JSON_DISABLE_EOF_CHECK 0x2
49#define EDKII_JSON_DECODE_ANY 0x4
50#define EDKII_JSON_DECODE_INT_AS_REAL 0x8
51#define EDKII_JSON_ALLOW_NUL 0x10
52
53#define EDKII_JSON_ARRAY_FOREACH(Array, Index, Value) \
54 for(Index = 0; \
55 Index < JsonArrayCount(Array) && (Value = JsonArrayGetValue(Array, Index)); \
56 Index++)
57
58#define EDKII_JSON_OBJECT_FOREACH_SAFE(Object, N, Key, Value) \
59 for (Key = JsonObjectIteratorKey(JsonObjectIterator(Object)), \
60 N = JsonObjectIteratorNext(Object, JsonObjectKeyToIterator(Key)); \
61 Key && (Value = JsonObjectIteratorValue(JsonObjectKeyToIterator(Key))); \
62 Key = JsonObjectIteratorKey(N), \
63 N = JsonObjectIteratorNext(Object, JsonObjectKeyToIterator(Key)))
64
65///
66/// Map to the json_error_t in jansson.h
67///
68#define EDKII_JSON_ERROR_TEXT_LENGTH 160
69#define EDKII_JSON_ERROR_SOURCE_LENGTH 80
70typedef struct {
71 INTN Line;
72 INTN Column;
73 INTN Position;
74 CHAR8 Source[EDKII_JSON_ERROR_SOURCE_LENGTH];
75 CHAR8 Text[EDKII_JSON_ERROR_TEXT_LENGTH];
76} EDKII_JSON_ERROR;
77
78///
79/// Map to the json_type in jansson.h
80///
81typedef enum {
82 EdkiiJsonTypeObject,
83 EdkiiJsonTypeArray,
84 EdkiiJsonTypeString,
85 EdkiiJsonTypeInteger,
86 EdkiiJsonTypeReal,
87 EdkiiJsonTypeTrue,
88 EdkiiJsonTypeFalse,
89 EdkiiJsonTypeNull
90} EDKII_JSON_TYPE;
91
92/**
93 The function is used to initialize a JSON value which contains a new JSON array,
94 or NULL on error. Initially, the array is empty.
95
96 The reference count of this value will be set to 1, and caller needs to cleanup the
97 value by calling JsonValueFree().
98
99 More details for reference count strategy can refer to the API description for JsonValueFree().
100
101 @retval The created JSON value which contains a JSON array or NULL if initial a JSON array
102 is failed.
103
104**/
105EDKII_JSON_VALUE
106EFIAPI
107JsonValueInitArray (
108 VOID
109 );
110
111/**
112 The function is used to initialize a JSON value which contains a new JSON object,
113 or NULL on error. Initially, the object is empty.
114
115 The reference count of this value will be set to 1, and caller needs to cleanup the
116 value by calling JsonValueFree().
117
118 More details for reference count strategy can refer to the API description for JsonValueFree().
119
120 @retval The created JSON value which contains a JSON object or NULL if initial a JSON object
121 is failed.
122
123**/
124EDKII_JSON_VALUE
125EFIAPI
126JsonValueInitObject (
127 VOID
128 );
129
130/**
131 The function is used to initialize a JSON value which contains a new JSON string,
132 or NULL on error.
133
134 The input string must be NULL terminated Ascii format, non-Ascii characters will
135 be processed as an error. Unicode characters can also be represented by Ascii string
136 as the format: \u + 4 hexadecimal digits, like \u3E5A, or \u003F.
137
138 The reference count of this value will be set to 1, and caller needs to cleanup the
139 value by calling JsonValueFree().
140
141 More details for reference count strategy can refer to the API description for JsonValueFree().
142
143 @param[in] String The Ascii string to initialize to JSON value
144
145 @retval The created JSON value which contains a JSON string or NULL. Select a
146 Getter API for a specific encoding format.
147
148**/
149EDKII_JSON_VALUE
150EFIAPI
151JsonValueInitAsciiString (
152 IN CONST CHAR8 *String
153 );
154
155/**
156 The function is used to initialize a JSON value which contains a new JSON string,
157 or NULL on error.
158
159 The input must be a NULL terminated UCS2 format Unicode string.
160
161 The reference count of this value will be set to 1, and caller needs to cleanup the
162 value by calling JsonValueFree().
163
164 More details for reference count strategy can refer to the API description for JsonValueFree().
165
166 @param[in] String The Unicode string to initialize to JSON value
167
168 @retval The created JSON value which contains a JSON string or NULL. Select a
169 Getter API for a specific encoding format.
170
171**/
172EDKII_JSON_VALUE
173EFIAPI
174JsonValueInitUnicodeString (
175 IN CHAR16 *String
176 );
177
178/**
179 The function is used to initialize a JSON value which contains a new JSON integer,
180 or NULL on error.
181
182 The reference count of this value will be set to 1, and caller needs to cleanup the
183 value by calling JsonValueFree().
184
185 More details for reference count strategy can refer to the API description for JsonValueFree().
186
187 @param[in] Value The integer to initialize to JSON value
188
189 @retval The created JSON value which contains a JSON integer or NULL.
190
191**/
192EDKII_JSON_VALUE
193EFIAPI
194JsonValueInitInteger (
195 IN INT64 Value
196 );
197
198/**
199 The function is used to initialize a JSON value which contains a new JSON boolean,
200 or NULL on error.
201
202 Boolean JSON value is kept as static value, and no need to do any cleanup work.
203
204 @param[in] Value The boolean value to initialize.
205
206 @retval The created JSON value which contains a JSON boolean or NULL.
207
208**/
209EDKII_JSON_VALUE
210EFIAPI
211JsonValueInitBoolean (
212 IN BOOLEAN Value
213 );
214
215/**
216 The function is used to initialize a JSON value which contains a new JSON NULL,
217 or NULL on error.
218
219 NULL JSON value is kept as static value, and no need to do any cleanup work.
220
221 @retval The created NULL JSON value.
222
223**/
224EDKII_JSON_VALUE
225EFIAPI
226JsonValueInitNull (
227 VOID
228 );
229
230/**
231 The function is used to initialize a JSON value which contains a TRUE JSON value,
232 or NULL on error.
233
234 NULL JSON value is kept as static value, and no need to do any cleanup work.
235
236 @retval The created JSON TRUE value.
237
238**/
239EDKII_JSON_VALUE
240EFIAPI
241JsonValueInitTrue (
242 VOID
243 );
244
245/**
246 The function is used to initialize a JSON value which contains a FALSE JSON value,
247 or NULL on error.
248
249 NULL JSON value is kept as static value, and no need to do any cleanup work.
250
251 @retval The created JSON FALSE value.
252
253**/
254EDKII_JSON_VALUE
255EFIAPI
256JsonValueInitFalse (
257 VOID
258 );
259
260/**
261 The function is used to decrease the reference count of a JSON value by one, and once
262 this reference count drops to zero, the value is destroyed and it can no longer be used.
263 If this destroyed value is object type or array type, reference counts for all containing
264 JSON values will be decreased by 1. Boolean JSON value and NULL JSON value won't be destroyed
265 since they are static values kept in memory.
266
267 Reference Count Strategy: BaseJsonLib uses this strategy to track whether a value is still
268 in use or not. When a value is created, it's reference count is set to 1. If a reference to a
269 value is kept for use, its reference count is incremented, and when the value is no longer
270 needed, the reference count is decremented. When the reference count drops to zero, there are
271 no references left, and the value can be destroyed.
272
273 The given JSON value maybe NULL and not causing any problem. Just output the debug message
274 to inform caller the NULL value is passed in.
275
276 @param[in] Json The JSON value to be freed. json_decref may return without any
277 changes if Json is NULL.
278
279**/
280VOID
281EFIAPI
282JsonValueFree (
283 IN EDKII_JSON_VALUE Json
284 );
285
286/**
287 The function is used to create a fresh copy of a JSON value, and all child values are deep
288 copied in a recursive fashion. It should be called when this JSON value might be modified
289 in later use, but the original still wants to be used in somewhere else.
290
291 Reference counts of the returned root JSON value and all child values will be set to 1, and
292 caller needs to cleanup the root value by calling JsonValueFree().
293
294 * Note: Since this function performs a copy from bottom to up, too many calls may cause some
295 performance issues, user should avoid unnecessary calls to this function unless it is really
296 needed.
297
298 @param[in] Json The JSON value to be cloned.
299
300 @retval Return the cloned JSON value, or NULL on error.
301
302**/
303EDKII_JSON_VALUE
304EFIAPI
305JsonValueClone (
306 IN EDKII_JSON_VALUE Json
307 );
308
309/**
310 The function is used to return if the provided JSON value contains a JSON array.
311
312 @param[in] Json The provided JSON value.
313
314 @retval TRUE The JSON value contains a JSON array.
315 @retval FALSE The JSON value doesn't contain a JSON array.
316
317**/
318BOOLEAN
319EFIAPI
320JsonValueIsArray (
321 IN EDKII_JSON_VALUE Json
322 );
323
324/**
325 The function is used to return if the provided JSON value contains a JSON object.
326
327 @param[in] Json The provided JSON value.
328
329 @retval TRUE The JSON value contains a JSON object.
330 @retval FALSE The JSON value doesn't contain a JSON object.
331
332**/
333BOOLEAN
334EFIAPI
335JsonValueIsObject (
336 IN EDKII_JSON_VALUE Json
337 );
338
339/**
340 The function is used to return if the provided JSON Value contains a string, Ascii or
341 Unicode format is not differentiated.
342
343 @param[in] Json The provided JSON value.
344
345 @retval TRUE The JSON value contains a JSON string.
346 @retval FALSE The JSON value doesn't contain a JSON string.
347
348**/
349BOOLEAN
350EFIAPI
351JsonValueIsString (
352 IN EDKII_JSON_VALUE Json
353 );
354
355/**
356 The function is used to return if the provided JSON value contains a JSON integer.
357
358 @param[in] Json The provided JSON value.
359
360 @retval TRUE The JSON value is contains JSON integer.
361 @retval FALSE The JSON value doesn't contain a JSON integer.
362
363**/
364BOOLEAN
365EFIAPI
366JsonValueIsInteger (
367 IN EDKII_JSON_VALUE Json
368 );
369
370/**
371 The function is used to return if the provided JSON value contains a JSON number.
372
373 @param[in] Json The provided JSON value.
374
375 @retval TRUE The JSON value is contains JSON number.
376 @retval FALSE The JSON value doesn't contain a JSON number.
377
378**/
379BOOLEAN
380EFIAPI
381JsonValueIsNumber (
382 IN EDKII_JSON_VALUE Json
383 );
384
385/**
386 The function is used to return if the provided JSON value contains a JSON boolean.
387
388 @param[in] Json The provided JSON value.
389
390 @retval TRUE The JSON value contains a JSON boolean.
391 @retval FALSE The JSON value doesn't contain a JSON boolean.
392
393**/
394BOOLEAN
395EFIAPI
396JsonValueIsBoolean (
397 IN EDKII_JSON_VALUE Json
398 );
399
400/**
401 The function is used to return if the provided JSON value contains a TRUE value.
402
403 @param[in] Json The provided JSON value.
404
405 @retval TRUE The JSON value contains a TRUE value.
406 @retval FALSE The JSON value doesn't contain a TRUE value.
407
408**/
409BOOLEAN
410EFIAPI
411JsonValueIsTrue (
412 IN EDKII_JSON_VALUE Json
413 );
414
415/**
416 The function is used to return if the provided JSON value contains a FALSE value.
417
418 @param[in] Json The provided JSON value.
419
420 @retval TRUE The JSON value contains a FALSE value.
421 @retval FALSE The JSON value doesn't contain a FALSE value.
422
423**/
424BOOLEAN
425EFIAPI
426JsonValueIsFalse (
427 IN EDKII_JSON_VALUE Json
428 );
429
430/**
431 The function is used to return if the provided JSON value contains a JSON NULL.
432
433 @param[in] Json The provided JSON value.
434
435 @retval TRUE The JSON value contains a JSON NULL.
436 @retval FALSE The JSON value doesn't contain a JSON NULL.
437
438**/
439BOOLEAN
440EFIAPI
441JsonValueIsNull (
442 IN EDKII_JSON_VALUE Json
443 );
444
445/**
446 The function is used to retrieve the associated array in an array type JSON value.
447
448 Any changes to the returned array will impact the original JSON value.
449
450 @param[in] Json The provided JSON value.
451
452 @retval Return the associated array in JSON value or NULL.
453
454**/
455EDKII_JSON_ARRAY
456EFIAPI
457JsonValueGetArray (
458 IN EDKII_JSON_VALUE Json
459 );
460
461/**
462 The function is used to retrieve the associated object in an object type JSON value.
463
464 Any changes to the returned object will impact the original JSON value.
465
466 @param[in] Json The provided JSON value.
467
468 @retval Return the associated object in JSON value or NULL.
469
470**/
471EDKII_JSON_OBJECT
472EFIAPI
473JsonValueGetObject (
474 IN EDKII_JSON_VALUE Json
475 );
476
477/**
478 The function is used to retrieve the associated Ascii string in a string type JSON value.
479
480 Any changes to the returned string will impact the original JSON value.
481
482 @param[in] Json The provided JSON value.
483
484 @retval Return the associated Ascii string in JSON value or NULL.
485
486**/
487CONST CHAR8 *
488EFIAPI
489JsonValueGetAsciiString (
490 IN EDKII_JSON_VALUE Json
491 );
492
493/**
494 The function is used to retrieve the associated Unicode string in a string type JSON value.
495
496 Caller can do any changes to the returned string without any impact to the original JSON
497 value, and caller needs to free the returned string using FreePool().
498
499 @param[in] Json The provided JSON value.
500
501 @retval Return the associated Unicode string in JSON value or NULL.
502
503**/
504CHAR16 *
505EFIAPI
506JsonValueGetUnicodeString (
507 IN EDKII_JSON_VALUE Json
508 );
509
510/**
511 The function is used to retrieve the associated integer in a integer type JSON value.
512
513 The input JSON value should not be NULL or contain no JSON Integer, otherwise it will
514 ASSERT() and return 0.
515
516 @param[in] Json The provided JSON value.
517
518 @retval Return the associated Integer in JSON value.
519
520**/
521INT64
522EFIAPI
523JsonValueGetInteger (
524 IN EDKII_JSON_VALUE Json
525 );
526
527/**
528 The function is used to retrieve the associated boolean in a boolean type JSON value.
529
530 The input JSON value should not be NULL or contain no JSON boolean, otherwise it will
531 ASSERT() and return FALSE.
532
533 @param[in] Json The provided JSON value.
534
535 @retval Return the associated value of JSON boolean.
536
537**/
538BOOLEAN
539EFIAPI
540JsonValueGetBoolean (
541 IN EDKII_JSON_VALUE Json
542 );
543
544/**
545 The function is used to retrieve the associated string in a string type JSON value.
546
547 Any changes to the returned string will impact the original JSON value.
548
549 @param[in] Json The provided JSON value.
550
551 @retval Return the associated Ascii string in JSON value or NULL on errors.
552
553**/
554CONST CHAR8 *
555EFIAPI
556JsonValueGetString (
557 IN EDKII_JSON_VALUE Json
558 );
559
560/**
561 The function is used to get the number of elements in a JSON object, or 0 if it is NULL or
562 not a JSON object.
563
564 @param[in] JsonObject The provided JSON object.
565
566 @retval Return the number of elements in this JSON object or 0.
567
568**/
569UINTN
570EFIAPI
571JsonObjectSize (
572 IN EDKII_JSON_OBJECT JsonObject
573 );
574
575/**
576 The function removes all elements from object. Returns 0 on success and -1 if object is not
577 a JSON object. The reference count of all removed values are decremented.
578
579 @param[in] JsonObject The provided JSON object.
580
581 @retval EFI_ABORTED Some error occur and operation aborted.
582 @retval EFI_SUCCESS JSON value has been appended to the end of the JSON array.
583
584**/
585EFI_STATUS
586EFIAPI
587JsonObjectClear (
588 IN EDKII_JSON_OBJECT JsonObject
589 );
590
591/**
592 The function is used to enumerate all keys in a JSON object.
593
594 Caller should be responsible to free the returned key array reference using
595 FreePool(). But contained keys are read only and must not be modified or freed.
596
597 @param[in] JsonObj The provided JSON object for enumeration.
598 @param[out] KeyCount The count of keys in this JSON object.
599
600 @retval Return an array of the enumerated keys in this JSON object or NULL if
601 JsonObj is not an JSON object, key count is zero or on other errors.
602
603**/
604CHAR8 **
605JsonObjectGetKeys (
606 IN EDKII_JSON_OBJECT JsonObj,
607 OUT UINTN *KeyCount
608 );
609
610/**
611 The function is used to get a JSON value corresponding to the input key from a JSON object.
612
613 It only returns a reference to this value and any changes on this value will impact the
614 original JSON object. If that is not expected, please call JsonValueClone() to clone it to
615 use.
616
617 Input key must be a valid NULL terminated UTF8 encoded string. NULL will be returned when
618 Key-Value is not found in this JSON object.
619
620 @param[in] JsonObj The provided JSON object.
621 @param[in] Key The key of the JSON value to be retrieved.
622
623 @retval Return the corresponding JSON value to key, or NULL on error.
624
625**/
626EDKII_JSON_VALUE
627EFIAPI
628JsonObjectGetValue (
629 IN CONST EDKII_JSON_OBJECT JsonObj,
630 IN CONST CHAR8 *Key
631 );
632
633/**
634 The function is used to set a JSON value corresponding to the input key from a JSON object,
635 and the reference count of this value will be increased by 1.
636
637 Input key must be a valid NULL terminated UTF8 encoded string. If there already is a value for
638 this key, this key will be assigned to the new JSON value. The old JSON value will be removed
639 from this object and thus its' reference count will be decreased by 1.
640
641 More details for reference count strategy can refer to the API description for JsonValueFree().
642
643 @param[in] JsonObj The provided JSON object.
644 @param[in] Key The key of the JSON value to be set.
645 @param[in] Json The JSON value to set to this JSON object mapped by key.
646
647 @retval EFI_ABORTED Some error occur and operation aborted.
648 @retval EFI_SUCCESS The JSON value has been set to this JSON object.
649
650**/
651EFI_STATUS
652EFIAPI
653JsonObjectSetValue (
654 IN EDKII_JSON_OBJECT JsonObj,
655 IN CONST CHAR8 *Key,
656 IN EDKII_JSON_VALUE Json
657 );
658
659/**
660 The function is used to get the number of elements in a JSON array. Returns or 0 if JsonArray
661 is NULL or not a JSON array.
662
663 @param[in] JsonArray The provided JSON array.
664
665 @retval Return the number of elements in this JSON array or 0.
666
667**/
668UINTN
669EFIAPI
670JsonArrayCount (
671 IN EDKII_JSON_ARRAY JsonArray
672 );
673
674/**
675 The function is used to return the JSON value in the array at position index. The valid range
676 for this index is from 0 to the return value of JsonArrayCount() minus 1.
677
678 It only returns a reference to this value and any changes on this value will impact the
679 original JSON object. If that is not expected, please call JsonValueClone() to clone it to
680 use.
681
682 If this array is NULL or not a JSON array, or if index is out of range, NULL will be returned.
683
684 @param[in] JsonArray The provided JSON Array.
685
686 @retval Return the JSON value located in the Index position or
687 NULL if JsonArray is not an array or no items in the array.
688
689**/
690EDKII_JSON_VALUE
691EFIAPI
692JsonArrayGetValue (
693 IN EDKII_JSON_ARRAY JsonArray,
694 IN UINTN Index
695 );
696
697/**
698 The function is used to append a JSON value to the end of the JSON array, and grow the size of
699 array by 1. The reference count of this value will be increased by 1.
700
701 More details for reference count strategy can refer to the API description for JsonValueFree().
702
703 @param[in] JsonArray The provided JSON object.
704 @param[in] Json The JSON value to append.
705
706 @retval EFI_ABORTED Some error occur and operation aborted.
707 @retval EFI_SUCCESS JSON value has been appended to the end of the JSON array.
708
709**/
710EFI_STATUS
711EFIAPI
712JsonArrayAppendValue (
713 IN EDKII_JSON_ARRAY JsonArray,
714 IN EDKII_JSON_VALUE Json
715 );
716
717/**
718 The function is used to remove a JSON value at position index, shifting the elements after index
719 one position towards the start of the array. The reference count of this value will be decreased
720 by 1.
721
722 More details for reference count strategy can refer to the API description for JsonValueFree().
723
724 @param[in] JsonArray The provided JSON array.
725 @param[in] Index The Index position before removal.
726
727 @retval EFI_ABORTED Some error occur and operation aborted.
728 @retval EFI_SUCCESS The JSON array has been removed at position index.
729
730**/
731EFI_STATUS
732EFIAPI
733JsonArrayRemoveValue (
734 IN EDKII_JSON_ARRAY JsonArray,
735 IN UINTN Index
736 );
737
738/**
739 Dump JSON to a buffer.
740
741 @param[in] JsonValue The provided JSON value.
742 @param[in] Flags The Index position before removal. The value
743 could be the combination of below flags.
744 - EDKII_JSON_INDENT(n)
745 - EDKII_JSON_COMPACT
746 - EDKII_JSON_ENSURE_ASCII
747 - EDKII_JSON_SORT_KEYS
748 - EDKII_JSON_PRESERVE_ORDER
749 - EDKII_JSON_ENCODE_ANY
750 - EDKII_JSON_ESCAPE_SLASH
751 - EDKII_JSON_REAL_PRECISION(n)
752 - EDKII_JSON_EMBED
753 See below URI for the JSON encoding flags reference.
754 https://jansson.readthedocs.io/en/2.13/apiref.html#encoding
755
756 @retval CHAR8 * Dump fail if NULL returned, otherwise the buffer
757 contain JSON payload in ASCII string. The return
758 value must be freed by the caller FreePool().
759**/
760CHAR8 *
761EFIAPI
762JsonDumpString (
763 IN EDKII_JSON_VALUE JsonValue,
764 IN UINTN Flags
765 );
766
767/**
768 Convert a string to JSON object.
769 The function is used to convert a NULL terminated CHAR8 string to a JSON
770 value. Only object and array represented strings can be converted successfully,
771 since they are the only valid root values of a JSON text for UEFI usage.
772
773 Real number and number with exponent part are not supported by UEFI.
774
775 Caller needs to cleanup the root value by calling JsonValueFree().
776
777 @param[in] String The NULL terminated CHAR8 string to convert.
778 @param[in] Flags Flags for loading JSON string.
779 @param[in] Error Returned error status.
780
781 @retval Array JSON value or object JSON value, or NULL when any error occurs.
782
783**/
784EDKII_JSON_VALUE
785EFIAPI
786JsonLoadString (
787 IN CONST CHAR8 *String,
788 IN UINT64 Flags,
789 IN EDKII_JSON_ERROR *Error
790 );
791
792/**
793 Load JSON from a buffer.
794
795 @param[in] Buffer Buffier to the JSON payload
796 @param[in] BufferLen Length of the buffer
797 @param[in] Flags Flag of loading JSON buffer, the value
798 could be the combination of below flags.
799 - EDKII_JSON_REJECT_DUPLICATES
800 - EDKII_JSON_DISABLE_EOF_CHECK
801 - EDKII_JSON_DECODE_ANY
802 - EDKII_JSON_DECODE_INT_AS_REAL
803 - EDKII_JSON_ALLOW_NUL
804 See below URI for the JSON encoding flags reference.
805 https://jansson.readthedocs.io/en/2.13/apiref.html?highlight=json_loadb#decoding
806
807 @param[in,out] Error Pointer EDKII_JSON_ERROR structure
808
809 @retval EDKII_JSON_VALUE NULL means fail to load JSON payload.
810**/
811EDKII_JSON_VALUE
812EFIAPI
813JsonLoadBuffer (
814 IN CONST CHAR8 *Buffer,
815 IN UINTN BufferLen,
816 IN UINTN Flags,
817 IN OUT EDKII_JSON_ERROR *Error
818 );
819
820/**
821 The reference count is used to track whether a value is still in use or not.
822 When a value is created, it's reference count is set to 1.
823 when the value is no longer needed, the reference count is decremented.
824 When the reference count drops to zero, there are no references left and the
825 value can be destroyed.
826
827 This function decrement the reference count of EDKII_JSON_VALUE. As soon as
828 a call to json_decref() drops the reference count to zero, the value is
829 destroyed and it can no longer be used.
830
831 @param[in] JsonValue JSON value
832**/
833VOID
834EFIAPI
835JsonDecreaseReference (
836 IN EDKII_JSON_VALUE JsonValue
837 );
838
839/**
840 The reference count is used to track whether a value is still in use or not.
841 When a value is created, it's reference count is set to 1.
842 If a reference to a value is kept (e.g. a value is stored somewhere for later use),
843 its reference count is incremented.
844
845 This function increment the reference count of json if it's not NULL.
846 Returns EDKII_JSON_VALUE.
847
848 @param[in] JsonValue JSON value
849 @retval EDKII_JSON_VALUE of itself
850**/
851EDKII_JSON_VALUE
852EFIAPI
853JsonIncreaseReference (
854 IN EDKII_JSON_VALUE JsonValue
855 );
856
857/**
858 Returns an opaque iterator which can be used to iterate over all key-value pairs
859 in object, or NULL if object is empty
860
861 @param[in] JsonValue JSON value
862**/
863VOID *
864EFIAPI
865JsonObjectIterator (
866 IN EDKII_JSON_VALUE JsonValue
867 );
868
869/**
870 Extract the associated value from iterator.
871
872 @param[in] Iterator Iterator pointer
873**/
874EDKII_JSON_VALUE
875EFIAPI
876JsonObjectIteratorValue (
877 IN VOID *Iterator
878 );
879
880/**
881 Returns an iterator pointing to the next key-value pair in object after iter,
882 or NULL if the whole object has been iterated through.
883
884 @param[in] JsonValue JSON value
885 @param[in] Iterator Iterator pointer
886 @retval Iterator pointer
887**/
888VOID *
889EFIAPI
890JsonObjectIteratorNext (
891 IN EDKII_JSON_VALUE JsonValue,
892 IN VOID *Iterator
893 );
894
895/**
896 Returns the key of iterator pointing
897
898 @param[in] Iterator Iterator pointer
899 @retval Key
900**/
901CHAR8 *
902EFIAPI
903JsonObjectIteratorKey (
904 IN VOID *Iterator
905 );
906
907/**
908 Returns the pointer of iterator by key.
909
910 @param[in] Key The key of interator pointer.
911 @retval Pointer to interator
912**/
913VOID *
914EFIAPI
915JsonObjectKeyToIterator (
916 IN CHAR8 *Key
917 );
918
919/**
920 Returns the json type of this json value
921
922 @param[in] JsonValue JSON value
923 @retval JSON type returned
924**/
925EDKII_JSON_TYPE
926EFIAPI
927JsonGetType (
928 IN EDKII_JSON_VALUE JsonValue
929 );
930
931#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette