If a CBLDocument_Exists function could be added to CBLPrivate.h and CBLDocument_CAPI.cc, calling through to the C++ APIs similar to CBLDocument_Generation, this would be really helpful for my usage.
My current native C implementation is super fragile and I expected it to break at some point, which it did in the 3.1.7 SDK release. I figured out the memory offsets to access the C4Document. For anything more than tests, this obviously wouldn’t fly. I also want to avoid recalculating and maintaining the memory offsets.
The exist() is the private API and the current implementation is also half right as it only checks if the c4document is not null in the Document object. The method is currently used for some testing purpose.
The implementation is also half right as it only checks whether the c4document is not null in the Document object. Do you need this only for testing purpose? If that so, can you have a function in the test that tries to get the document from the database to see if it exists or not?
The tests are common between all the supported platforms, running from the same common Kotlin code. Under the hood, there are platform-specific implementations of the APIs, most of which are the public CBL API. But since the tests do use several internal/private APIs, such as Document.exists, this is why I need an implementation of the function on all three platforms (JVM/Android via Java SDK, iOS/macOS via Objective-C SDK, and Linux/Windows via C SDK).
It’s not really possible to change the behavior specifically on Linux/Windows to checking if the Document itself is not null, since it expects a not-null Document that it can call the exists() function on. I could change the common logic in the tests for all platforms instead, but I’d prefer to avoid this, since I do my best to have the tests mirror the Java SDK tests as much as possible for ease of maintenance. There seems to be a reason the tests prefer this more robust private API check as well.
I did notice the C SDK exists() is only checking for whether the C4Document is not null and not checking the flags as the Java SDK does. I have the flag check logic implemented for both Objective-C and C already though.
So really, if there was even just a private C API available to get the C4Document, this would avoid the need to hack the struct’s memory offsets. Something like C4Document CBLDocument_GetC4Document(const CBLDocument* doc) in CBLPrivate.h that returned _c4doc.
bool CBLDocument_Exists(const CBLDocument* doc) would work as well, even without the flag check.
I don’t expect any kind of support for this API and it’s only used for these tests. If it were to be removed at some point, it would probably be removed in all SDKs and no longer used in the tests anyway.