Announcing vali, a C library for Varlink 2025-10-04 In the past months I’ve been working on vali, a C library for Varlink. Today I’m publishing the first vali release! I’d like to explain how to use it for readers who aren’t especially familiar with Varlink, and describe some interesting API design decisions. What is Varlink anyways? Varlink is a very simple Remote Procedure Call (RPC) protocol. Clients can call methods exposed by services (ie, servers). To call a method, a client sends a JSON object with its name and parameters over a Unix socket. To reply to a call, a service sends a JSON object with response parameters. That’s it. Here’s an example request with a bar parameter containing an integer: { "method": "org.example.service.Foo", "parameters": { "bar": 42 } } And here’s an example response with a baz parameter containing a list of strings: { "parameters": { "baz": ["hello", "world"] } } Varlink also supports calls with no reply or with multiple replies, but let’s leave this out of the picture for simplicity’s sake. Varlink services can describe the methods they implement with an interface definition file. method Foo(bar: int) -> (baz: []string) Coming from the Wayland world, I love generating code from specification files. This removes all of the manual encoding/decoding boilerplate and is more type-safe. Unfortunately the official libvarlink library doesn’t support code generation (and is not actively maintained anymore), so I’ve decided to write my own. vali is the result! vali without code generation To better understand the benefits of code generation and vali design decisions, let’s take a minute to have a look at what usage without code generation looks like. A client first needs to connect via vali_client_connect_unix(), then call vali_client_call() with a JSON object containing input parameters. It’ll get back a JSON object containing output parameters, which needs to be parsed. struct vali_client *client = vali_client_connect_unix("/run/org.examp...
First seen: 2025-10-14 05:29
Last seen: 2025-10-14 12:33