Cap’n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except faster - capnproto.org
Why this is interesting
Cap’n Proto is the basis for Sandstorm.io, and presents the opportunity to extend LiveCode on the server side in a way which is not possible using conventional web technologies. It leverage's the strengths of Livecode while mitigating it's weaknesses on the server side.
It provides:
- Capability Based Security
- Capability Urls w3.org
Supporting Dynamic Languages
What would be needed would be to extend the server with the C++ Dynamic Refelction API - capnproto.org
Dynamic languages have no compile step. This makes it difficult to work capnp compile into the workflow for such languages. Additionally, dynamic languages are often scripting languages that do not support pointer arithmetic or any reasonably-performant alternative.
Fortunately, dynamic languages usually have facilities for calling native code. The best way to support Cap’n Proto in a dynamic language, then, is to wrap the C++ library, in particular the C++ dynamic API. This way you get reasonable performance while still avoiding the need to generate any code specific to each schema.
Sometimes you want to write generic code that operates on arbitrary types, iterating over the fields or looking them up by name. For example, you might want to write code that encodes arbitrary Cap’n Proto types in JSON format. This requires something like “reflection”, but C++ does not offer reflection. Also, you might even want to operate on types that aren’t compiled into the binary at all, but only discovered at runtime.
The C++ API supports inspecting schemas at runtime via the interface defined in capnp/schema.h, and dynamically reading and writing instances of arbitrary types via capnp/dynamic.h. Here’s the example from the beginning of this file rewritten in terms of the dynamic API: