wire / wire-format / capnproto
Cap'n Proto is a zero-copy serialization format by the creator of Protocol Buffers. A Cap'n Proto message: segment table (number of segments + segment sizes), then segments (each a sequence of 64-bit words). Pointers (struct, list, text, data) are 64-bit values with type, offset, and size. Structs are fixed-size with a data section and pointer section. Lists can be of primitives, pointers, or structs.
aka: Cap'n Proto (zero-copy serialization)
spec: Cap'n Proto (capnproto.org)
Cap'n Proto is a zero-copy serialization format by the creator of Protocol Buffers. A Cap'n Proto message: segment table (number of segments + segment sizes), then segments (each a sequence of 64-bit words). Pointers (struct, list, text, data) are 64-bit values with type, offset, and size. Structs are fixed-size with a data section and pointer section. Lists can be of primitives, pointers, or structs.
| field | size | meaning |
|---|---|---|
| Segment count - 1 | 4 bytes (uint32) | Number of segments minus 1. |
| Padding | 4 bytes | Zero padding to 8-byte alignment. |
| Segment sizes | 4 bytes each (uint32) | Size of each segment in 8-byte words. |
| Segment data | variable | 64-bit words: struct pointers, list pointers, text/data pointers, and primitive values. |
| Struct pointer | 8 bytes | Type (2 bits) + offset (30 bits) + data size (16 bits) + pointer count (16 bits). |
| List pointer | 8 bytes | Type (2 bits) + offset (30 bits) + element size (3 bits) + element count (29 bits). |
example:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Cap'n Proto: 1 segment, 0 words (empty message)
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/capnproto
or /wire-format/capnproto.json