~caolan/zig-netstring

Zig parser for netstrings
support for zig 0.11
remove unused msg buffer from test case
use fixed buffer in README

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~caolan/zig-netstring
read/write
git@git.sr.ht:~caolan/zig-netstring

You can also use your local clone with git send-email.

#zig-netstring

Zig parser for netstrings.

#Usage

Add src/netstring.zig as a package in your build.zig:

example.addPackagePath("netstring", "path/to/deps/netstring/src/netstring.zig");

#Example

const netstring = @import("netstring");
const std = @import("std");

pub fn main() !void {
    var input = std.io.fixedBufferStream("5:hello,6:world!,");
    var parser = netstring.netStringParser(input.reader());
    var buf: [1024]u8 = undefined;

    // Repeat while the parser can find another netstring
    while (try parser.next()) |reader| {
        // Read the current netstring and print it
        const bytes = try reader.readAll(&buf);
        std.debug.print("{s}\n", .{buf[0..bytes]});
    }
}

Output:

hello
world!

#Running test suite

$ zig build tests