Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 1018 Bytes

README.md

File metadata and controls

37 lines (31 loc) · 1018 Bytes

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. 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

// 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

zig fetch --save https://github.com/TheWaWaR/mqtt-zig/archive/<commit-id>.tar.gz

In build.zig

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