Couchbase Lite C
Couchbase Lite C API
Fleece.h
Go to the documentation of this file.
1//
2// Fleece.h
3//
4// Copyright (c) 2016 Couchbase, Inc All rights reserved.
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18
19#pragma once
20#ifndef _FLEECE_H
21#define _FLEECE_H
22
23#include "FLSlice.h"
24#include <stdio.h>
25
26// On Windows, FLEECE_PUBLIC marks symbols as being exported from the shared library.
27// However, this is not the whole list of things that are exported. The API methods
28// are exported using a definition list, but it is not possible to correctly include
29// initialized global variables, so those need to be marked (both in the header and
30// implementation) with FLEECE_PUBLIC. See kFLNullValue below and in Fleece.cc
31// for an example.
32#if defined(_MSC_VER)
33#ifdef FLEECE_EXPORTS
34#define FLEECE_PUBLIC __declspec(dllexport)
35#else
36#define FLEECE_PUBLIC __declspec(dllimport)
37#endif
38#else
39#define FLEECE_PUBLIC
40#endif
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46 // This is the C API! For the C++ API, see Fleece.hh.
47
48
50
54#ifndef FL_IMPL
55 typedef const struct _FLValue* FLValue;
56 typedef const struct _FLArray* FLArray;
57 typedef const struct _FLDict* FLDict;
58 typedef struct _FLSlot* FLSlot;
59 typedef struct _FLArray* FLMutableArray;
60 typedef struct _FLDict* FLMutableDict;
61 typedef struct _FLEncoder* FLEncoder;
62#endif
63
64
66 typedef enum {
68 kFLMemoryError, // Out of memory, or allocation failed
69 kFLOutOfRange, // Array index or iterator out of range
70 kFLInvalidData, // Bad input data (NaN, non-string key, etc.)
71 kFLEncodeError, // Structural error encoding (missing value, too many ends, etc.)
72 kFLJSONError, // Error parsing JSON
73 kFLUnknownValue, // Unparseable data in a Value (corrupt? Or from some distant future?)
74 kFLInternalError, // Something that shouldn't happen
75 kFLNotFound, // Key not found
76 kFLSharedKeysStateError, // Misuse of shared keys (not in transaction, etc.)
78 kFLUnsupported, // Operation is unsupported
79 } FLError;
80
81
83
84
94#ifndef FL_IMPL
95 typedef struct _FLDoc* FLDoc;
96 typedef struct _FLSharedKeys* FLSharedKeys;
97#endif
98
100 typedef enum {
112
113
118
123
126
130
133
136
139
142
157 bool FLDoc_SetAssociated(FLDoc doc, void *pointer, const char *type) FLAPI;
158
167 void* FLDoc_GetAssociated(FLDoc doc, const char *type) FLAPI FLPURE;
168
172
173
182
186
190
191
202
206
209 bool json5,
210 bool canonicalForm) FLAPI;
211
227 FLStringResult *outErrorMessage,
228 size_t *outErrorPos,
229 FLError *outError) FLAPI;
230
234 const char* FLDump(FLValue) FLAPI;
236 const char* FLDumpData(FLSlice data) FLAPI;
237
242
243
264 typedef enum {
272 kFLDict
274
275
277 typedef int64_t FLTimestamp;
278
280 #define FLTimestampNone INT64_MIN
281
282
286
289
295
298
302
308
313
320
327
330
335
338
341
344
348
351
354
361
366
367 static inline FLArray FLArray_Retain(FLArray v) {FLValue_Retain((FLValue)v); return v;}
368 static inline void FLArray_Release(FLArray v) {FLValue_Release((FLValue)v);}
369 static inline FLDict FLDict_Retain(FLDict v) {FLValue_Retain((FLValue)v); return v;}
370 static inline void FLDict_Release(FLDict v) {FLValue_Release((FLValue)v);}
371
378
383
386
387
389
390
404
408
411
414
416
434 typedef struct {
435#if !DOXYGEN_PARSING
436 void* _private1;
437 uint32_t _private2;
438 bool _private3;
439 void* _private4;
440#endif
442
446
449
452
455
458
463
464
468 typedef enum {
473 } FLCopyFlags;
474
475
488
492
496 }
500 }
501
504
507
510
515 void FLMutableArray_Insert(FLMutableArray array, uint32_t firstIndex, uint32_t count) FLAPI;
516
521 void FLMutableArray_Remove(FLMutableArray array, uint32_t firstIndex, uint32_t count) FLAPI;
522
526 void FLMutableArray_Resize(FLMutableArray array, uint32_t size) FLAPI;
527
534
541
542
544 static inline void FLMutableArray_SetNull(FLMutableArray NONNULL, uint32_t index);
546 static inline void FLMutableArray_SetBool(FLMutableArray NONNULL, uint32_t index, bool);
548 static inline void FLMutableArray_SetInt(FLMutableArray NONNULL, uint32_t index, int64_t);
552 static inline void FLMutableArray_SetUInt(FLMutableArray NONNULL, uint32_t index, uint64_t);
554 static inline void FLMutableArray_SetFloat(FLMutableArray NONNULL, uint32_t index, float);
556 static inline void FLMutableArray_SetDouble(FLMutableArray NONNULL, uint32_t index, double);
558 static inline void FLMutableArray_SetString(FLMutableArray NONNULL, uint32_t index, FLString);
560 static inline void FLMutableArray_SetData(FLMutableArray NONNULL, uint32_t index, FLSlice);
562 static inline void FLMutableArray_SetValue(FLMutableArray NONNULL, uint32_t index, FLValue);
564 static inline void FLMutableArray_SetArray(FLMutableArray NONNULL, uint32_t index, FLArray);
566 static inline void FLMutableArray_SetDict(FLMutableArray NONNULL, uint32_t index, FLDict);
567
571 static inline void FLMutableArray_AppendBool(FLMutableArray NONNULL, bool);
573 static inline void FLMutableArray_AppendInt(FLMutableArray NONNULL, int64_t);
577 static inline void FLMutableArray_AppendUInt(FLMutableArray NONNULL, uint64_t);
579 static inline void FLMutableArray_AppendFloat(FLMutableArray NONNULL, float);
581 static inline void FLMutableArray_AppendDouble(FLMutableArray NONNULL, double);
592
593
598
599
606
610
613
617
618 FLEECE_PUBLIC extern const FLDict kFLEmptyDict;
619
638 typedef struct {
639#if !DOXYGEN_PARSING
640 void* _private1;
641 uint32_t _private2;
642 bool _private3;
643 void* _private4[4];
644 int _private5;
645#endif
647
652
655
658
661
664
667
671
680 typedef struct {
681#if !DOXYGEN_PARSING
682 FLSlice _private1;
683 void* _private2;
684 uint32_t _private3, private4;
685 bool private5;
686#endif
687 } FLDictKey;
688
695
698
702
703
705
706
722
726
730 }
731
733 static inline void FLMutableDict_Release(FLMutableDict d) {
735 }
736
739
742
745
748
751
758
765
766
768 static inline void FLMutableDict_SetNull(FLMutableDict NONNULL, FLString key);
770 static inline void FLMutableDict_SetBool(FLMutableDict NONNULL, FLString key, bool);
772 static inline void FLMutableDict_SetInt(FLMutableDict NONNULL, FLString key, int64_t);
776 static inline void FLMutableDict_SetUInt(FLMutableDict NONNULL, FLString key, uint64_t);
778 static inline void FLMutableDict_SetFloat(FLMutableDict NONNULL, FLString key, float);
780 static inline void FLMutableDict_SetDouble(FLMutableDict NONNULL, FLString key, double);
791
792
797
798
805#ifndef FL_IMPL
806 typedef struct _FLDeepIterator* FLDeepIterator;
807#endif
808
813
815
818
821
824
827
830
833
836
837 typedef struct {
839 uint32_t index;
841
844 FLPathComponent* * NONNULL outPath,
845 size_t* NONNULL outDepth) FLAPI;
846
849
852
853
855
856
874#ifndef FL_IMPL
875 typedef struct _FLKeyPath* FLKeyPath;
876#endif
877
880
883
886
891
894
897
900 size_t i,
901 FLSlice *outDictKey NONNULL,
902 int32_t *outArrayIndex NONNULL) FLAPI;
903
905
906
929
930 typedef bool (*FLSharedKeysReadCallback)(void *context, FLSharedKeys);
931
933 void *context) FLAPI;
934
937
940
944
948
955
958
962
965
968
971
972
973 typedef struct _FLSharedKeyScope* FLSharedKeyScope;
976
977
979
980
996 typedef enum {
1001
1002
1005
1014 size_t reserveSize,
1015 bool uniqueStrings) FLAPI;
1016
1019
1022
1025
1028
1031
1032
1048 bool reuseStrings, bool externPointers) FLAPI;
1049
1052
1056
1060
1063
1067
1080
1086
1089
1094
1099
1106
1112
1117
1126
1131
1137
1138
1144 bool FLEncoder_BeginArray(FLEncoder NONNULL, size_t reserveCount) FLAPI;
1145
1148
1149
1158 bool FLEncoder_BeginDict(FLEncoder NONNULL, size_t reserveCount) FLAPI;
1159
1162
1166
1169
1170
1173
1174
1179
1183 void FLEncoder_WriteValueAgain(FLEncoder e, intptr_t preWrittenValue);
1184
1185
1191
1192
1197
1204
1209
1214
1221
1224
1230
1231
1249
1258
1259
1269 FLSlice jsonDelta,
1270 FLError *error) FLAPI;
1271
1282 FLSlice jsonDelta,
1283 FLEncoder encoder) FLAPI;
1284
1285
1287
1288
1310
1317
1324
1325
1335
1336 static inline void FLSlot_SetArray(FLSlot NONNULL slot, FLArray array) {
1337 FLSlot_SetValue(slot, (FLValue)array);
1338 }
1339
1340 static inline void FLSlot_SetDict(FLSlot NONNULL slot, FLDict dict) {
1341 FLSlot_SetValue(slot, (FLValue)dict);
1342 }
1343
1344
1345 // implementations of the inline methods declared earlier:
1346
1347 static inline void FLMutableArray_SetNull(FLMutableArray a, uint32_t index) {
1349 }
1350 static inline void FLMutableArray_SetBool(FLMutableArray a, uint32_t index, bool val) {
1351 FLSlot_SetBool(FLMutableArray_Set(a, index), val);
1352 }
1353 static inline void FLMutableArray_SetInt(FLMutableArray a, uint32_t index, int64_t val) {
1354 FLSlot_SetInt(FLMutableArray_Set(a, index), val);
1355 }
1356 static inline void FLMutableArray_SetUInt(FLMutableArray a, uint32_t index, uint64_t val) {
1357 FLSlot_SetUInt(FLMutableArray_Set(a, index), val);
1358 }
1359 static inline void FLMutableArray_SetFloat(FLMutableArray a, uint32_t index, float val) {
1360 FLSlot_SetFloat(FLMutableArray_Set(a, index), val);
1361 }
1362 static inline void FLMutableArray_SetDouble(FLMutableArray a, uint32_t index, double val) {
1363 FLSlot_SetDouble(FLMutableArray_Set(a, index), val);
1364 }
1365 static inline void FLMutableArray_SetString(FLMutableArray a, uint32_t index, FLString val) {
1366 FLSlot_SetString(FLMutableArray_Set(a, index), val);
1367 }
1368 static inline void FLMutableArray_SetData(FLMutableArray a, uint32_t index, FLSlice val) {
1369 FLSlot_SetData(FLMutableArray_Set(a, index), val);
1370 }
1371 static inline void FLMutableArray_SetValue(FLMutableArray a, uint32_t index, FLValue val) {
1372 FLSlot_SetValue(FLMutableArray_Set(a, index), val);
1373 }
1374 static inline void FLMutableArray_SetArray(FLMutableArray a, uint32_t index, FLArray val) {
1376 }
1377 static inline void FLMutableArray_SetDict(FLMutableArray a, uint32_t index, FLDict val) {
1379 }
1380
1383 }
1384 static inline void FLMutableArray_AppendBool(FLMutableArray a, bool val) {
1386 }
1387 static inline void FLMutableArray_AppendInt(FLMutableArray a, int64_t val) {
1389 }
1390 static inline void FLMutableArray_AppendUInt(FLMutableArray a, uint64_t val) {
1392 }
1393 static inline void FLMutableArray_AppendFloat(FLMutableArray a, float val) {
1395 }
1396 static inline void FLMutableArray_AppendDouble(FLMutableArray a, double val) {
1398 }
1401 }
1404 }
1407 }
1410 }
1413 }
1414
1415 static inline void FLMutableDict_SetNull(FLMutableDict d, FLString key) {
1417 }
1418 static inline void FLMutableDict_SetBool(FLMutableDict d, FLString key, bool val) {
1419 FLSlot_SetBool(FLMutableDict_Set(d, key), val);
1420 }
1421 static inline void FLMutableDict_SetInt(FLMutableDict d, FLString key, int64_t val) {
1422 FLSlot_SetInt(FLMutableDict_Set(d, key), val);
1423 }
1424 static inline void FLMutableDict_SetUInt(FLMutableDict d, FLString key, uint64_t val) {
1425 FLSlot_SetUInt(FLMutableDict_Set(d, key), val);
1426 }
1427 static inline void FLMutableDict_SetFloat(FLMutableDict d, FLString key, float val) {
1428 FLSlot_SetFloat(FLMutableDict_Set(d, key), val);
1429 }
1430 static inline void FLMutableDict_SetDouble(FLMutableDict d, FLString key, double val) {
1431 FLSlot_SetDouble(FLMutableDict_Set(d, key), val);
1432 }
1433 static inline void FLMutableDict_SetString(FLMutableDict d, FLString key, FLString val) {
1434 FLSlot_SetString(FLMutableDict_Set(d, key), val);
1435 }
1436 static inline void FLMutableDict_SetData(FLMutableDict d, FLString key, FLSlice val) {
1437 FLSlot_SetData(FLMutableDict_Set(d, key), val);
1438 }
1439 static inline void FLMutableDict_SetValue(FLMutableDict d, FLString key, FLValue val) {
1440 FLSlot_SetValue(FLMutableDict_Set(d, key), val);
1441 }
1442 static inline void FLMutableDict_SetArray(FLMutableDict d, FLString key, FLArray val) {
1444 }
1445 static inline void FLMutableDict_SetDict(FLMutableDict d, FLString key, FLDict val) {
1447 }
1448
1449
1452#ifdef __cplusplus
1453}
1454#endif
1455
1456
1457#ifdef __OBJC__
1458// When compiling as Objective-C, include CoreFoundation / Objective-C utilities:
1459#include "Fleece+CoreFoundation.h"
1460#endif
1461
1462#endif // _FLEECE_H
#define FLPURE
Definition: Base.h:83
#define NONNULL
Definition: Base.h:62
#define MUST_USE_RESULT
Definition: Base.h:47
#define FLAPI
Definition: FLSlice.h:25
#define FLEECE_PUBLIC
Definition: Fleece.h:39
static void FLMutableArray_SetInt(FLMutableArray, uint32_t index, int64_t)
Stores an integer into an array.
Definition: Fleece.h:1353
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:468
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:1411
static void FLMutableArray_SetArray(FLMutableArray, uint32_t index, FLArray)
Stores a Fleece array into an array.
Definition: Fleece.h:1374
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:1396
static void FLMutableArray_SetUInt(FLMutableArray, uint32_t index, uint64_t)
Stores an unsigned integer into an array.
Definition: Fleece.h:1356
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:1390
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:1359
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:1377
static void FLMutableArray_AppendInt(FLMutableArray, int64_t)
Appends an integer to an array.
Definition: Fleece.h:1387
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:1365
static void FLMutableArray_AppendBool(FLMutableArray, bool)
Appends a boolean value to an array.
Definition: Fleece.h:1384
static void FLMutableArray_AppendString(FLMutableArray, FLString)
Appends a UTF-8-encoded string to an array.
Definition: Fleece.h:1399
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:1362
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:1405
static FLMutableArray FLMutableArray_Retain(FLMutableArray d)
Increments the ref-count of a mutable Array.
Definition: Fleece.h:494
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:1368
FLEECE_PUBLIC const FLArray kFLEmptyArray
static void FLMutableArray_SetBool(FLMutableArray, uint32_t index, bool)
Stores a boolean value into an array.
Definition: Fleece.h:1350
static void FLMutableArray_Release(FLMutableArray d)
Decrements the refcount of (and possibly frees) a mutable Array.
Definition: Fleece.h:498
static void FLMutableArray_AppendNull(FLMutableArray)
Appends a JSON null value to an array.
Definition: Fleece.h:1381
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:1347
static void FLMutableArray_AppendData(FLMutableArray, FLSlice)
Appends a binary data blob to an array.
Definition: Fleece.h:1402
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:1393
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:1371
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:1408
@ kFLDeepCopy
Definition: Fleece.h:470
@ kFLCopyImmutables
Definition: Fleece.h:471
@ kFLDefaultCopy
Definition: Fleece.h:469
@ kFLDeepCopyImmutables
Definition: Fleece.h:472
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:806
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:1445
static void FLMutableDict_SetNull(FLMutableDict, FLString key)
Stores a JSON null value into a mutable dictionary.
Definition: Fleece.h:1415
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:728
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:1436
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:1427
static void FLMutableDict_SetInt(FLMutableDict, FLString key, int64_t)
Stores an integer into a mutable dictionary.
Definition: Fleece.h:1421
static void FLMutableDict_SetValue(FLMutableDict, FLString key, FLValue)
Stores a Fleece value into a mutable dictionary.
Definition: Fleece.h:1439
static void FLMutableDict_SetDouble(FLMutableDict, FLString key, double)
Stores a 64-bit floating point number into a mutable dictionary.
Definition: Fleece.h:1430
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.
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:1418
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:1442
static void FLMutableDict_Release(FLMutableDict d)
Decrements the refcount of (and possibly frees) a mutable Dict.
Definition: Fleece.h:733
static void FLMutableDict_SetString(FLMutableDict, FLString key, FLString)
Stores a UTF-8-encoded string into a mutable dictionary.
Definition: Fleece.h:1433
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:1424
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:996
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:997
@ kFLEncodeJSON5
JSON5, an extension of JSON with a more readable syntax
Definition: Fleece.h:999
@ kFLEncodeJSON
JSON encoding.
Definition: Fleece.h:998
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:875
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:973
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:930
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:264
static void FLArray_Release(FLArray v)
Definition: Fleece.h:368
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:277
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:369
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.
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:367
static void FLDict_Release(FLDict v)
Definition: Fleece.h:370
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:271
@ kFLNumber
A numeric value, either integer or floating-point.
Definition: Fleece.h:268
@ kFLBoolean
A true or false value.
Definition: Fleece.h:267
@ kFLString
A string.
Definition: Fleece.h:269
@ kFLNull
Equivalent to a JSON 'null'.
Definition: Fleece.h:266
@ 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:265
@ kFLDict
A mapping of strings to values.
Definition: Fleece.h:272
@ kFLData
Binary data (no JSON equivalent)
Definition: Fleece.h:270
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:1336
static void FLSlot_SetDict(FLSlot slot, FLDict dict)
Definition: Fleece.h:1340
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:95
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:100
struct _FLSharedKeys * FLSharedKeys
A reference to a shared-keys mapping.
Definition: Fleece.h:96
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:110
@ kFLUntrusted
Input data is not trusted to be valid, and will be fully validated by the API call.
Definition: Fleece.h:102
struct _FLDict * FLMutableDict
A reference to a mutable dictionary.
Definition: Fleece.h:60
const struct _FLDict * FLDict
A reference to a dictionary (map) value.
Definition: Fleece.h:57
struct _FLSlot * FLSlot
A reference to a mutable array/dict item.
Definition: Fleece.h:58
struct _FLArray * FLMutableArray
A reference to a mutable array.
Definition: Fleece.h:59
FLError
Error codes returned from some API calls.
Definition: Fleece.h:66
const struct _FLArray * FLArray
A reference to an array value.
Definition: Fleece.h:56
struct _FLEncoder * FLEncoder
A reference to an encoder.
Definition: Fleece.h:61
const struct _FLValue * FLValue
A reference to a value of any type.
Definition: Fleece.h:55
@ kFLNotFound
Definition: Fleece.h:75
@ kFLInvalidData
Definition: Fleece.h:70
@ kFLInternalError
Definition: Fleece.h:74
@ kFLSharedKeysStateError
Definition: Fleece.h:76
@ kFLOutOfRange
Definition: Fleece.h:69
@ kFLEncodeError
Definition: Fleece.h:71
@ kFLMemoryError
Definition: Fleece.h:68
@ kFLUnsupported
Definition: Fleece.h:78
@ kFLUnknownValue
Definition: Fleece.h:73
@ kFLJSONError
Definition: Fleece.h:72
@ kFLPOSIXError
Definition: Fleece.h:77
@ kFLNoError
Definition: Fleece.h:67
Opaque array iterator.
Definition: Fleece.h:434
Opaque dictionary iterator.
Definition: Fleece.h:638
Opaque key for a dictionary.
Definition: Fleece.h:680
Definition: Fleece.h:837
uint32_t index
Array index, only if there's no key.
Definition: Fleece.h:839
FLSlice key
Dict key, or kFLSliceNull if none.
Definition: Fleece.h:838
A simple reference to a block of memory.
Definition: FLSlice.h:40
A heap-allocated block of memory returned from an API call.
Definition: FLSlice.h:58