capnp-janet#

Native Cap’n Proto runtime for Janet, plus a C library embedders can link without the Janet VM.

Sibling runtimes: c-capnproto and capnp-fortran. Status: 0.2.0-dev. AddressBook encode matches official capnp encode when fields are set in schema order.

Install (shortest path)#

$ git clone https://github.com/HaoZeke/capnp-janet.git
$ cd capnp-janet
$ pixi install && pixi run configure && pixi run build && pixi run test

First message (Janet)#

(import capnp)

(def buf (capnp/build-demo 42 "hello" ["a" "bb"]))
(def msg (capnp/message-from-buffer buf))
(def root (capnp/root msg))
(print (capnp/get-u32 root 0))        # 42
(print (capnp/get-text root 0))       # hello
(def items (capnp/getp root 1))
(print (capnp/list-get-text items 1)) # bb

C embed (no Janet VM):

#include <capnp-janet/capnp_message.h>

capnp_message_t msg;
capnp_message_view_flat(&msg, bytes, len);
capnp_ptr_t root;
capnp_root(&msg, &root);
const char *s; size_t n;
capnp_get_text(&root, 0, &s, &n);

The tutorial walks AddressBook encode and the embed register path.

Documentation map#

Install

pixi, Meson, C embed, Janet module.

Install
Tutorial

First buffer, AddressBook, capnp_janet_register.

Tutorial
Architecture

C layers, zero-copy views, compiled .jimage packs.

capnp-janet architecture
Wire

Packed, canonical, list evolution.

Wire format