Couchbase Lite C
Couchbase Lite C API
Fleece.h
Go to the documentation of this file.
1//
2// Fleece.h
3//
4// Copyright 2016-Present Couchbase, Inc.
5//
6// Use of this software is governed by the Business Source License included
7// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
8// in that file, in accordance with the Business Source License, use of this
9// software will be governed by the Apache License, Version 2.0, included in
10// the file licenses/APL2.txt.
11//
12
13#pragma once
14#ifndef _FLEECE_H
15#define _FLEECE_H
16
17#include "FLSlice.h"
18#include <stdio.h>
19
20// On Windows, FLEECE_PUBLIC marks symbols as being exported from the shared library.
21// However, this is not the whole list of things that are exported. The API methods
22// are exported using a definition list, but it is not possible to correctly include
23// initialized global variables, so those need to be marked (both in the header and
24// implementation) with FLEECE_PUBLIC. See kFLNullValue below and in Fleece.cc
25// for an example.
26#if defined(_MSC_VER)
27#ifdef FLEECE_EXPORTS
28#define FLEECE_PUBLIC __declspec(dllexport)
29#else
30#define FLEECE_PUBLIC __declspec(dllimport)
31#endif
32#else
33#define FLEECE_PUBLIC
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40 // This is the C API! For the C++ API, see Fleece.hh.
41
42
44
48#ifndef FL_IMPL
49 typedef const struct _FLValue* FLValue;
50 typedef const struct _FLArray* FLArray;
51 typedef const struct _FLDict* FLDict;
52 typedef struct _FLSlot* FLSlot;
53 typedef struct _FLArray* FLMutableArray;
54 typedef struct _FLDict* FLMutableDict;
55 typedef struct _FLEncoder* FLEncoder;
56#endif
57
58
60 typedef enum {
62 kFLMemoryError, // Out of memory, or allocation failed
63 kFLOutOfRange, // Array index or iterator out of range
64 kFLInvalidData, // Bad input data (NaN, non-string key, etc.)
65 kFLEncodeError, // Structural error encoding (missing value, too many ends, etc.)
66 kFLJSONError, // Error parsing JSON
67 kFLUnknownValue, // Unparseable data in a Value (corrupt? Or from some distant future?)
68 kFLInternalError, // Something that shouldn't happen
69 kFLNotFound, // Key not found
70 kFLSharedKeysStateError, // Misuse of shared keys (not in transaction, etc.)
72 kFLUnsupported, // Operation is unsupported
73 } FLError;
74
75
77
78
88#ifndef FL_IMPL
89 typedef struct _FLDoc* FLDoc;
90 typedef struct _FLSharedKeys* FLSharedKeys;
91#endif
92
94 typedef enum {
106
107
112
117
120
124
127
130
133
136
151 bool FLDoc_SetAssociated(FLDoc doc, void *pointer, const char *type) FLAPI;
152
161 void* FLDoc_GetAssociated(FLDoc doc, const char *type) FLAPI FLPURE;
162
166
167
176
180
184
185
196
200
203 bool json5,
204 bool canonicalForm) FLAPI;
205
221 FLStringResult *outErrorMessage,
222 size_t *outErrorPos,
223 FLError *outError) FLAPI;
224
228 const char* FLDump(FLValue) FLAPI;
230 const char* FLDumpData(FLSlice data) FLAPI;
231
236
237
258 typedef enum {
266 kFLDict
268
269
271 typedef int64_t FLTimestamp;
272
274 #define FLTimestampNone INT64_MIN
275
276
280
283
289
292
296
302
307
314
321
324
329
332
335
338
342
345
348
355
360
361 static inline FLArray FLArray_Retain(FLArray v) {FLValue_Retain((FLValue)v); return v;}
362 static inline void FLArray_Release(FLArray v) {FLValue_Release((FLValue)v);}
363 static inline FLDict FLDict_Retain(FLDict v) {FLValue_Retain((FLValue)v); return v;}
364 static inline void FLDict_Release(FLDict v) {FLValue_Release((FLValue)v);}
365
372
377
380
383
384
386
387
401
405
408
411
413
431 typedef struct {
432#if !DOXYGEN_PARSING
433 void* _private1;
434 uint32_t _private2;
435 bool _private3;
436 void* _private4;
437#endif
439
443
446
449
452
455
460
461
465 typedef enum {
470 } FLCopyFlags;
471
472
485
489
493
497 }
501 }
502
505
508
511
516 void FLMutableArray_Insert(FLMutableArray array, uint32_t firstIndex, uint32_t count) FLAPI;
517
522 void FLMutableArray_Remove(FLMutableArray array, uint32_t firstIndex, uint32_t count) FLAPI;
523
527 void FLMutableArray_Resize(FLMutableArray array, uint32_t size) FLAPI;
528
535
542
543
545 static inline void FLMutableArray_SetNull(FLMutableArray NONNULL, uint32_t index);
547 static inline void FLMutableArray_SetBool(FLMutableArray NONNULL, uint32_t index, bool);
549 static inline void FLMutableArray_SetInt(FLMutableArray NONNULL, uint32_t index, int64_t);
553 static inline void FLMutableArray_SetUInt(FLMutableArray NONNULL, uint32_t index, uint64_t);
555 static inline void FLMutableArray_SetFloat(FLMutableArray NONNULL, uint32_t index, float);
557 static inline void FLMutableArray_SetDouble(FLMutableArray NONNULL, uint32_t index, double);
559 static inline void FLMutableArray_SetString(FLMutableArray NONNULL, uint32_t index, FLString);
561 static inline void FLMutableArray_SetData(FLMutableArray NONNULL, uint32_t index, FLSlice);
563 static inline void FLMutableArray_SetValue(FLMutableArray NONNULL, uint32_t index, FLValue);
565 static inline void FLMutableArray_SetArray(FLMutableArray NONNULL, uint32_t index, FLArray);
567 static inline void FLMutableArray_SetDict(FLMutableArray NONNULL, uint32_t index, FLDict);
568
572 static inline void FLMutableArray_AppendBool(FLMutableArray NONNULL, bool);
574 static inline void FLMutableArray_AppendInt(FLMutableArray NONNULL, int64_t);
578 static inline void FLMutableArray_AppendUInt(FLMutableArray NONNULL, uint64_t);
580 static inline void FLMutableArray_AppendFloat(FLMutableArray NONNULL, float);
582 static inline void FLMutableArray_AppendDouble(FLMutableArray NONNULL, double);
593
594
599
600
607
611
614
618
619 FLEECE_PUBLIC extern const FLDict kFLEmptyDict;
620
639 typedef struct {
640#if !DOXYGEN_PARSING
641 void* _private1;
642 uint32_t _private2;
643 bool _private3;
644 void* _private4[4];
645 int _private5;
646#endif
648
653
656
659
662
665
668
672
681 typedef struct {
682#if !DOXYGEN_PARSING
683 FLSlice _private1;
684 void* _private2;
685 uint32_t _private3, private4;
686 bool private5;
687#endif
688 } FLDictKey;
689
696
699
703
704
706
707
723
727
731
735 }
736
738 static inline void FLMutableDict_Release(FLMutableDict d) {
740 }
741
744
747
750
753
756
763
770
771
773 static inline void FLMutableDict_SetNull(FLMutableDict NONNULL, FLString key);
775 static inline void FLMutableDict_SetBool(FLMutableDict NONNULL, FLString key, bool);
777 static inline void FLMutableDict_SetInt(FLMutableDict NONNULL, FLString key, int64_t);
781 static inline void FLMutableDict_SetUInt(FLMutableDict NONNULL, FLString key, uint64_t);
783 static inline void FLMutableDict_SetFloat(FLMutableDict NONNULL, FLString key, float);
785 static inline void FLMutableDict_SetDouble(FLMutableDict NONNULL, FLString key, double);
796
797
802
803
810#ifndef FL_IMPL
811 typedef struct _FLDeepIterator* FLDeepIterator;
812#endif
813
818
820
823
826
829
832
835
838
841
842 typedef struct {
844 uint32_t index;
846
849 FLPathComponent* * NONNULL outPath,
850 size_t* NONNULL outDepth) FLAPI;
851
854
857
858
860
861
879#ifndef FL_IMPL
880 typedef struct _FLKeyPath* FLKeyPath;
881#endif
882
885
888
891
896
899
902
905 size_t i,
906 FLSlice *outDictKey NONNULL,
907 int32_t *outArrayIndex NONNULL) FLAPI;
908
910
911
934
935 typedef bool (*FLSharedKeysReadCallback)(void *context, FLSharedKeys);
936
938 void *context) FLAPI;
939
942
945
949
953
960
963
967
970
973
976
977
978 typedef struct _FLSharedKeyScope* FLSharedKeyScope;
981
982
984
985
1001 typedef enum {
1006
1007
1010
1019 size_t reserveSize,
1020 bool uniqueStrings) FLAPI;
1021
1024
1027
1030
1033
1036
1037
1053 bool reuseStrings, bool externPointers) FLAPI;
1054
1057
1061
1065
1068
1072
1085
1091
1094
1099
1104
1111
1117
1122
1131
1136
1142
1143
1149 bool FLEncoder_BeginArray(FLEncoder NONNULL, size_t reserveCount) FLAPI;
1150
1153
1154
1163 bool FLEncoder_BeginDict(FLEncoder NONNULL, size_t reserveCount) FLAPI;
1164
1167
1171
1174
1175
1178
1179
1184
1188 void FLEncoder_WriteValueAgain(FLEncoder e, intptr_t preWrittenValue);
1189
1190
1196
1197
1202
1209
1214
1219
1226
1229
1235
1236
1254
1263
1264
1274 FLSlice jsonDelta,
1275 FLError *error) FLAPI;
1276
1287 FLSlice jsonDelta,
1288 FLEncoder encoder) FLAPI;
1289
1290
1292
1293
1315
1322
1329
1330
1340
1341 static inline void FLSlot_SetArray(FLSlot NONNULL slot, FLArray array) {
1342 FLSlot_SetValue(slot, (FLValue)array);
1343 }
1344
1345 static inline void FLSlot_SetDict(FLSlot NONNULL slot, FLDict dict) {
1346 FLSlot_SetValue(slot, (FLValue)dict);
1347 }
1348
1349
1350 // implementations of the inline methods declared earlier:
1351
1352 static inline void FLMutableArray_SetNull(FLMutableArray a, uint32_t index) {
1354 }
1355 static inline void FLMutableArray_SetBool(FLMutableArray a, uint32_t index, bool val) {
1356 FLSlot_SetBool(FLMutableArray_Set(a, index), val);
1357 }
1358 static inline void FLMutableArray_SetInt(FLMutableArray a, uint32_t index, int64_t val) {
1359 FLSlot_SetInt(FLMutableArray_Set(a, index), val);
1360 }
1361 static inline void FLMutableArray_SetUInt(FLMutableArray a, uint32_t index, uint64_t val) {
1362 FLSlot_SetUInt(FLMutableArray_Set(a, index), val);
1363 }
1364 static inline void FLMutableArray_SetFloat(FLMutableArray a, uint32_t index, float val) {
1365 FLSlot_SetFloat(FLMutableArray_Set(a, index), val);
1366 }
1367 static inline void FLMutableArray_SetDouble(FLMutableArray a, uint32_t index, double val) {
1368 FLSlot_SetDouble(FLMutableArray_Set(a, index), val);
1369 }
1370 static inline void FLMutableArray_SetString(FLMutableArray a, uint32_t index, FLString val) {
1371 FLSlot_SetString(FLMutableArray_Set(a, index), val);
1372 }
1373 static inline void FLMutableArray_SetData(FLMutableArray a, uint32_t index, FLSlice val) {
1374 FLSlot_SetData(FLMutableArray_Set(a, index), val);
1375 }
1376 static inline void FLMutableArray_SetValue(FLMutableArray a, uint32_t index, FLValue val) {
1377 FLSlot_SetValue(FLMutableArray_Set(a, index), val);
1378 }
1379 static inline void FLMutableArray_SetArray(FLMutableArray a, uint32_t index, FLArray val) {
1381 }
1382 static inline void FLMutableArray_SetDict(FLMutableArray a, uint32_t index, FLDict val) {
1384 }
1385
1388 }
1389 static inline void FLMutableArray_AppendBool(FLMutableArray a, bool val) {
1391 }
1392 static inline void FLMutableArray_AppendInt(FLMutableArray a, int64_t val) {
1394 }
1395 static inline void FLMutableArray_AppendUInt(FLMutableArray a, uint64_t val) {
1397 }
1398 static inline void FLMutableArray_AppendFloat(FLMutableArray a, float val) {
1400 }
1401 static inline void FLMutableArray_AppendDouble(FLMutableArray a, double val) {
1403 }
1406 }
1409 }
1412 }
1415 }
1418 }
1419
1420 static inline void FLMutableDict_SetNull(FLMutableDict d, FLString key) {
1422 }
1423 static inline void FLMutableDict_SetBool(FLMutableDict d, FLString key, bool val) {
1424 FLSlot_SetBool(FLMutableDict_Set(d, key), val);
1425 }
1426 static inline void FLMutableDict_SetInt(FLMutableDict d, FLString key, int64_t val) {
1427 FLSlot_SetInt(FLMutableDict_Set(d, key), val);
1428 }
1429 static inline void FLMutableDict_SetUInt(FLMutableDict d, FLString key, uint64_t val) {
1430 FLSlot_SetUInt(FLMutableDict_Set(d, key), val);
1431 }
1432 static inline void FLMutableDict_SetFloat(FLMutableDict d, FLString key, float val) {
1433 FLSlot_SetFloat(FLMutableDict_Set(d, key), val);
1434 }
1435 static inline void FLMutableDict_SetDouble(FLMutableDict d, FLString key, double val) {
1436 FLSlot_SetDouble(FLMutableDict_Set(d, key), val);
1437 }
1438 static inline void FLMutableDict_SetString(FLMutableDict d, FLString key, FLString val) {
1439 FLSlot_SetString(FLMutableDict_Set(d, key), val);
1440 }
1441 static inline void FLMutableDict_SetData(FLMutableDict d, FLString key, FLSlice val) {
1442 FLSlot_SetData(FLMutableDict_Set(d, key), val);
1443 }
1444 static inline void FLMutableDict_SetValue(FLMutableDict d, FLString key, FLValue val) {
1445 FLSlot_SetValue(FLMutableDict_Set(d, key), val);
1446 }
1447 static inline void FLMutableDict_SetArray(FLMutableDict d, FLString key, FLArray val) {
1449 }
1450 static inline void FLMutableDict_SetDict(FLMutableDict d, FLString key, FLDict val) {
1452 }
1453
1454
1457#ifdef __cplusplus
1458}
1459#endif
1460
1461
1462#ifdef __OBJC__
1463// When compiling as Objective-C, include CoreFoundation / Objective-C utilities:
1464#include "Fleece+CoreFoundation.h"
1465#endif
1466
1467#endif // _FLEECE_H
#define FLPURE
Definition: Base.h:89
#define NONNULL
Definition: Base.h:68
#define MUST_USE_RESULT
Definition: Base.h:53
#define FLAPI
Definition: FLSlice.h:31
#define FLEECE_PUBLIC
Definition: Fleece.h:33
static void FLMutableArray_SetInt(FLMutableArray, uint32_t index, int64_t)
Stores an integer into an array.
Definition: Fleece.h:1358
bool FLMutableArray_IsChanged(FLMutableArray)
Returns true if the Array has been changed from the source it was copied from.
void FLMutableArray_Remove(FLMutableArray array, uint32_t firstIndex, uint32_t count)
Removes contiguous items from the array.
FLMutableDict FLMutableArray_GetMutableDict(FLMutableArray, uint32_t index)
Convenience function for getting an array-valued property in mutable form.
FLCopyFlags
Definition: Fleece.h:465
FLMutableArray FLMutableArray_GetMutableArray(FLMutableArray, uint32_t index)
Convenience function for getting an array-valued property in mutable form.
static void FLMutableArray_AppendDict(FLMutableArray, FLDict)
Appends a Fleece dictionary to an array.
Definition: Fleece.h:1416
static void FLMutableArray_SetArray(FLMutableArray, uint32_t index, FLArray)
Stores a Fleece array into an array.
Definition: Fleece.h:1379
bool FLArray_IsEmpty(FLArray) FLPURE
Returns true if an array is empty (or NULL).
static void FLMutableArray_AppendDouble(FLMutableArray, double)
Appends a 64-bit floating point number to an array.
Definition: Fleece.h:1401
static void FLMutableArray_SetUInt(FLMutableArray, uint32_t index, uint64_t)
Stores an unsigned integer into an array.
Definition: Fleece.h:1361
uint32_t FLArrayIterator_GetCount(const FLArrayIterator *) FLPURE
Returns the number of items remaining to be iterated, including the current one.
static void FLMutableArray_AppendUInt(FLMutableArray, uint64_t)
Appends an unsigned integer to an array.
Definition: Fleece.h:1395
FLMutableArray FLMutableArray_New(void)
Creates a new empty mutable Array.
void FLArrayIterator_Begin(FLArray, FLArrayIterator *)
Initializes a FLArrayIterator struct to iterate over an array.
static void FLMutableArray_SetFloat(FLMutableArray, uint32_t index, float)
Stores a 32-bit floating-point number into an array.
Definition: Fleece.h:1364
FLValue FLArrayIterator_GetValueAt(const FLArrayIterator *, uint32_t offset) FLPURE
Returns a value in the array at the given offset from the current value.
static void FLMutableArray_SetDict(FLMutableArray, uint32_t index, FLDict)
Stores a Fleece dictionary into an array.
Definition: Fleece.h:1382
static void FLMutableArray_AppendInt(FLMutableArray, int64_t)
Appends an integer to an array.
Definition: Fleece.h:1392
void FLMutableArray_SetChanged(FLMutableArray, bool)
Sets or clears the mutable Array's "changed" flag.
static void FLMutableArray_SetString(FLMutableArray, uint32_t index, FLString)
Stores a UTF-8-encoded string into an array.
Definition: Fleece.h:1370
static void FLMutableArray_AppendBool(FLMutableArray, bool)
Appends a boolean value to an array.
Definition: Fleece.h:1389
static void FLMutableArray_AppendString(FLMutableArray, FLString)
Appends a UTF-8-encoded string to an array.
Definition: Fleece.h:1404
FLMutableArray FLArray_AsMutable(FLArray) FLPURE
If the array is mutable, returns it cast to FLMutableArray, else NULL.
static void FLMutableArray_SetDouble(FLMutableArray, uint32_t index, double)
Stores a 64-bit floating point number into an array.
Definition: Fleece.h:1367
FLValue FLArray_Get(FLArray, uint32_t index) FLPURE
Returns an value at an array index, or NULL if the index is out of range.
static void FLMutableArray_AppendValue(FLMutableArray, FLValue)
Appends a Fleece value to an array.
Definition: Fleece.h:1410
static FLMutableArray FLMutableArray_Retain(FLMutableArray d)
Increments the ref-count of a mutable Array.
Definition: Fleece.h:495
void FLMutableArray_Insert(FLMutableArray array, uint32_t firstIndex, uint32_t count)
Inserts a contiguous range of JSON null values into the array.
static void FLMutableArray_SetData(FLMutableArray, uint32_t index, FLSlice)
Stores a binary data blob into an array.
Definition: Fleece.h:1373
FLEECE_PUBLIC const FLArray kFLEmptyArray
static void FLMutableArray_SetBool(FLMutableArray, uint32_t index, bool)
Stores a boolean value into an array.
Definition: Fleece.h:1355
static void FLMutableArray_Release(FLMutableArray d)
Decrements the refcount of (and possibly frees) a mutable Array.
Definition: Fleece.h:499
FLMutableArray FLMutableArray_NewFromJSON(FLString json, FLError *outError)
Creates a new mutable Array from JSON.
static void FLMutableArray_AppendNull(FLMutableArray)
Appends a JSON null value to an array.
Definition: Fleece.h:1386
bool FLArrayIterator_Next(FLArrayIterator *)
Advances the iterator to the next value, or returns false if at the end.
static void FLMutableArray_SetNull(FLMutableArray, uint32_t index)
Stores a JSON null value into an array.
Definition: Fleece.h:1352
static void FLMutableArray_AppendData(FLMutableArray, FLSlice)
Appends a binary data blob to an array.
Definition: Fleece.h:1407
FLMutableArray FLArray_MutableCopy(FLArray, FLCopyFlags)
Creates a new mutable Array that's a copy of the source Array.
FLValue FLArrayIterator_GetValue(const FLArrayIterator *) FLPURE
Returns the current value being iterated over.
uint32_t FLArray_Count(FLArray) FLPURE
Returns the number of items in an array, or 0 if the pointer is NULL.
static void FLMutableArray_AppendFloat(FLMutableArray, float)
Appends a 32-bit floating-point number to an array.
Definition: Fleece.h:1398
void FLMutableArray_Resize(FLMutableArray array, uint32_t size)
Changes the size of an array.
static void FLMutableArray_SetValue(FLMutableArray, uint32_t index, FLValue)
Stores a Fleece value into an array.
Definition: Fleece.h:1376
FLArray FLMutableArray_GetSource(FLMutableArray)
If the Array was created by FLArray_MutableCopy, returns the original source Array.
static void FLMutableArray_AppendArray(FLMutableArray, FLArray)
Appends a Fleece array to an array.
Definition: Fleece.h:1413
@ kFLDeepCopy
Definition: Fleece.h:467
@ kFLCopyImmutables
Definition: Fleece.h:468
@ kFLDefaultCopy
Definition: Fleece.h:466
@ kFLDeepCopyImmutables
Definition: Fleece.h:469
void FLDeepIterator_GetPath(FLDeepIterator, FLPathComponent **outPath, size_t *outDepth)
Returns the path as an array of FLPathComponents.
void FLDeepIterator_SkipChildren(FLDeepIterator)
Tells the iterator to skip the children of the current value.
size_t FLDeepIterator_GetDepth(FLDeepIterator)
Returns the current depth in the hierarchy, starting at 1 for the top-level children.
FLSlice FLDeepIterator_GetKey(FLDeepIterator)
Returns the key of the current value in its parent, or an empty slice if not in a dictionary.
struct _FLDeepIterator * FLDeepIterator
A reference to a deep iterator.
Definition: Fleece.h:811
FLValue FLDeepIterator_GetParent(FLDeepIterator)
Returns the parent/container of the current value, or NULL at the end of iteration.
void FLDeepIterator_Free(FLDeepIterator)
bool FLDeepIterator_Next(FLDeepIterator)
Advances the iterator to the next value, or returns false if at the end.
uint32_t FLDeepIterator_GetIndex(FLDeepIterator)
Returns the array index of the current value in its parent, or 0 if not in an array.
FLDeepIterator FLDeepIterator_New(FLValue)
Creates a FLDeepIterator to iterate over a dictionary.
FLValue FLDeepIterator_GetValue(FLDeepIterator)
Returns the current value being iterated over.
FLSliceResult FLDeepIterator_GetJSONPointer(FLDeepIterator)
Returns the current path in JSONPointer format (RFC 6901).
FLSliceResult FLDeepIterator_GetPathString(FLDeepIterator)
Returns the current path in JavaScript format.
void FLDictIterator_Begin(FLDict, FLDictIterator *)
Initializes a FLDictIterator struct to iterate over a dictionary.
bool FLMutableDict_IsChanged(FLMutableDict)
Returns true if the Dict has been changed from the source it was copied from.
FLString FLDictKey_GetString(const FLDictKey *)
Returns the string value of the key (which it was initialized with.)
static void FLMutableDict_SetDict(FLMutableDict, FLString key, FLDict)
Stores a Fleece dictionary into a mutable dictionary.
Definition: Fleece.h:1450
static void FLMutableDict_SetNull(FLMutableDict, FLString key)
Stores a JSON null value into a mutable dictionary.
Definition: Fleece.h:1420
FLMutableDict FLMutableDict_New(void)
Creates a new empty mutable Dict.
static FLMutableDict FLMutableDict_Retain(FLMutableDict d)
Increments the ref-count of a mutable Dict.
Definition: Fleece.h:733
FLString FLDictIterator_GetKeyString(const FLDictIterator *)
Returns the current key's string value.
uint32_t FLDict_Count(FLDict) FLPURE
Returns the number of items in a dictionary, or 0 if the pointer is NULL.
FLValue FLDict_GetWithKey(FLDict, FLDictKey *)
Looks up a key in a dictionary using an FLDictKey.
void FLMutableDict_SetChanged(FLMutableDict, bool)
Sets or clears the mutable Dict's "changed" flag.
static void FLMutableDict_SetData(FLMutableDict, FLString key, FLSlice)
Stores a binary data blob into a mutable dictionary.
Definition: Fleece.h:1441
FLMutableArray FLMutableDict_GetMutableArray(FLMutableDict, FLString key)
Convenience function for getting an array-valued property in mutable form.
FLValue FLDict_Get(FLDict, FLSlice keyString) FLPURE
Looks up a key in a dictionary, returning its value.
uint32_t FLDictIterator_GetCount(const FLDictIterator *) FLPURE
Returns the number of items remaining to be iterated, including the current one.
void FLMutableDict_RemoveAll(FLMutableDict)
Removes all keys and values.
FLEECE_PUBLIC const FLDict kFLEmptyDict
FLMutableDict FLDict_MutableCopy(FLDict source, FLCopyFlags)
Creates a new mutable Dict that's a copy of the source Dict.
void FLDictIterator_End(FLDictIterator *)
Cleans up after an iterator.
static void FLMutableDict_SetFloat(FLMutableDict, FLString key, float)
Stores a 32-bit floating-point number into a mutable dictionary.
Definition: Fleece.h:1432
static void FLMutableDict_SetInt(FLMutableDict, FLString key, int64_t)
Stores an integer into a mutable dictionary.
Definition: Fleece.h:1426
static void FLMutableDict_SetValue(FLMutableDict, FLString key, FLValue)
Stores a Fleece value into a mutable dictionary.
Definition: Fleece.h:1444
static void FLMutableDict_SetDouble(FLMutableDict, FLString key, double)
Stores a 64-bit floating point number into a mutable dictionary.
Definition: Fleece.h:1435
FLDict FLMutableDict_GetSource(FLMutableDict)
If the Dict was created by FLDict_MutableCopy, returns the original source Dict.
FLMutableDict FLDict_AsMutable(FLDict) FLPURE
If the dictionary is mutable, returns it cast to FLMutableDict, else NULL.
FLMutableDict FLMutableDict_NewFromJSON(FLString json, FLError *outError)
Creates a new mutable Dict from json.
bool FLDict_IsEmpty(FLDict) FLPURE
Returns true if a dictionary is empty (or NULL).
static void FLMutableDict_SetBool(FLMutableDict, FLString key, bool)
Stores a boolean value into a mutable dictionary.
Definition: Fleece.h:1423
FLMutableDict FLMutableDict_GetMutableDict(FLMutableDict, FLString key)
Convenience function for getting a dict-valued property in mutable form.
static void FLMutableDict_SetArray(FLMutableDict, FLString key, FLArray)
Stores a Fleece array into a mutable dictionary.
Definition: Fleece.h:1447
static void FLMutableDict_Release(FLMutableDict d)
Decrements the refcount of (and possibly frees) a mutable Dict.
Definition: Fleece.h:738
static void FLMutableDict_SetString(FLMutableDict, FLString key, FLString)
Stores a UTF-8-encoded string into a mutable dictionary.
Definition: Fleece.h:1438
void FLMutableDict_Remove(FLMutableDict, FLString key)
Removes the value for a key.
FLValue FLDictIterator_GetKey(const FLDictIterator *) FLPURE
Returns the current key being iterated over.
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.
FLDictKey FLDictKey_Init(FLSlice string)
Initializes an FLDictKey struct with a key string.
static void FLMutableDict_SetUInt(FLMutableDict, FLString key, uint64_t)
Stores an unsigned integer into a mutable dictionary.
Definition: Fleece.h:1429
bool FLEncoder_ConvertJSON(FLEncoder, FLSlice json)
Parses JSON data and writes the object(s) to the encoder.
const char * FLEncoder_GetErrorMessage(FLEncoder)
Returns the error message of an encoder, or NULL if there's no error.
FLSliceResult FLEncoder_Snip(FLEncoder e)
Returns the data written so far as a standalone Fleece document, whose root is the last value written...
bool FLEncoder_WriteUInt(FLEncoder, uint64_t)
Writes an unsigned integer to an encoder.
void FLEncoder_SetSharedKeys(FLEncoder, FLSharedKeys)
Tells the encoder to use a shared-keys mapping when encoding dictionary keys.
void FLEncoder_Free(FLEncoder)
Frees the space used by an encoder.
intptr_t FLEncoder_LastValueWritten(FLEncoder e)
Returns an opaque reference to the last complete value written to the encoder, if possible.
FLEncoder FLEncoder_NewWritingToFile(FILE *, bool uniqueStrings)
Creates a new Fleece encoder that writes to a file, not to memory.
void FLEncoder_SetExtraInfo(FLEncoder, void *info)
Associates an arbitrary user-defined value with the encoder.
void FLEncoder_SuppressTrailer(FLEncoder)
Tells the encoder not to write the two-byte Fleece trailer at the end of the data.
bool FLEncoder_WriteKey(FLEncoder, FLString)
Specifies the key for the next value to be written to the current dictionary.
FLEncoder FLEncoder_New(void)
Creates a new encoder, for generating Fleece data.
FLSlice FLEncoder_GetBase(FLEncoder)
Returns the base value passed to FLEncoder_Amend.
bool FLEncoder_WriteInt(FLEncoder, int64_t)
Writes an integer to an encoder.
void FLEncoder_WriteValueAgain(FLEncoder e, intptr_t preWrittenValue)
Writes another reference (a "pointer") to an already-written value, given a reference previously retu...
bool FLEncoder_BeginArray(FLEncoder, size_t reserveCount)
Begins writing an array value to an encoder.
bool FLEncoder_WriteUndefined(FLEncoder)
Writes an undefined value to an encoder.
bool FLEncoder_WriteFloat(FLEncoder, float)
Writes a 32-bit floating point number to an encoder.
bool FLEncoder_WriteBool(FLEncoder, bool)
Writes a boolean value (true or false) to an encoder.
void * FLEncoder_GetExtraInfo(FLEncoder)
Returns the user-defined value associated with the encoder; NULL by default.
bool FLEncoder_WriteDouble(FLEncoder, double)
Writes a 64-bit floating point number to an encoder.
FLDoc FLEncoder_FinishDoc(FLEncoder, FLError *)
Ends encoding; if there has been no error, it returns the encoded Fleece data packaged in an FLDoc.
bool FLEncoder_WriteDateString(FLEncoder encoder, FLTimestamp ts, bool asUTC)
Writes a timestamp to an encoder, as an ISO-8601 date string.
size_t FLEncoder_GetNextWritePos(FLEncoder)
Returns the byte offset in the encoded data where the next value will be written.
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 d...
bool FLEncoder_WriteNull(FLEncoder)
Writes a null value to an encoder.
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.
bool FLEncoder_BeginDict(FLEncoder, size_t reserveCount)
Begins writing a dictionary value to an encoder.
size_t FLEncoder_BytesWritten(FLEncoder)
Returns the number of bytes encoded so far.
bool FLEncoder_WriteData(FLEncoder, FLSlice)
Writes a binary data value (a blob) to an encoder.
size_t FLEncoder_FinishItem(FLEncoder)
Finishes encoding the current item, and returns its offset in the output data.
bool FLEncoder_WriteValue(FLEncoder, FLValue)
Writes a Fleece Value to an Encoder.
bool FLEncoder_WriteString(FLEncoder, FLString)
Writes a string to an encoder.
bool FLEncoder_WriteKeyValue(FLEncoder, FLValue)
Specifies the key for the next value to be written to the current dictionary.
FLEncoderFormat
Output formats a FLEncoder can generate.
Definition: Fleece.h:1001
bool FLEncoder_EndDict(FLEncoder)
Ends writing a dictionary value; pops back the previous encoding state.
void FLEncoder_Reset(FLEncoder)
Resets the state of an encoder without freeing it.
FLEncoder FLEncoder_NewWithOptions(FLEncoderFormat format, size_t reserveSize, bool uniqueStrings)
Creates a new encoder, allowing some options to be customized.
FLError FLEncoder_GetError(FLEncoder)
Returns the error code of an encoder, or NoError (0) if there's no error.
bool FLEncoder_EndArray(FLEncoder)
Ends writing an array value; pops back the previous encoding state.
bool FLEncoder_WriteRaw(FLEncoder, FLSlice)
Writes raw data directly to the encoded output.
@ kFLEncodeFleece
Fleece encoding.
Definition: Fleece.h:1002
@ kFLEncodeJSON5
JSON5, an extension of JSON with a more readable syntax
Definition: Fleece.h:1004
@ kFLEncodeJSON
JSON encoding.
Definition: Fleece.h:1003
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.
struct _FLKeyPath * FLKeyPath
A reference to a key path.
Definition: Fleece.h:880
bool FLKeyPath_Equals(FLKeyPath path1, FLKeyPath path2)
Equality test.
FLStringResult FLKeyPath_ToString(FLKeyPath path)
Returns a path in string form.
void FLKeyPath_Free(FLKeyPath)
Frees a compiled FLKeyPath object.
FLValue FLKeyPath_EvalOnce(FLSlice specifier, FLValue root, FLError *error)
Evaluates a key-path from a specifier string, for a given Fleece root object.
FLKeyPath FLKeyPath_New(FLSlice specifier, FLError *error)
Creates a new FLKeyPath object by compiling a path specifier string.
FLValue FLKeyPath_Eval(FLKeyPath, FLValue root)
Evaluates a compiled key-path for a given Fleece root object.
FLString FLSharedKeys_Decode(FLSharedKeys, int key)
Returns the key string that maps to the given integer key, else NULL.
FLSharedKeyScope FLSharedKeyScope_WithRange(FLSlice range, FLSharedKeys)
struct _FLSharedKeyScope * FLSharedKeyScope
Definition: Fleece.h:978
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.
void FLSharedKeys_Release(FLSharedKeys)
Decrements the reference count of an FLSharedKeys, freeing it when it reaches zero.
FLSliceResult FLSharedKeys_GetStateData(FLSharedKeys)
Returns a data blob containing the current state (all the keys and their integers....
void FLSharedKeys_WriteState(FLSharedKeys, FLEncoder)
Writes the current state to a Fleece encoder as a single value, which can later be decoded and passed...
FLSharedKeys FLSharedKeys_Retain(FLSharedKeys)
Increments the reference count of an FLSharedKeys.
bool FLSharedKeys_LoadState(FLSharedKeys, FLValue)
Updates an FLSharedKeys object with saved state, a Fleece value previously written by FLSharedKeys_Wr...
void FLSharedKeyScope_Free(FLSharedKeyScope)
void FLSharedKeys_RevertToCount(FLSharedKeys, unsigned oldCount)
Reverts an FLSharedKeys by "forgetting" any keys added since it had the count oldCount.
FLSharedKeys FLSharedKeys_New(void)
Creates a new empty FLSharedKeys object, which must eventually be released.
bool(* FLSharedKeysReadCallback)(void *context, FLSharedKeys)
Definition: Fleece.h:935
unsigned FLSharedKeys_Count(FLSharedKeys)
Returns the number of keys in the mapping.
bool FLSharedKeys_LoadStateData(FLSharedKeys, FLSlice)
Updates an FLSharedKeys with saved state data created by FLSharedKeys_GetStateData.
FLSharedKeys FLSharedKeys_NewWithRead(FLSharedKeysReadCallback, void *context)
FLValueType
Types of Fleece values.
Definition: Fleece.h:258
static void FLArray_Release(FLArray v)
Definition: Fleece.h:362
FLValueType FLValue_GetType(FLValue) FLPURE
Returns the data type of an arbitrary Value.
int64_t FLTimestamp
A timestamp, expressed as milliseconds since the Unix epoch (1-1-1970 midnight UTC....
Definition: Fleece.h:271
FLTimestamp FLValue_AsTimestamp(FLValue) FLPURE
Converts a value to a timestamp, in milliseconds since Unix epoch, or INT64_MIN on failure.
FLArray FLValue_AsArray(FLValue) FLPURE
If a FLValue represents an array, returns it cast to FLArray, else NULL.
FLStringResult FLValue_ToString(FLValue)
Returns a string representation of any scalar value.
bool FLValue_IsMutable(FLValue) FLPURE
Returns true if the value is mutable.
FLEECE_PUBLIC const FLValue kFLNullValue
A constant null value (not a NULL pointer!)
FLValue FLValue_NewString(FLString)
Allocates a string value on the heap.
static FLDict FLDict_Retain(FLDict v)
Definition: Fleece.h:363
FLString FLValue_AsString(FLValue) FLPURE
Returns the exact contents of a string value, or null for all other types.
bool FLValue_IsEqual(FLValue v1, FLValue v2) FLPURE
Compares two values for equality.
FLEECE_PUBLIC const FLValue kFLUndefinedValue
A constant undefined value.
bool FLValue_IsInteger(FLValue) FLPURE
Returns true if the value is non-NULL and represents an integer.
static FLArray FLArray_Retain(FLArray v)
Definition: Fleece.h:361
static void FLDict_Release(FLDict v)
Definition: Fleece.h:364
bool FLValue_AsBool(FLValue) FLPURE
Returns a value coerced to boolean.
FLSlice FLValue_AsData(FLValue) FLPURE
Returns the exact contents of a data value, or null for all other types.
bool FLValue_IsDouble(FLValue)
Returns true if the value is non-NULL and represents a 64-bit floating-point number.
float FLValue_AsFloat(FLValue) FLPURE
Returns a value coerced to a 32-bit floating point number.
bool FLValue_IsUnsigned(FLValue) FLPURE
Returns true if the value is non-NULL and represents an integer >= 2^63.
FLDict FLValue_AsDict(FLValue) FLPURE
If a FLValue represents a dictionary, returns it as an FLDict, else NULL.
FLValue FLValue_Retain(FLValue)
If this value is mutable (and thus heap-based) its ref-count is incremented.
double FLValue_AsDouble(FLValue) FLPURE
Returns a value coerced to a 32-bit floating point number.
void FLValue_Release(FLValue)
If this value is mutable (and thus heap-based) its ref-count is decremented, and if it reaches zero t...
uint64_t FLValue_AsUnsigned(FLValue) FLPURE
Returns a value coerced to an unsigned integer.
int64_t FLValue_AsInt(FLValue) FLPURE
Returns a value coerced to an integer.
FLValue FLValue_NewData(FLSlice)
Allocates a data/blob value on the heap.
@ kFLArray
An array of values.
Definition: Fleece.h:265
@ kFLNumber
A numeric value, either integer or floating-point.
Definition: Fleece.h:262
@ kFLBoolean
A true or false value.
Definition: Fleece.h:261
@ kFLString
A string.
Definition: Fleece.h:263
@ kFLNull
Equivalent to a JSON 'null'.
Definition: Fleece.h:260
@ kFLUndefined
Type of a NULL pointer, i.e. no such value, like JSON undefined. Also the type of a value created by ...
Definition: Fleece.h:259
@ kFLDict
A mapping of strings to values.
Definition: Fleece.h:266
@ kFLData
Binary data (no JSON equivalent)
Definition: Fleece.h:264
void FLSlot_SetValue(FLSlot, FLValue)
Stores an FLValue into a slot.
void FLSlot_SetNull(FLSlot)
Stores a JSON null into a slot.
static void FLSlot_SetArray(FLSlot slot, FLArray array)
Definition: Fleece.h:1341
static void FLSlot_SetDict(FLSlot slot, FLDict dict)
Definition: Fleece.h:1345
void FLSlot_SetBool(FLSlot, bool)
Stores a boolean into a slot.
void FLSlot_SetInt(FLSlot, int64_t)
Stores an integer into a slot.
void FLSlot_SetUInt(FLSlot, uint64_t)
Stores an unsigned int into a slot.
void FLSlot_SetString(FLSlot, FLString)
Stores a UTF-8 string into a slot.
MUST_USE_RESULT FLSlot FLMutableArray_Set(FLMutableArray, uint32_t index)
Returns an FLSlot that refers to the given index of the given array.
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.
void FLSlot_SetData(FLSlot, FLSlice)
Stores a data blob into a slot.
MUST_USE_RESULT FLSlot FLMutableArray_Append(FLMutableArray)
Appends a null value to the array and returns an FLSlot that refers to that position.
void FLSlot_SetFloat(FLSlot, float)
Stores a float into a slot.
void FLSlot_SetDouble(FLSlot, double)
Stores a double into a slot.
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 val...
bool FLEncodeJSONDelta(FLValue old, FLValue nuu, FLEncoder jsonEncoder)
Writes JSON that describes the changes to turn the value old into nuu.
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 th...
FLSliceResult FLCreateJSONDelta(FLValue old, FLValue nuu)
Returns JSON that encodes the changes to turn the value old into nuu.
FLStringResult FLJSON5_ToJSON(FLString json5, FLStringResult *outErrorMessage, size_t *outErrorPos, FLError *outError)
Converts valid JSON5 https://json5.org to JSON.
FLStringResult FLValue_ToJSON(FLValue)
Encodes a Fleece value as JSON (or a JSON fragment.) Any Data values will become base64-encoded JSON ...
FLStringResult FLValue_ToJSONX(FLValue v, bool json5, bool canonicalForm)
Most general Fleece to JSON converter.
FLStringResult FLValue_ToJSON5(FLValue v)
Encodes a Fleece value as JSON5, a more lenient variant of JSON that allows dictionary keys to be unq...
const char * FLDump(FLValue)
Debugging function that returns a C string of JSON.
const char * FLDumpData(FLSlice data)
Debugging function that returns a C string of JSON.
FLDoc FLDoc_FromJSON(FLSlice json, FLError *outError)
Creates an FLDoc from JSON-encoded data.
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...
void * FLDoc_GetAssociated(FLDoc doc, const char *type) FLPURE
Returns the pointer associated with the document.
FLDoc FLValue_FindDoc(FLValue) FLPURE
Looks up the Doc containing the Value, or NULL if the Value was created without a Doc.
bool FLDoc_SetAssociated(FLDoc doc, void *pointer, const char *type)
Associates an arbitrary pointer value with a document, and thus its contained values.
FLDoc FLDoc_Retain(FLDoc)
Adds a reference to an FLDoc.
FLSharedKeys FLDoc_GetSharedKeys(FLDoc) FLPURE
Returns the FLSharedKeys used by this FLDoc, as specified when it was created.
struct _FLDoc * FLDoc
A reference to a document.
Definition: Fleece.h:89
FLValue FLDoc_GetRoot(FLDoc) FLPURE
Returns the root value in the FLDoc, usually an FLDict.
FLValue FLValue_FromData(FLSlice data, FLTrust) FLPURE
Returns a pointer to the root value in the encoded data, or NULL if validation failed.
FLStringResult FLData_Dump(FLSlice data)
Produces a human-readable dump of the Value encoded in the data.
FLTrust
Specifies whether not input data is trusted to be 100% valid Fleece.
Definition: Fleece.h:94
struct _FLSharedKeys * FLSharedKeys
A reference to a shared-keys mapping.
Definition: Fleece.h:90
FLSliceResult FLDoc_GetAllocedData(FLDoc) FLPURE
Returns the FLSliceResult data owned by the document, if any, else a null slice.
FLSliceResult FLData_ConvertJSON(FLSlice json, FLError *outError)
Directly converts JSON data to Fleece-encoded data.
FLSlice FLDoc_GetData(FLDoc) FLPURE
Returns the encoded Fleece data backing the document.
void FLDoc_Release(FLDoc)
Releases a reference to an FLDoc.
@ kFLTrusted
Input data is trusted to be valid.
Definition: Fleece.h:104
@ kFLUntrusted
Input data is not trusted to be valid, and will be fully validated by the API call.
Definition: Fleece.h:96
struct _FLDict * FLMutableDict
A reference to a mutable dictionary.
Definition: Fleece.h:54
const struct _FLDict * FLDict
A reference to a dictionary (map) value.
Definition: Fleece.h:51
struct _FLSlot * FLSlot
A reference to a mutable array/dict item.
Definition: Fleece.h:52
struct _FLArray * FLMutableArray
A reference to a mutable array.
Definition: Fleece.h:53
FLError
Error codes returned from some API calls.
Definition: Fleece.h:60
const struct _FLArray * FLArray
A reference to an array value.
Definition: Fleece.h:50
struct _FLEncoder * FLEncoder
A reference to an encoder.
Definition: Fleece.h:55
const struct _FLValue * FLValue
A reference to a value of any type.
Definition: Fleece.h:49
@ kFLNotFound
Definition: Fleece.h:69
@ kFLInvalidData
Definition: Fleece.h:64
@ kFLInternalError
Definition: Fleece.h:68
@ kFLSharedKeysStateError
Definition: Fleece.h:70
@ kFLOutOfRange
Definition: Fleece.h:63
@ kFLEncodeError
Definition: Fleece.h:65
@ kFLMemoryError
Definition: Fleece.h:62
@ kFLUnsupported
Definition: Fleece.h:72
@ kFLUnknownValue
Definition: Fleece.h:67
@ kFLJSONError
Definition: Fleece.h:66
@ kFLPOSIXError
Definition: Fleece.h:71
@ kFLNoError
Definition: Fleece.h:61
Opaque array iterator.
Definition: Fleece.h:431
Opaque dictionary iterator.
Definition: Fleece.h:639
Opaque key for a dictionary.
Definition: Fleece.h:681
Definition: Fleece.h:842
uint32_t index
Array index, only if there's no key.
Definition: Fleece.h:844
FLSlice key
Dict key, or kFLSliceNull if none.
Definition: Fleece.h:843
A simple reference to a block of memory.
Definition: FLSlice.h:46
A heap-allocated block of memory returned from an API call.
Definition: FLSlice.h:64