Couchbase Lite C
Couchbase Lite C API
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
Fleece.h File Reference
#include "FLSlice.h"
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  FLArrayIterator
 Opaque array iterator. More...
 
struct  FLDictIterator
 Opaque dictionary iterator. More...
 
struct  FLDictKey
 Opaque key for a dictionary. More...
 
struct  FLPathComponent
 

Macros

#define _FLEECE_H
 
#define FLEECE_PUBLIC
 
#define FLTimestampNone   INT64_MIN
 A value representing a missing timestamp; returned when a date cannot be parsed. More...
 

Typedefs

typedef const struct _FLValue * FLValue
 A reference to a value of any type. More...
 
typedef const struct _FLArray * FLArray
 A reference to an array value. More...
 
typedef const struct _FLDict * FLDict
 A reference to a dictionary (map) value. More...
 
typedef struct _FLSlot * FLSlot
 A reference to a mutable array/dict item. More...
 
typedef struct _FLArray * FLMutableArray
 A reference to a mutable array. More...
 
typedef struct _FLDict * FLMutableDict
 A reference to a mutable dictionary. More...
 
typedef struct _FLEncoder * FLEncoder
 A reference to an encoder. More...
 
typedef int64_t FLTimestamp
 A timestamp, expressed as milliseconds since the Unix epoch (1-1-1970 midnight UTC.) More...
 
typedef struct _FLDeepIterator * FLDeepIterator
 A reference to a deep iterator. More...
 
typedef struct _FLKeyPath * FLKeyPath
 A reference to a key path. More...
 
typedef bool(* FLSharedKeysReadCallback) (void *context, FLSharedKeys)
 
typedef struct _FLSharedKeyScope * FLSharedKeyScope
 

Enumerations

enum  FLError {
  kFLNoError = 0 , kFLMemoryError , kFLOutOfRange , kFLInvalidData ,
  kFLEncodeError , kFLJSONError , kFLUnknownValue , kFLInternalError ,
  kFLNotFound , kFLSharedKeysStateError , kFLPOSIXError , kFLUnsupported
}
 Error codes returned from some API calls. More...
 
enum  FLValueType {
  kFLUndefined = -1 , kFLNull = 0 , kFLBoolean , kFLNumber ,
  kFLString , kFLData , kFLArray , kFLDict
}
 Types of Fleece values. More...
 

Functions

FLStringResult FLValue_ToJSON (FLValue)
 Encodes a Fleece value as JSON (or a JSON fragment.) Any Data values will become base64-encoded JSON strings. More...
 
FLStringResult FLValue_ToJSON5 (FLValue v)
 Encodes a Fleece value as JSON5, a more lenient variant of JSON that allows dictionary keys to be unquoted if they're alphanumeric. More...
 
FLStringResult FLValue_ToJSONX (FLValue v, bool json5, bool canonicalForm)
 Most general Fleece to JSON converter. More...
 
FLStringResult FLJSON5_ToJSON (FLString json5, FLStringResult *outErrorMessage, size_t *outErrorPos, FLError *outError)
 Converts valid JSON5 https://json5.org to JSON. More...
 
FLValueType FLValue_GetType (FLValue) FLPURE
 Returns the data type of an arbitrary Value. More...
 
bool FLValue_IsInteger (FLValue) FLPURE
 Returns true if the value is non-NULL and represents an integer. More...
 
bool FLValue_IsUnsigned (FLValue) FLPURE
 Returns true if the value is non-NULL and represents an integer >= 2^63. More...
 
bool FLValue_IsDouble (FLValue)
 Returns true if the value is non-NULL and represents a 64-bit floating-point number. More...
 
bool FLValue_AsBool (FLValue) FLPURE
 Returns a value coerced to boolean. More...
 
int64_t FLValue_AsInt (FLValue) FLPURE
 Returns a value coerced to an integer. More...
 
uint64_t FLValue_AsUnsigned (FLValue) FLPURE
 Returns a value coerced to an unsigned integer. More...
 
float FLValue_AsFloat (FLValue) FLPURE
 Returns a value coerced to a 32-bit floating point number. More...
 
double FLValue_AsDouble (FLValue) FLPURE
 Returns a value coerced to a 32-bit floating point number. More...
 
FLString FLValue_AsString (FLValue) FLPURE
 Returns the exact contents of a string value, or null for all other types. More...
 
FLTimestamp FLValue_AsTimestamp (FLValue) FLPURE
 Converts a value to a timestamp, in milliseconds since Unix epoch, or INT64_MIN on failure. More...
 
FLSlice FLValue_AsData (FLValue) FLPURE
 Returns the exact contents of a data value, or null for all other types. More...
 
FLArray FLValue_AsArray (FLValue) FLPURE
 If a FLValue represents an array, returns it cast to FLArray, else NULL. More...
 
FLDict FLValue_AsDict (FLValue) FLPURE
 If a FLValue represents a dictionary, returns it as an FLDict, else NULL. More...
 
FLStringResult FLValue_ToString (FLValue)
 Returns a string representation of any scalar value. More...
 
bool FLValue_IsEqual (FLValue v1, FLValue v2) FLPURE
 Compares two values for equality. More...
 
bool FLValue_IsMutable (FLValue) FLPURE
 Returns true if the value is mutable. More...
 
FLValue FLValue_NewString (FLString)
 Allocates a string value on the heap. More...
 
FLValue FLValue_NewData (FLSlice)
 Allocates a data/blob value on the heap. More...
 
uint32_t FLArray_Count (FLArray) FLPURE
 Returns the number of items in an array, or 0 if the pointer is NULL. More...
 
bool FLArray_IsEmpty (FLArray) FLPURE
 Returns true if an array is empty (or NULL). More...
 
FLMutableArray FLArray_AsMutable (FLArray) FLPURE
 If the array is mutable, returns it cast to FLMutableArray, else NULL. More...
 
FLValue FLArray_Get (FLArray, uint32_t index) FLPURE
 Returns an value at an array index, or NULL if the index is out of range. More...
 
uint32_t FLDict_Count (FLDict) FLPURE
 Returns the number of items in a dictionary, or 0 if the pointer is NULL. More...
 
bool FLDict_IsEmpty (FLDict) FLPURE
 Returns true if a dictionary is empty (or NULL). More...
 
FLMutableDict FLDict_AsMutable (FLDict) FLPURE
 If the dictionary is mutable, returns it cast to FLMutableDict, else NULL. More...
 
FLValue FLDict_Get (FLDict, FLSlice keyString) FLPURE
 Looks up a key in a dictionary, returning its value. More...
 
FLDeepIterator FLDeepIterator_New (FLValue)
 Creates a FLDeepIterator to iterate over a dictionary. More...
 
void FLDeepIterator_Free (FLDeepIterator)
 
FLValue FLDeepIterator_GetValue (FLDeepIterator)
 Returns the current value being iterated over. More...
 
FLValue FLDeepIterator_GetParent (FLDeepIterator)
 Returns the parent/container of the current value, or NULL at the end of iteration. More...
 
FLSlice FLDeepIterator_GetKey (FLDeepIterator)
 Returns the key of the current value in its parent, or an empty slice if not in a dictionary. More...
 
uint32_t FLDeepIterator_GetIndex (FLDeepIterator)
 Returns the array index of the current value in its parent, or 0 if not in an array. More...
 
size_t FLDeepIterator_GetDepth (FLDeepIterator)
 Returns the current depth in the hierarchy, starting at 1 for the top-level children. More...
 
void FLDeepIterator_SkipChildren (FLDeepIterator)
 Tells the iterator to skip the children of the current value. More...
 
bool FLDeepIterator_Next (FLDeepIterator)
 Advances the iterator to the next value, or returns false if at the end. More...
 
void FLDeepIterator_GetPath (FLDeepIterator, FLPathComponent **outPath, size_t *outDepth)
 Returns the path as an array of FLPathComponents. More...
 
FLSliceResult FLDeepIterator_GetPathString (FLDeepIterator)
 Returns the current path in JavaScript format. More...
 
FLSliceResult FLDeepIterator_GetJSONPointer (FLDeepIterator)
 Returns the current path in JSONPointer format (RFC 6901). More...
 
FLKeyPath FLKeyPath_New (FLSlice specifier, FLError *error)
 Creates a new FLKeyPath object by compiling a path specifier string. More...
 
void FLKeyPath_Free (FLKeyPath)
 Frees a compiled FLKeyPath object. More...
 
FLValue FLKeyPath_Eval (FLKeyPath, FLValue root)
 Evaluates a compiled key-path for a given Fleece root object. More...
 
FLValue FLKeyPath_EvalOnce (FLSlice specifier, FLValue root, FLError *error)
 Evaluates a key-path from a specifier string, for a given Fleece root object. More...
 
FLStringResult FLKeyPath_ToString (FLKeyPath path)
 Returns a path in string form. More...
 
bool FLKeyPath_Equals (FLKeyPath path1, FLKeyPath path2)
 Equality test. More...
 
bool FLKeyPath_GetElement (FLKeyPath, size_t i, FLSlice *outDictKey, int32_t *outArrayIndex)
 Returns an element of a path, either a key or an array index. More...
 
FLSharedKeys FLSharedKeys_New (void)
 Creates a new empty FLSharedKeys object, which must eventually be released. More...
 
FLSharedKeys FLSharedKeys_NewWithRead (FLSharedKeysReadCallback, void *context)
 
FLSliceResult FLSharedKeys_GetStateData (FLSharedKeys)
 Returns a data blob containing the current state (all the keys and their integers.) More...
 
bool FLSharedKeys_LoadStateData (FLSharedKeys, FLSlice)
 Updates an FLSharedKeys with saved state data created by FLSharedKeys_GetStateData. More...
 
void FLSharedKeys_WriteState (FLSharedKeys, FLEncoder)
 Writes the current state to a Fleece encoder as a single value, which can later be decoded and passed to FLSharedKeys_LoadState. More...
 
bool FLSharedKeys_LoadState (FLSharedKeys, FLValue)
 Updates an FLSharedKeys object with saved state, a Fleece value previously written by FLSharedKeys_WriteState. More...
 
int FLSharedKeys_Encode (FLSharedKeys, FLString, bool add)
 Maps a key string to a number in the range [0...2047], or returns -1 if it isn't mapped. More...
 
FLString FLSharedKeys_Decode (FLSharedKeys, int key)
 Returns the key string that maps to the given integer key, else NULL. More...
 
unsigned FLSharedKeys_Count (FLSharedKeys)
 Returns the number of keys in the mapping. More...
 
void FLSharedKeys_RevertToCount (FLSharedKeys, unsigned oldCount)
 Reverts an FLSharedKeys by "forgetting" any keys added since it had the count oldCount. More...
 
FLSharedKeys FLSharedKeys_Retain (FLSharedKeys)
 Increments the reference count of an FLSharedKeys. More...
 
void FLSharedKeys_Release (FLSharedKeys)
 Decrements the reference count of an FLSharedKeys, freeing it when it reaches zero. More...
 
FLSharedKeyScope FLSharedKeyScope_WithRange (FLSlice range, FLSharedKeys)
 
void FLSharedKeyScope_Free (FLSharedKeyScope)
 
FLSliceResult FLCreateJSONDelta (FLValue old, FLValue nuu)
 Returns JSON that encodes the changes to turn the value old into nuu. More...
 
bool FLEncodeJSONDelta (FLValue old, FLValue nuu, FLEncoder jsonEncoder)
 Writes JSON that describes the changes to turn the value old into nuu. More...
 
FLSliceResult FLApplyJSONDelta (FLValue old, FLSlice jsonDelta, FLError *error)
 Applies the JSON data created by CreateJSONDelta to the value old, which must be equal to the old value originally passed to FLCreateJSONDelta, and returns a Fleece document equal to the original nuu value. More...
 
bool FLEncodeApplyingJSONDelta (FLValue old, FLSlice jsonDelta, FLEncoder encoder)
 Applies the (parsed) JSON data created by CreateJSONDelta to the value old, which must be equal to the old value originally passed to FLCreateJSONDelta, and writes the corresponding nuu value to the encoder. More...
 
MUST_USE_RESULT FLSlot FLMutableArray_Set (FLMutableArray, uint32_t index)
 Returns an FLSlot that refers to the given index of the given array. More...
 
MUST_USE_RESULT FLSlot FLMutableArray_Append (FLMutableArray)
 Appends a null value to the array and returns an FLSlot that refers to that position. More...
 
MUST_USE_RESULT FLSlot FLMutableDict_Set (FLMutableDict FL_NONNULL, FLString key)
 Returns an FLSlot that refers to the given key/value pair of the given dictionary. More...
 
void FLSlot_SetNull (FLSlot)
 Stores a JSON null into a slot. More...
 
void FLSlot_SetBool (FLSlot, bool)
 Stores a boolean into a slot. More...
 
void FLSlot_SetInt (FLSlot, int64_t)
 Stores an integer into a slot. More...
 
void FLSlot_SetUInt (FLSlot, uint64_t)
 Stores an unsigned int into a slot. More...
 
void FLSlot_SetFloat (FLSlot, float)
 Stores a float into a slot. More...
 
void FLSlot_SetDouble (FLSlot, double)
 Stores a double into a slot. More...
 
void FLSlot_SetString (FLSlot, FLString)
 Stores a UTF-8 string into a slot. More...
 
void FLSlot_SetData (FLSlot, FLSlice)
 Stores a data blob into a slot. More...
 
void FLSlot_SetValue (FLSlot, FLValue)
 Stores an FLValue into a slot. More...
 
static void FLSlot_SetArray (FLSlot slot, FLArray array)
 
static void FLSlot_SetDict (FLSlot slot, FLDict dict)
 
Parsing And Converting Values Directly
FLValue FLValue_FromData (FLSlice data, FLTrust) FLPURE
 Returns a pointer to the root value in the encoded data, or NULL if validation failed. More...
 
FLSliceResult FLData_ConvertJSON (FLSlice json, FLError *outError)
 Directly converts JSON data to Fleece-encoded data. More...
 
FLStringResult FLData_Dump (FLSlice data)
 Produces a human-readable dump of the Value encoded in the data. More...
 
Debugging Functions
const char * FLDump (FLValue)
 Debugging function that returns a C string of JSON. More...
 
const char * FLDumpData (FLSlice data)
 Debugging function that returns a C string of JSON. More...
 
Ref-counting (mutable values only)
FLValue FLValue_Retain (FLValue)
 If this value is mutable (and thus heap-based) its ref-count is incremented. More...
 
void FLValue_Release (FLValue)
 If this value is mutable (and thus heap-based) its ref-count is decremented, and if it reaches zero the value is freed. More...
 
static FLArray FLArray_Retain (FLArray v)
 
static void FLArray_Release (FLArray v)
 
static FLDict FLDict_Retain (FLDict v)
 
static void FLDict_Release (FLDict v)
 
Array iteration

Iterating an array typically looks like this:

FLArrayIterator_Begin(theArray, &iter);
FLValue value;
while (NULL != (value = FLArrayIterator_GetValue(&iter))) {
// ...
}
void FLArrayIterator_Begin(FLArray, FLArrayIterator *)
Initializes a FLArrayIterator struct to iterate over an array.
bool FLArrayIterator_Next(FLArrayIterator *)
Advances the iterator to the next value, or returns false if at the end.
FLValue FLArrayIterator_GetValue(const FLArrayIterator *) FLPURE
Returns the current value being iterated over.
const struct _FLValue * FLValue
A reference to a value of any type.
Definition: Fleece.h:49
Opaque array iterator.
Definition: Fleece.h:431
void FLArrayIterator_Begin (FLArray, FLArrayIterator *)
 Initializes a FLArrayIterator struct to iterate over an array. More...
 
FLValue FLArrayIterator_GetValue (const FLArrayIterator *) FLPURE
 Returns the current value being iterated over. More...
 
FLValue FLArrayIterator_GetValueAt (const FLArrayIterator *, uint32_t offset) FLPURE
 Returns a value in the array at the given offset from the current value. More...
 
uint32_t FLArrayIterator_GetCount (const FLArrayIterator *) FLPURE
 Returns the number of items remaining to be iterated, including the current one. More...
 
bool FLArrayIterator_Next (FLArrayIterator *)
 Advances the iterator to the next value, or returns false if at the end. More...
 
Dict iteration

Iterating a dictionary typically looks like this:

FLDictIterator_Begin(theDict, &iter);
FLValue value;
while (NULL != (value = FLDictIterator_GetValue(&iter))) {
// ...
}
void FLDictIterator_Begin(FLDict, FLDictIterator *)
Initializes a FLDictIterator struct to iterate over a dictionary.
FLString FLDictIterator_GetKeyString(const FLDictIterator *)
Returns the current key's string value.
bool FLDictIterator_Next(FLDictIterator *)
Advances the iterator to the next value, or returns false if at the end.
FLValue FLDictIterator_GetValue(const FLDictIterator *) FLPURE
Returns the current value being iterated over.
Opaque dictionary iterator.
Definition: Fleece.h:639
A simple reference to a block of memory.
Definition: FLSlice.h:46
void FLDictIterator_Begin (FLDict, FLDictIterator *)
 Initializes a FLDictIterator struct to iterate over a dictionary. More...
 
FLValue FLDictIterator_GetKey (const FLDictIterator *) FLPURE
 Returns the current key being iterated over. More...
 
FLString FLDictIterator_GetKeyString (const FLDictIterator *)
 Returns the current key's string value. More...
 
FLValue FLDictIterator_GetValue (const FLDictIterator *) FLPURE
 Returns the current value being iterated over. More...
 
uint32_t FLDictIterator_GetCount (const FLDictIterator *) FLPURE
 Returns the number of items remaining to be iterated, including the current one. More...
 
bool FLDictIterator_Next (FLDictIterator *)
 Advances the iterator to the next value, or returns false if at the end. More...
 
void FLDictIterator_End (FLDictIterator *)
 Cleans up after an iterator. More...
 
Optimized Keys
FLDictKey FLDictKey_Init (FLSlice string)
 Initializes an FLDictKey struct with a key string. More...
 
FLString FLDictKey_GetString (const FLDictKey *)
 Returns the string value of the key (which it was initialized with.) More...
 
FLValue FLDict_GetWithKey (FLDict, FLDictKey *)
 Looks up a key in a dictionary using an FLDictKey. More...
 
Mutable dictionaries
FLMutableDict FLDict_MutableCopy (FLDict source, FLCopyFlags)
 Creates a new mutable Dict that's a copy of the source Dict. More...
 
FLMutableDict FLMutableDict_New (void)
 Creates a new empty mutable Dict. More...
 
FLMutableDict FLMutableDict_NewFromJSON (FLString json, FLError *outError)
 Creates a new mutable Dict from json. More...
 
static FLMutableDict FLMutableDict_Retain (FLMutableDict d)
 Increments the ref-count of a mutable Dict. More...
 
static void FLMutableDict_Release (FLMutableDict d)
 Decrements the refcount of (and possibly frees) a mutable Dict. More...
 
FLDict FLMutableDict_GetSource (FLMutableDict)
 If the Dict was created by FLDict_MutableCopy, returns the original source Dict. More...
 
bool FLMutableDict_IsChanged (FLMutableDict)
 Returns true if the Dict has been changed from the source it was copied from. More...
 
void FLMutableDict_SetChanged (FLMutableDict, bool)
 Sets or clears the mutable Dict's "changed" flag. More...
 
void FLMutableDict_Remove (FLMutableDict, FLString key)
 Removes the value for a key. More...
 
void FLMutableDict_RemoveAll (FLMutableDict)
 Removes all keys and values. More...
 
FLMutableArray FLMutableDict_GetMutableArray (FLMutableDict, FLString key)
 Convenience function for getting an array-valued property in mutable form. More...
 
FLMutableDict FLMutableDict_GetMutableDict (FLMutableDict, FLString key)
 Convenience function for getting a dict-valued property in mutable form. More...
 
static void FLMutableDict_SetNull (FLMutableDict, FLString key)
 Stores a JSON null value into a mutable dictionary. More...
 
static void FLMutableDict_SetBool (FLMutableDict, FLString key, bool)
 Stores a boolean value into a mutable dictionary. More...
 
static void FLMutableDict_SetInt (FLMutableDict, FLString key, int64_t)
 Stores an integer into a mutable dictionary. More...
 
static void FLMutableDict_SetUInt (FLMutableDict, FLString key, uint64_t)
 Stores an unsigned integer into a mutable dictionary. More...
 
static void FLMutableDict_SetFloat (FLMutableDict, FLString key, float)
 Stores a 32-bit floating-point number into a mutable dictionary. More...
 
static void FLMutableDict_SetDouble (FLMutableDict, FLString key, double)
 Stores a 64-bit floating point number into a mutable dictionary. More...
 
static void FLMutableDict_SetString (FLMutableDict, FLString key, FLString)
 Stores a UTF-8-encoded string into a mutable dictionary. More...
 
static void FLMutableDict_SetData (FLMutableDict, FLString key, FLSlice)
 Stores a binary data blob into a mutable dictionary. More...
 
static void FLMutableDict_SetValue (FLMutableDict, FLString key, FLValue)
 Stores a Fleece value into a mutable dictionary. More...
 
static void FLMutableDict_SetArray (FLMutableDict, FLString key, FLArray)
 Stores a Fleece array into a mutable dictionary. More...
 
static void FLMutableDict_SetDict (FLMutableDict, FLString key, FLDict)
 Stores a Fleece dictionary into a mutable dictionary. More...
 
Writing to the encoder
Note
The functions that write to the encoder do not return error codes, just a 'false' result on error. The actual error is attached to the encoder and can be accessed by calling FLEncoder_GetError or FLEncoder_End.

After an error occurs, the encoder will ignore all subsequent writes.

bool FLEncoder_WriteNull (FLEncoder)
 Writes a null value to an encoder. More...
 
bool FLEncoder_WriteUndefined (FLEncoder)
 Writes an undefined value to an encoder. More...
 
bool FLEncoder_WriteBool (FLEncoder, bool)
 Writes a boolean value (true or false) to an encoder. More...
 
bool FLEncoder_WriteInt (FLEncoder, int64_t)
 Writes an integer to an encoder. More...
 
bool FLEncoder_WriteUInt (FLEncoder, uint64_t)
 Writes an unsigned integer to an encoder. More...
 
bool FLEncoder_WriteFloat (FLEncoder, float)
 Writes a 32-bit floating point number to an encoder. More...
 
bool FLEncoder_WriteDouble (FLEncoder, double)
 Writes a 64-bit floating point number to an encoder. More...
 
bool FLEncoder_WriteString (FLEncoder, FLString)
 Writes a string to an encoder. More...
 
bool FLEncoder_WriteDateString (FLEncoder encoder, FLTimestamp ts, bool asUTC)
 Writes a timestamp to an encoder, as an ISO-8601 date string. More...
 
bool FLEncoder_WriteData (FLEncoder, FLSlice)
 Writes a binary data value (a blob) to an encoder. More...
 
bool FLEncoder_WriteRaw (FLEncoder, FLSlice)
 Writes raw data directly to the encoded output. More...
 
bool FLEncoder_BeginArray (FLEncoder, size_t reserveCount)
 Begins writing an array value to an encoder. More...
 
bool FLEncoder_EndArray (FLEncoder)
 Ends writing an array value; pops back the previous encoding state. More...
 
bool FLEncoder_BeginDict (FLEncoder, size_t reserveCount)
 Begins writing a dictionary value to an encoder. More...
 
bool FLEncoder_WriteKey (FLEncoder, FLString)
 Specifies the key for the next value to be written to the current dictionary. More...
 
bool FLEncoder_WriteKeyValue (FLEncoder, FLValue)
 Specifies the key for the next value to be written to the current dictionary. More...
 
bool FLEncoder_EndDict (FLEncoder)
 Ends writing a dictionary value; pops back the previous encoding state. More...
 
bool FLEncoder_WriteValue (FLEncoder, FLValue)
 Writes a Fleece Value to an Encoder. More...
 
intptr_t FLEncoder_LastValueWritten (FLEncoder e)
 Returns an opaque reference to the last complete value written to the encoder, if possible. More...
 
void FLEncoder_WriteValueAgain (FLEncoder e, intptr_t preWrittenValue)
 Writes another reference (a "pointer") to an already-written value, given a reference previously returned from FLEncoder_LastValueWritten. More...
 
FLSliceResult FLEncoder_Snip (FLEncoder e)
 Returns the data written so far as a standalone Fleece document, whose root is the last value written. More...
 
bool FLEncoder_ConvertJSON (FLEncoder, FLSlice json)
 Parses JSON data and writes the object(s) to the encoder. More...
 
Finishing up
size_t FLEncoder_FinishItem (FLEncoder)
 Finishes encoding the current item, and returns its offset in the output data. More...
 
FLDoc FLEncoder_FinishDoc (FLEncoder, FLError *)
 Ends encoding; if there has been no error, it returns the encoded Fleece data packaged in an FLDoc. More...
 
MUST_USE_RESULT FLSliceResult FLEncoder_Finish (FLEncoder e, FLError *outError)
 Ends encoding; if there has been no error, it returns the encoded data, else null. More...
 
Error handling
FLError FLEncoder_GetError (FLEncoder)
 Returns the error code of an encoder, or NoError (0) if there's no error. More...
 
const char * FLEncoder_GetErrorMessage (FLEncoder)
 Returns the error message of an encoder, or NULL if there's no error. More...
 

Variables

FLEECE_PUBLIC const FLValue kFLNullValue
 A constant null value (not a NULL pointer!) More...
 
FLEECE_PUBLIC const FLValue kFLUndefinedValue
 A constant undefined value. More...
 
FLEECE_PUBLIC const FLArray kFLEmptyArray
 
FLEECE_PUBLIC const FLDict kFLEmptyDict
 

FLDoc

An FLDoc points to (and often owns) Fleece-encoded data and provides access to its Fleece values.

enum  FLTrust { kFLUntrusted , kFLTrusted }
 Specifies whether not input data is trusted to be 100% valid Fleece. More...
 
typedef struct _FLDoc * FLDoc
 A reference to a document. More...
 
typedef struct _FLSharedKeys * FLSharedKeys
 A reference to a shared-keys mapping. More...
 
FLDoc FLDoc_FromResultData (FLSliceResult data, FLTrust, FLSharedKeys, FLSlice externData)
 Creates an FLDoc from Fleece-encoded data that's been returned as a result from FLSlice_Copy or other API. More...
 
FLDoc FLDoc_FromJSON (FLSlice json, FLError *outError)
 Creates an FLDoc from JSON-encoded data. More...
 
void FLDoc_Release (FLDoc)
 Releases a reference to an FLDoc. More...
 
FLDoc FLDoc_Retain (FLDoc)
 Adds a reference to an FLDoc. More...
 
FLSlice FLDoc_GetData (FLDoc) FLPURE
 Returns the encoded Fleece data backing the document. More...
 
FLSliceResult FLDoc_GetAllocedData (FLDoc) FLPURE
 Returns the FLSliceResult data owned by the document, if any, else a null slice. More...
 
FLValue FLDoc_GetRoot (FLDoc) FLPURE
 Returns the root value in the FLDoc, usually an FLDict. More...
 
FLSharedKeys FLDoc_GetSharedKeys (FLDoc) FLPURE
 Returns the FLSharedKeys used by this FLDoc, as specified when it was created. More...
 
bool FLDoc_SetAssociated (FLDoc doc, void *pointer, const char *type)
 Associates an arbitrary pointer value with a document, and thus its contained values. More...
 
void * FLDoc_GetAssociated (FLDoc doc, const char *type) FLPURE
 Returns the pointer associated with the document. More...
 
FLDoc FLValue_FindDoc (FLValue) FLPURE
 Looks up the Doc containing the Value, or NULL if the Value was created without a Doc. More...
 

Mutable Arrays

enum  FLCopyFlags { kFLDefaultCopy = 0 , kFLDeepCopy = 1 , kFLCopyImmutables = 2 , kFLDeepCopyImmutables = (kFLDeepCopy | kFLCopyImmutables) }
 
FLMutableArray FLArray_MutableCopy (FLArray, FLCopyFlags)
 Creates a new mutable Array that's a copy of the source Array. More...
 
FLMutableArray FLMutableArray_New (void)
 Creates a new empty mutable Array. More...
 
FLMutableArray FLMutableArray_NewFromJSON (FLString json, FLError *outError)
 Creates a new mutable Array from JSON. More...
 
static FLMutableArray FLMutableArray_Retain (FLMutableArray d)
 Increments the ref-count of a mutable Array. More...
 
static void FLMutableArray_Release (FLMutableArray d)
 Decrements the refcount of (and possibly frees) a mutable Array. More...
 
FLArray FLMutableArray_GetSource (FLMutableArray)
 If the Array was created by FLArray_MutableCopy, returns the original source Array. More...
 
bool FLMutableArray_IsChanged (FLMutableArray)
 Returns true if the Array has been changed from the source it was copied from. More...
 
void FLMutableArray_SetChanged (FLMutableArray, bool)
 Sets or clears the mutable Array's "changed" flag. More...
 
void FLMutableArray_Insert (FLMutableArray array, uint32_t firstIndex, uint32_t count)
 Inserts a contiguous range of JSON null values into the array. More...
 
void FLMutableArray_Remove (FLMutableArray array, uint32_t firstIndex, uint32_t count)
 Removes contiguous items from the array. More...
 
void FLMutableArray_Resize (FLMutableArray array, uint32_t size)
 Changes the size of an array. More...
 
FLMutableArray FLMutableArray_GetMutableArray (FLMutableArray, uint32_t index)
 Convenience function for getting an array-valued property in mutable form. More...
 
FLMutableDict FLMutableArray_GetMutableDict (FLMutableArray, uint32_t index)
 Convenience function for getting an array-valued property in mutable form. More...
 
static void FLMutableArray_SetNull (FLMutableArray, uint32_t index)
 Stores a JSON null value into an array. More...
 
static void FLMutableArray_SetBool (FLMutableArray, uint32_t index, bool)
 Stores a boolean value into an array. More...
 
static void FLMutableArray_SetInt (FLMutableArray, uint32_t index, int64_t)
 Stores an integer into an array. More...
 
static void FLMutableArray_SetUInt (FLMutableArray, uint32_t index, uint64_t)
 Stores an unsigned integer into an array. More...
 
static void FLMutableArray_SetFloat (FLMutableArray, uint32_t index, float)
 Stores a 32-bit floating-point number into an array. More...
 
static void FLMutableArray_SetDouble (FLMutableArray, uint32_t index, double)
 Stores a 64-bit floating point number into an array. More...
 
static void FLMutableArray_SetString (FLMutableArray, uint32_t index, FLString)
 Stores a UTF-8-encoded string into an array. More...
 
static void FLMutableArray_SetData (FLMutableArray, uint32_t index, FLSlice)
 Stores a binary data blob into an array. More...
 
static void FLMutableArray_SetValue (FLMutableArray, uint32_t index, FLValue)
 Stores a Fleece value into an array. More...
 
static void FLMutableArray_SetArray (FLMutableArray, uint32_t index, FLArray)
 Stores a Fleece array into an array. More...
 
static void FLMutableArray_SetDict (FLMutableArray, uint32_t index, FLDict)
 Stores a Fleece dictionary into an array. More...
 
static void FLMutableArray_AppendNull (FLMutableArray)
 Appends a JSON null value to an array. More...
 
static void FLMutableArray_AppendBool (FLMutableArray, bool)
 Appends a boolean value to an array. More...
 
static void FLMutableArray_AppendInt (FLMutableArray, int64_t)
 Appends an integer to an array. More...
 
static void FLMutableArray_AppendUInt (FLMutableArray, uint64_t)
 Appends an unsigned integer to an array. More...
 
static void FLMutableArray_AppendFloat (FLMutableArray, float)
 Appends a 32-bit floating-point number to an array. More...
 
static void FLMutableArray_AppendDouble (FLMutableArray, double)
 Appends a 64-bit floating point number to an array. More...
 
static void FLMutableArray_AppendString (FLMutableArray, FLString)
 Appends a UTF-8-encoded string to an array. More...
 
static void FLMutableArray_AppendData (FLMutableArray, FLSlice)
 Appends a binary data blob to an array. More...
 
static void FLMutableArray_AppendValue (FLMutableArray, FLValue)
 Appends a Fleece value to an array. More...
 
static void FLMutableArray_AppendArray (FLMutableArray, FLArray)
 Appends a Fleece array to an array. More...
 
static void FLMutableArray_AppendDict (FLMutableArray, FLDict)
 Appends a Fleece dictionary to an array. More...
 

Setup and configuration

enum  FLEncoderFormat { kFLEncodeFleece , kFLEncodeJSON , kFLEncodeJSON5 }
 Output formats a FLEncoder can generate. More...
 
FLEncoder FLEncoder_New (void)
 Creates a new encoder, for generating Fleece data. More...
 
FLEncoder FLEncoder_NewWithOptions (FLEncoderFormat format, size_t reserveSize, bool uniqueStrings)
 Creates a new encoder, allowing some options to be customized. More...
 
FLEncoder FLEncoder_NewWritingToFile (FILE *, bool uniqueStrings)
 Creates a new Fleece encoder that writes to a file, not to memory. More...
 
void FLEncoder_Free (FLEncoder)
 Frees the space used by an encoder. More...
 
void FLEncoder_SetSharedKeys (FLEncoder, FLSharedKeys)
 Tells the encoder to use a shared-keys mapping when encoding dictionary keys. More...
 
void FLEncoder_SetExtraInfo (FLEncoder, void *info)
 Associates an arbitrary user-defined value with the encoder. More...
 
void * FLEncoder_GetExtraInfo (FLEncoder)
 Returns the user-defined value associated with the encoder; NULL by default. More...
 
void FLEncoder_Amend (FLEncoder e, FLSlice base, bool reuseStrings, bool externPointers)
 Tells the encoder to logically append to the given Fleece document, rather than making a standalone document. More...
 
FLSlice FLEncoder_GetBase (FLEncoder)
 Returns the base value passed to FLEncoder_Amend. More...
 
void FLEncoder_SuppressTrailer (FLEncoder)
 Tells the encoder not to write the two-byte Fleece trailer at the end of the data. More...
 
void FLEncoder_Reset (FLEncoder)
 Resets the state of an encoder without freeing it. More...
 
size_t FLEncoder_BytesWritten (FLEncoder)
 Returns the number of bytes encoded so far. More...
 
size_t FLEncoder_GetNextWritePos (FLEncoder)
 Returns the byte offset in the encoded data where the next value will be written. More...
 

Macro Definition Documentation

◆ _FLEECE_H

#define _FLEECE_H

◆ FLEECE_PUBLIC

#define FLEECE_PUBLIC