An incremental RFC 8949 CBOR library for C89 and Lua 5.5.1. It provides:
- A token encoder/decoder with caller-owned state and bounded buffers.
- Framed streams and POSIX adapters for files, pipes, TCP, Unix sockets and datagrams.
- Direct C record mapping through lonejson and bidirectional JSON conversion.
- COSE encryption, signatures, MACs, authenticated record streams and CWT claims.
- A native Lua module with typed handles and C-to-Lua pointer interop.
Applications control I/O readiness, limits and object lifetimes. Large payloads
flow through bounded chunks; INPUT and OUTPUT return control to your event loop.
make build # native Debug C SDK and Lua module
make check-native # C/Lua tests, formatting and shell checksThe build prepares pinned lonejson 0.50.0, cpkt 0.8.0/OpenSSL 3.6.5 and Lua 5.5.1 inputs. See development for workstation tools, toolchain preparation, target selection and editor setup.
For an installed SDK, provide the libcbor, lonejson and cpkt prefixes through
CMAKE_PREFIX_PATH:
find_package(C89Cbor CONFIG REQUIRED)
target_link_libraries(app PRIVATE C89Cbor::static) # or C89Cbor::sharedThe pkg-config package is c89cbor. This is the c89.systems library; PJK/libcbor
uses a separate installation prefix. Delivery describes the
seven SDK targets, LuaRocks packages and installation layout.
This complete program encodes integer 42 as the bytes 18 2a. Link it against
one of the CMake targets above.
#include <c89cbor/cbor.h>
int main(void) {
c89cbor_encoder encoder;
c89cbor_token value = {0};
unsigned char bytes[9];
size_t written = 0;
int status = c89cbor_encoder_init(NULL, &encoder, NULL, 0, 0);
if (status != C89CBOR_OK)
return 1;
value.type = C89CBOR_UINT;
value.argument = 42;
status = encoder.put(&encoder, &value);
if (status == C89CBOR_OK)
status = encoder.read(&encoder, bytes, sizeof(bytes), &written);
if (status == C89CBOR_OK)
status = encoder.finish(&encoder);
(void)encoder.cleanup(&encoder);
return status != C89CBOR_OK || written != 2 ||
bytes[0] != 0x18 || bytes[1] != 0x2a;
}Use <c89cbor/cbor.h> for tokens, <c89cbor/io.h> for framing and I/O, and
<c89cbor/lonejson.h> for the runtime and mapped/JSON conversions. The
C API guide covers status handling, borrowed spans and native
records. copy.c is a complete descriptor-to-descriptor example;
the authenticated client/server demonstrates all transports.
require('cbor') loads the native cbor module, which calls the public shared
C library. This example decodes the same integer:
local cbor = require('cbor')
local runtime = assert(cbor.create())
local decoder = assert(runtime:decoder_init())
local status, consumed, token = decoder:next('\x18\x2a')
assert(status == cbor.TOKEN and consumed == 2)
assert(token)
assert(token:argument() == 42)
assert(token:close() == cbor.OK)
assert(decoder:finish() == cbor.OK)
assert(decoder:close() == cbor.OK)
assert(runtime:close() == cbor.OK)Native source/sink handles let Lua schedule whole transfers without per-token Lua calls. Lua-only source packages build against installed SDKs; see the Lua guide for installation, loading the module, streaming, interop and editor declarations.
| Topic | Guide |
|---|---|
| Ownership, tokens, records and JSON | C API |
| Lua handles and native embedding | Lua API |
| Encryption and authenticated streams | COSE |
| Signatures, MACs and claim policies | Sign1, Mac0 and CWT |
| Builds, clangd, LuaLS and testing | Development |
| SDKs, LuaRocks and releases | Delivery |
| Test suites and independent peers | Hardening |
| Workloads and measurements | Benchmarks |
| Architecture and detailed contracts | Design, specification |
| Symbols and receiver methods | API inventory |
| Attribution and upstream sources | Provenance |