Something went wrong. Try again.
Experimental NATS client, written in Zig
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107pub const Conn = @import("client.zig").Conn;
// const std = @import("std");// const json = std.json;// const mem = std.mem;// const net = std.net;// const testing = std.testing;//// const Address = std.net.Address;// const Allocator = std.mem.Allocator;// const Stream = std.net.Stream;//// const buffer_size: usize = 1 << 20;//// pub const Client = struct {// allocator: Allocator,//// conn: ?Stream = null,// server_info: ?ServerInfo = null,//// pub fn init(allocator: Allocator) Client {// return Client{ .allocator = allocator };// }//// pub fn deinit(self: Client) void {// _ = self;// }//// pub fn connect(self: *Client, addr: Address, opts: ConnectOptions) !void {// const stream = try net.tcpConnectToAddress(addr);// self.stream = stream;//// const reader = stream.reader();// var buf: [buffer_size]u8 = undefined;// const msg = try reader.readUntilDelimiterOrEof(&buf, '\r');// // Read another byte to discard the newline.// _ = try reader.readByte();// if (!mem.startsWith(u8, msg, "INFO ")) return error.ExpectedInfoMessage;//// const result = try json.parseFromSliceLeaky(ServerInfo, self.allocator, buf[5..], .{});// self.server_info = result;//// _ = opts;// }//// pub fn publish(self: Client, subject: []const u8, payload: []const u8, opts: PublishOptions) !void {// _ = self;// _ = subject;// _ = payload;// _ = opts;// }// };//// test "Client connect" {// const input = "INFO {\"server_id\":\"NABGLAPI2AJEVYIPG54HIEUXZ5O7PEM5ZV5RFAJAECKG6T4BUPMWXLHY\",\"server_name\":\"us-south-nats-demo\",\"version\":\"2.10.20\",\"proto\":1,\"git_commit\":\"7140387\",\"go\":\"go1.22.6\",\"host\":\"0.0.0.0\",\"port\":4222,\"headers\":true,\"tls_available\":true,\"max_payload\":1048576,\"jetstream\":true,\"client_id\":176731,\"client_ip\":\"45.74.107.249\",\"nonce\":\"ze_FWXjX8RjC2cs\",\"xkey\":\"XBERSHAJDGJM3KTAXZEFG7FNJ45ABPXF5IS2OHOKS3FHXADSY65XEQIV\"}";// _ = input;// }//// pub const ServerInfo = struct {// server_id: []u8,// server_name: []u8,// version: []u8,// go: []u8,// host: []u8,// port: u16,// headers: bool,// max_payload: usize,// proto: u8,// client_id: u64,// auth_required: bool,// tls_required: bool,// tls_verify: bool,// tls_available: bool,// connect_urls: ?[][]u8,// ws_connect_urls: ?[][]u8,// ldm: bool,// git_commit: []u8,// jetstream: bool,// ip: []u8,// client_ip: []u8,// nonce: []u8,// cluster: []u8,// domain: []u8,// };//// pub const ConnectOptions = struct {// verbose: bool = false,// pedantic: bool = false,// tls_required: bool = false,// auth_token: ?[]u8,// user: ?[]u8,// pass: ?[]u8,// name: ?[]u8,// lang: []const u8 = "zig",// protocol: u8 = 1,// echo: bool = true,// sig: ?[]u8,// jwt: ?[]u8,// no_responders: bool = false,// headers: bool = true,// nkey: ?[]u8,// };//// pub const PublishOptions = struct {// reply_to: []const u8 = "",// };