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
- Host: GitHub
- URL: https://github.com/thewawar/mqtt-zig
- Owner: TheWaWaR
- License: mit
- Created: 2022-11-08T02:53:21.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-22T14:33:20.000Z (10 months ago)
- Last Synced: 2025-03-27T22:43:11.406Z (about 1 month ago)
- Topics: codec, iot, mqtt
- Language: Zig
- Homepage:
- Size: 190 KB
- Stars: 13
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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"));
```