#include <stdbool.h>
#include <launchdarkly/bindings/c/export.h>
Go to the source code of this file.
◆ LDValue
Value represents any of the data types supported by JSON, all of which can be used for a LaunchDarkly feature flag variation, or for an attribute in an evaluation context. Value instances are immutable.
A basic LDValue types can be created directly using the LDValue_New* methods. This includes: null-type, boolean-type, number-type, and string-type.
An array-type or object-type LDValue must be created using LDArrayBuilder_New() or LDObjectBuilder_New().
Basic LDValue types can be converted to raw types using the LDValue_Get* methods.
Accessing the members of object-type or array-type type must be done using iteration.
◆ LDValue_ArrayIter
LDValue_ArrayIter is a handle to an iterator, bound to an LDValue. It can be used to obtain the values of an array.
The iterator must be destroyed after use using LDValue_ArrayIter_Free. An iterator for an LDValue that has been freed should not be used.
◆ LDValue_ObjectIter
LDValue_ObjectIter is a handle to an iterator, bound to an LDValue. It can be used to obtain the keys and values of an object.
The iterator must be destroyed after use using LDValue_ObjectIter_Free. An iterator for an LDValue that has been freed should not be used.
◆ LDValueType
Describes the type of an LDValue. These correspond to the standard types in JSON.
Enumerator |
---|
LDValueType_Null | The value is null.
|
LDValueType_Bool | The value is a boolean.
|
LDValueType_Number | The value is a number. JSON does not have separate types for integers and floats.
|
LDValueType_String | The value is a string.
|
LDValueType_Array | The value is an array.
|
LDValueType_Object | The value is an object.
|
◆ LDValue_ArrayIter_End()
Check if an array-type iterator is at the end.
- Parameters
-
iter | The iterator to check. Must not be NULL. |
- Returns
- True if the iterator is at the end.
◆ LDValue_ArrayIter_Free()
Destroy an array iterator.
- Parameters
-
iter | The iterator to destroy. |
◆ LDValue_ArrayIter_New()
LDValue_ArrayIter_New |
( |
LDValue |
val | ) |
|
Obtain iterator over an array-type LDValue, otherwise NULL.
The iterator starts at the first element.
- Parameters
-
val | Target LDValue. Must not be NULL. |
- Returns
- Iterator, or NULL if not an array-type. The iterator must should be destroyed with LDValue_ArrayIter_Free().
◆ LDValue_ArrayIter_Next()
Move the array-type iterator to the next item. Should only be done for an iterator which is not at the end.
- Parameters
-
iter | The iterator to advance. Must not be NULL. |
◆ LDValue_ArrayIter_Value()
Get the value for the array-type iterator. The value's lifetime is valid only for as long as the iterator. To obtain a copy, call LDValue_NewValue with the result.
- Parameters
-
iter | The iterator to get a value for. Must not be NULL. |
- Returns
- The value reference.
◆ LDValue_Count()
Obtain number of LDValue elements stored in an array-type LDValue, or number of key/LDValue pairs stored in an object-type LDValue.
If not an array-type or object-type, returns 0.
- Parameters
-
val | Target LDValue. Must not be NULL. |
- Returns
- Count of LDValue elements, or 0 if not array-type/object-type.
◆ LDValue_Free()
Frees an LDValue.
An LDValue should only be freed when directly owned by the caller, i.e., it was never moved into an array or object builder.
- Parameters
-
◆ LDValue_GetBool()
Obtain value of a boolean-type LDValue, otherwise returns false.
- Parameters
-
val | Target LDValue. Must not be NULL. |
- Returns
- Boolean value, or false if not boolean-type.
◆ LDValue_GetNumber()
Obtain value of a number-type LDValue, otherwise return 0.
- Parameters
-
val | Target LDValue. Must not be NULL. |
- Returns
- Number value, or 0 if not number-type.
◆ LDValue_GetString()
Obtain value of a string-type LDValue, otherwise returns pointer to an empty string.
The returned string is only valid for the lifetime of the LDValue. If you need the string outside this lifetime, then a copy should be made.
- Parameters
-
val | Target LDValue. Must not be NULL. |
- Returns
- String value, or empty string if not string-type.
◆ LDValue_NewBool()
LDValue_NewBool |
( |
bool |
val | ) |
|
Allocates a new boolean-type LDValue.
- Parameters
-
- Returns
- New LDValue.
◆ LDValue_NewNull()
Allocates a new null-type LDValue. WARNING! A NULL
pointer is not a valid LDValue; to represent null (the JSON type), use this constructor.
- Returns
- New LDValue.
◆ LDValue_NewNumber()
LDValue_NewNumber |
( |
double |
val | ) |
|
Allocates a new number-type LDValue.
- Parameters
-
- Returns
- New LDValue.
◆ LDValue_NewString()
LDValue_NewString |
( |
char const * |
val | ) |
|
Allocates a new string-type LDValue.
The input string will be copied.
- Parameters
-
val | Constant reference to a string. The string is copied. Must not be NULL. |
- Returns
- New LDValue.
◆ LDValue_NewValue()
Allocates an LDValue by cloning an existing LDValue.
- Parameters
-
val | The source value. Must not be NULL. |
- Returns
- New LDValue.
◆ LDValue_ObjectIter_End()
Check if an object-type iterator is at the end.
- Parameters
-
iter | The iterator to check. Must not be NULL. |
- Returns
- True if the iterator is at the end.
◆ LDValue_ObjectIter_Free()
Destroy an object iterator.
- Parameters
-
iter | The iterator to destroy. |
◆ LDValue_ObjectIter_Key()
Get the key for an object-type iterator.
The returned key has a lifetime attached to that of the LDValue.
- Parameters
-
iter | The iterator to get a key for. Must not be NULL. |
- Returns
- The key.
◆ LDValue_ObjectIter_New()
LDValue_ObjectIter_New |
( |
LDValue |
val | ) |
|
Obtain iterator over an object-type LDValue, otherwise NULL.
The iterator starts at the first element.
- Parameters
-
val | Target LDValue. Must not be NULL. |
- Returns
- Iterator, or NULL if not an object-type. The iterator must should be destroyed with LDValue_ObjectIter_Free().
◆ LDValue_ObjectIter_Next()
Move the object-type iterator to the next item. Should only be done for an iterator which is not at the end.
- Parameters
-
iter | The iterator to advance. Must not be NULL. |
◆ LDValue_ObjectIter_Value()
Get the value for an object-type iterator. The value's lifetime is valid only for as long as the iterator. To obtain a copy, call LDValue_NewValue.
- Parameters
-
iter | The iterator to get a value for. Must not be NULL. |
- Returns
- The value.
◆ LDValue_SerializeJSON()
LDValue_SerializeJSON |
( |
LDValue |
val | ) |
|
Serializes the LDValue to a JSON value. The returning string should be freed with LDMemory_FreeString.
Please note that numbers are serialized using scientific notation; for example the number 17 would be serialized as '1.7E1'.
- Parameters
-
val | Target LDValue. Must not be NULL. |
- Returns
- A string containing the JSON representation of the LDValue. The string should be freed with LDMemory_FreeString.
◆ LDValue_Type()
Returns the type of an LDValue.
- Parameters
-
val | LDValue to inspect. Must not be NULL. |
- Returns
- Type of the LDValue, or LDValueType_Unrecognized if the type is unrecognized.