From 8ccf59248da37b9adf3b5c39c22dca00fb108572 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Mon, 2 Oct 2023 08:39:40 +0800 Subject: [PATCH] improve readme --- readme.md | 3 +++ src/client.zig | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/readme.md b/readme.md index 4665085..5261892 100644 --- a/readme.md +++ b/readme.md @@ -197,6 +197,7 @@ The websocket client implementation is currently a work in progress. Feedback on var client = try websocket.connect(allocator, "localhost", 9001, .{}); defer client.deinit(); +const path = "/"; try client.handshake(path, .{ .timeout_ms = 5000, .headers = "host: localhost:9001\r\n", @@ -228,6 +229,8 @@ The main methods of `*websocket.Client` are: * `write([]u8)` - Alias to `writeText` * `close()` - Sends a close message and closes the connection +As you can see, these methods take a `[]u8`, not a `[]const u8` as they **will** mutate the data (websocket payloads are always masked). + More advanced methods are: * `closeWithCode(u16)` - Sends a close message with the specified code and closes the connection * `writePing([]u8)` - Writes a ping frame diff --git a/src/client.zig b/src/client.zig index 856957c..47b396d 100644 --- a/src/client.zig +++ b/src/client.zig @@ -172,6 +172,10 @@ pub fn Client(comptime T: type) type { return self.writeFrame(.text, data); } + pub fn writeText(self: *Self, data: []u8) !void { + return self.writeFrame(.text, data); + } + pub fn writeBin(self: *Self, data: []u8) !void { return self.writeFrame(.binary, data); } -- knotmirror 0.0.1