Help creating FLArray for python bindings in couchbase-lite-C

This question is in reference to:

We are extending the python bindings to include Replicator, and we’re getting hung up on how to create and FLArray with ffi, in particular:

FLArray documentIDs; ///< Optional set of document IDs to replicate

We’ve gone through the documentation and have tried a few things without any luck. The common and Collection code has plenty of examples for decoding but not encoding.

Could you please show a small example for how to create this from a simple string array?


You’ll need to use the bindings to the C Fleece API, which is documented here. In C, the code would look like:

FLMutableArray a = FLMutableArray_New();
for (int i = 0; i < nStrings; i++) {
    FLString str = {myCString[i], strlen(myCString[i])};
    FLSlot slot = FLMutableArray_Append(a);
    FLSLot_SetString(slot, str);

... use the array ...

  • FLString is not a C string and doesn’t need to be null-terminated; it has a pointer and a length.
  • The string gets copied into the array, so you don’t need to worry about keeping the Python string from being relocated.
  • FLMutableArray_Release is a C inline function so you probably can’t call it from Python directly. Instead you can call what it calls, which is FLValue_Release.
  • I believe you can release the array after you’ve passed the config to the replicator – the replicator retains it.