You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cap'n Proto is a type system for distributed systems.
With Cap'n Proto, you describe your data and interfaces
in a schema file, like this:
@0x986b3393db1396c9;
structPoint {
x @0:Float32;
y @1:Float32;
}
interface PointTracker {
addPoint @0 (p :Point) -> (totalPoints :UInt64);
}
You can then use the capnp tool
to generate code in a variety of programming languages.
The generated code lets you produce and consume values of the
types you've defined in your schema.
Values are encoded in a format that
is suitable not only for transmission over a network and persistence to disk,
but also for zero-copy in-memory traversal.
That is, you can completely skip serialization and deserialization!
It's in this sense that Cap'n Proto is
"infinity times faster"
than alternatives like Protocol Buffers.
In Rust, the generated code for the example above includes
a point::Reader<'a> struct with get_x() and get_y() methods,
and a point::Builder<'a> struct with set_x() and set_y() methods.
The lifetime parameter 'a is a formal reminder
that point::Reader<'a> and point::Builder<'a>
contain borrowed references to the raw buffers that contain the encoded messages.
Those underlying buffers are never actually copied into separate data structures.
The generated code for the example above also includes
a point_tracker::Server trait with an add_point() method,
and a point_tracker::Client struct with an add_point_request() method.
The former can be implemented to create a network-accessible object,
and the latter can be used to invoke a possibly-remote instance of a PointTracker.