···4141 .target = target,
4242 });
43434444+ // Create static library
4545+ const lib = b.addLibrary(.{
4646+ .name = "zaprus",
4747+ .root_module = b.createModule(.{
4848+ .root_source_file = b.path("src/c_api.zig"),
4949+ .target = target,
5050+ .optimize = optimize,
5151+ .link_libc = true,
5252+ .imports = &.{
5353+ .{ .name = "zaprus", .module = mod },
5454+ },
5555+ }),
5656+ });
5757+5858+ b.installArtifact(lib);
5959+ lib.installHeader(b.path("include/zaprus.h"), "zaprus.h");
6060+4461 // Here we define an executable. An executable needs to have a root module
4562 // which needs to expose a `main` function. While we could add a main function
4663 // to the module defined above, it's sometimes preferable to split business
+33
include/zaprus.h
···11+#ifndef ZAPRUS_H
22+#define ZAPRUS_H
33+44+#include <stdint.h>
55+#include <stdlib.h>
66+77+typedef void* zaprus_client;
88+typedef void* zaprus_connection;
99+1010+// Returns NULL if there was an error.
1111+zaprus_client zaprus_init_client(void);
1212+1313+void zaprus_deinit_client(zaprus_client client);
1414+1515+// Returns 0 on success, else returns 1.
1616+int zaprus_client_send_relay(zaprus_client client, const char* payload, size_t payload_len, const char dest[4]);
1717+1818+// Returns NULL if there was an error.
1919+// Caller should call zaprus_deinit_connection when done with the connection.
2020+zaprus_connection zaprus_connect(zaprus_client client, const char* payload, size_t payload_len);
2121+2222+void zaprus_deinit_connection(zaprus_connection connection);
2323+2424+// Capacity is the maximum length of the output buffer.
2525+// out_len is modified to specify how much of the capacity is used by the response.
2626+// Blocks until the next message is available, or returns 1 if the underlying socket times out.
2727+// Returns 0 on success, else returns 1.
2828+int zaprus_connection_next(zaprus_connection connection, char *out, size_t capacity, size_t *out_len);
2929+3030+// Returns 0 on success, else returns 1.
3131+int zaprus_connection_send(zaprus_connection connection, const char *payload, size_t payload_len);
3232+3333+#endif // ZAPRUS_H