Cap'n Proto

From Just Solve the File Format Problem
Jump to: navigation, search
File Format
Name Cap'n Proto
Extension(s) .capnp
Released 2013[1]

Cap'n Proto is a serialization format and RPC system meant to be an improved version of Protocol Buffers, written by the same author[2]. Its major claimed advantage over Protocol Buffers is fast serialization and very fast deserialization; parsing is done lazily and much more simply than in Protocol Buffers, mostly amounting to a small amount of bounds-checking. Compare Simple Binary Encoding and FlatBuffers in this regard.



Cap'n Proto schema files have the extension ".capnp"[3]. It is not clear what, if any, extensions may be in use for the serialized format.


Cap'n Proto messages are generally divided into several units called "segments" in order to make construction of the message easier.[4] Messages using segments begin with a "segment table"[5] and then the content of those segments. It is possible to write a "flat" message that takes up a single segment, however, the help text of the CLI calls this "rare".


Cap'n Proto defines a very simple compression format called the "packing" format, which is essentially a variant of run-length encoding that only encode runs of bytes with value 0x00. This is especially useful because Cap'n Proto does not leave out zero-valued fields[6][7], and so without packing, messages may consist of long runs of zero bytes for the values of uninitialized fields. Packing can in many cases significantly reduce file size. See [1] for details on the format.

Canonical Form

"Canonicalized" messages are those belonging to a well-defined subset of the regular message format. Where packing is used on canonicalized messages, it is taken as a container rather than as part of the format (unlike for non-canonicalized messages). See [2] for a specification.


  • Official library
    • Includes a CLI capable of dumping, converting, etc. messages
    • Debian packages capnproto, libcapnp-*
  • List at [3]



  2., section "Why do you pick on Protocol Buffers so much?"
  5.; name is from
  6., and the fact that fast pointer access requires this to be true
Personal tools