Home

Awesome

Build and Test

Fleece

Fleece is a binary encoding for semi-structured data. Its data model is a superset of JSON, adding support for binary values. It is designed to be:

What You Get

FAQ

Q: Why does the world need yet another binary JSON encoding?
A: Excellent question, sock puppet! Fleece is different from BSON, PSON, etc. in that it's been carefully designed to not need parsing. In performance tests with other binary formats I found that, while they were faster to parse than JSON, the total time was still dominated by allocating and freeing the resulting objects, as well as the conversion from UTF-8 data to platform strings. (I was using Objective-C, but similar issues would arise if using STL or GLib or other collection frameworks.) The way around this is to structure the encoded data more like a memory dump, with "pointers" (relative byte offsets) and fixed-width random-accessible arrays. That's what Fleece does. As a result, it's many times faster to work with than JSON; literally 20x faster in the included benchmark run on a Macbook Pro.

Q: Can I use it in $LANGUAGE? [where $LANGUAGE not in ("C++", "C")]
Not currently. It would be very nice to more bindings, and the C API should make that fairly straightforward since it's easy to call from other languages. (But any real API should follow the language's idioms, instead of being a direct translation!)

Q: Why didn't you write this in $NEW_LANGUAGE instead of crufty C++?
A: I probably should have! $NEW_LANGUAGE is deservedly attracting a lot of attention for its combination of safety, readable syntax, and support for modern programming paradigms. I've been trying out $NEW_LANGUAGE and want to write more code in it. But for this I chose C++ because it's supported on all platforms, lots of people know how to use it, and it still supports high-level abstractions (unlike C.)

Q: Why did you only benchmark it against Cocoa's Foundation classes? Those are slow.
Because Foundation is what I know and work with. I'd love to incorporate benchmarks of other frameworks; please send a pull request.

Q: Why the name "Fleece"?
A: It's a reference to the mythical Golden Fleece, the treasure sought by Jason and the Argonauts.

Q: Who wrote this?
Jens Alfke, with design input from Volker Mische and Dave Rigby, and much help with portability and bug-fixing from Jim Borden. (And thanks to Mark Nunberg for the excellent jsonsl parser.)

Status

Fleece is in active use and development. It is a core component of Couchbase Lite 2.0, via the LiteCore library.

Requirements / Compatibility

We use Travis and Appveyor for CI, covering Clang, GCC, Xcode and MSVC on macOS, Linux and Windows. If you encounter portability problems, please file an issue and we'll fix it.

License

Apache 2.0