An open API service indexing awesome lists of open source software.

https://github.com/thewawar/mqtt-zig

Allocation free MQTT v3.1/v3.1.1/v5.0 packet codec in Zig
https://github.com/thewawar/mqtt-zig

codec iot mqtt

Last synced: 21 days ago
JSON representation

Allocation free MQTT v3.1/v3.1.1/v5.0 packet codec in Zig

Awesome Lists containing this project

README

        

# mqtt-zig
Zig implementation of MQTT v3.1/v3.1.1/v5.0 codec that is **allocation free**. The code is ported from my rust library: [mqtt-proto](https://github.com/akasamq/mqtt-proto). This library is intended for both **client** and **server** usage (with `strict` protocol validation).

## Current State:
* Implemented versions
- v3.1
- v3.1.1
* Test Coverage: `92.2%` (by kcov)

## Example

```zig
// Encode a packet
const pkt = Packet{ .connect = Connect{
.protocol = .V311,
.clean_session = true,
.keep_alive = 120,
.client_id = Utf8View.initUnchecked("sample"),
} };
var buf: [512]u8 = undefined;
var idx: usize = 0;
try pkt.encode(buf[0..], &idx);

// Decode a packet
const read_pkt = try Packet.decode(buf[0..]);
```

## Import Guide
```shell
zig fetch --save https://github.com/TheWaWaR/mqtt-zig/archive/.tar.gz
```

In `build.zig`
```zig
const mqtt = b.dependency("mqtt", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("mqtt", mqtt.module("mqtt"));
```