From 2e06f44aa8f1df879de9e7948d339b225810ef27 Mon Sep 17 00:00:00 2001 From: torque Date: Wed, 23 Aug 2023 22:35:15 -0700 Subject: [PATCH] examples: add pub_bytes This was the point that I realized there's no reason to have the string variants of the publishing methods. But also there's not really much point in porting the other getting-started examples, since we've covered all their functionality in the existing examples (actually, this one is redundant too, but I have already done it, so it's getting grandfathered in). Porting some of the more interesting examples might be a good idea, but those have a weird argument parser that I don't really want to port (even though it is very simple in the way that it works). For the most part, I think writing unit tests will do a better of flexing the bindings. --- build.zig | 1 + examples/pub_bytes.zig | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 examples/pub_bytes.zig diff --git a/build.zig b/build.zig index c6be53f..8151bb8 100644 --- a/build.zig +++ b/build.zig @@ -54,6 +54,7 @@ const Example = struct { const examples = [_]Example{ .{ .name = "request_reply", .file = "examples/request_reply.zig" }, .{ .name = "headers", .file = "examples/headers.zig" }, + .{ .name = "pub_bytes", .file = "examples/pub_bytes.zig" }, }; pub fn add_examples(b: *std.build, options: ExampleOptions) void { diff --git a/examples/pub_bytes.zig b/examples/pub_bytes.zig new file mode 100644 index 0000000..c176d35 --- /dev/null +++ b/examples/pub_bytes.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const nats = @import("nats"); + +pub fn main() !void { + const connection = try nats.Connection.connectTo(nats.default_server_url); + defer connection.destroy(); + + const data = [_]u8{ 104, 101, 108, 108, 111, 33 }; + try connection.publish("subject", &data); +}