Kenton Varda, primary author of Protocol Buffers 59,573 version 2, released Cap'n Proto 686,504 on 1 April 2013. Its home page calls it "INFINITY TIMES faster than Protocol Buffers", admitting the comparison is unfair: there is no decode step, because the wire format is the in-memory layout. The pycapnp binding loads order.capnp at run time:
import capnp
from order1 import order1
schema = capnp.load("order.capnp") # pycapnp parses the schema at run time
fields = {k: v for k, v in order1().items() if v is not None}
msg = schema.Order.new_message(**fields)
data = msg.to_bytes()
msg.clear_write_flag() # allow a second, packed serialization
packed = msg.to_bytes_packed()
with schema.Order.from_bytes(data) as order: # a view over the bytes, no decode step
print(f"{len(data)} bytes, {len(packed)} packed; totalCents={order.totalCents}, "
f"channel={order.channel}, items={len(order.items)}")Output
152 bytes, 64 packed; totalCents=4020, channel=ios, items=2
Word-aligned 64-bit slots make the message 152 bytes; packing squeezes out zero bytes, giving 64. The design pays off for memory-mapped files and RPC, where promise pipelining sends dependent calls in one round trip.